From b8cbd25e0e384de6b3cd87b2bbc40c8748bc1385 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 18:48:29 -0700 Subject: [PATCH 01/10] Drop support for optional url params --- lib/makeRequest.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/makeRequest.js b/lib/makeRequest.js index cb49d4c2ed..81bfbc6d49 100644 --- a/lib/makeRequest.js +++ b/lib/makeRequest.js @@ -1,7 +1,6 @@ 'use strict'; const utils = require('./utils'); -const OPTIONAL_REGEX = /^optional!/; function getRequestOpts(self, requestArgs, spec, overrideData) { // Extract spec values with defaults. @@ -28,9 +27,6 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { let param = urlParams[i]; - const isOptional = OPTIONAL_REGEX.test(param); - param = param.replace(OPTIONAL_REGEX, ''); - if (param == 'id' && typeof arg !== 'string') { path = self.createResourcePathWithSymbols(spec.path); throw new Error( @@ -39,11 +35,6 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { } if (!arg) { - if (isOptional) { - urlData[param] = ''; - continue; - } - path = self.createResourcePathWithSymbols(spec.path); throw new Error( `Stripe: Argument "${ From d88a3e715b20cbe9478b05140e825c381bc5f817 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 19:47:42 -0700 Subject: [PATCH 02/10] Delete nested resource files --- lib/resources/ApplicationFeeRefunds.js | 21 ----- lib/resources/LoginLinks.js | 9 --- lib/resources/Persons.js | 9 --- .../SubscriptionScheduleRevisions.js | 9 --- lib/resources/TaxIds.js | 9 --- lib/resources/TransferReversals.js | 9 --- lib/stripe.js | 8 -- test/resources/ApplicationFeeRefunds.spec.js | 56 ------------- test/resources/LoginLinks.spec.js | 27 ------- test/resources/Persons.spec.js | 80 ------------------- .../SubscriptionScheduleRevision.spec.js | 42 ---------- test/resources/TaxIds.spec.js | 67 ---------------- test/resources/TransferReversals.spec.js | 70 ---------------- 13 files changed, 416 deletions(-) delete mode 100644 lib/resources/ApplicationFeeRefunds.js delete mode 100644 lib/resources/LoginLinks.js delete mode 100644 lib/resources/Persons.js delete mode 100644 lib/resources/SubscriptionScheduleRevisions.js delete mode 100644 lib/resources/TaxIds.js delete mode 100644 lib/resources/TransferReversals.js delete mode 100644 test/resources/ApplicationFeeRefunds.spec.js delete mode 100644 test/resources/LoginLinks.spec.js delete mode 100644 test/resources/Persons.spec.js delete mode 100644 test/resources/SubscriptionScheduleRevision.spec.js delete mode 100644 test/resources/TaxIds.spec.js delete mode 100644 test/resources/TransferReversals.spec.js diff --git a/lib/resources/ApplicationFeeRefunds.js b/lib/resources/ApplicationFeeRefunds.js deleted file mode 100644 index 68d92045be..0000000000 --- a/lib/resources/ApplicationFeeRefunds.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -/** - * ApplicationFeeRefunds is a unique resource in that, upon instantiation, - * requires an application fee id , and therefore each of its methods only - * require the refundId argument. - * - * This streamlines the API specifically for the case of accessing refunds - * on a returned application fee object. - * - * E.g. applicationFeeObject.refunds.retrieve(refundId) - * (As opposed to the also-supported stripe.applicationFees.retrieveRefund(chargeId, - * refundId)) - */ -module.exports = StripeResource.extend({ - path: 'application_fees/{feeId}/refunds', - - includeBasic: ['create', 'list', 'retrieve', 'update'], -}); diff --git a/lib/resources/LoginLinks.js b/lib/resources/LoginLinks.js deleted file mode 100644 index 842a447ddb..0000000000 --- a/lib/resources/LoginLinks.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'accounts/{accountId}/login_links', - - includeBasic: ['create'], -}); diff --git a/lib/resources/Persons.js b/lib/resources/Persons.js deleted file mode 100644 index 921561ea64..0000000000 --- a/lib/resources/Persons.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'accounts/{accountId}/persons', - - includeBasic: ['create', 'del', 'list', 'retrieve', 'update'], -}); diff --git a/lib/resources/SubscriptionScheduleRevisions.js b/lib/resources/SubscriptionScheduleRevisions.js deleted file mode 100644 index 7748b9a721..0000000000 --- a/lib/resources/SubscriptionScheduleRevisions.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'subscription_schedules/{scheduleId}/revisions', - - includeBasic: ['list', 'retrieve'], -}); diff --git a/lib/resources/TaxIds.js b/lib/resources/TaxIds.js deleted file mode 100644 index 7cc865bd87..0000000000 --- a/lib/resources/TaxIds.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'customers/{customerId}/tax_ids', - - includeBasic: ['create', 'del', 'list', 'retrieve'], -}); diff --git a/lib/resources/TransferReversals.js b/lib/resources/TransferReversals.js deleted file mode 100644 index 207b653491..0000000000 --- a/lib/resources/TransferReversals.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'transfers/{transferId}/reversals', - - includeBasic: ['create', 'list', 'retrieve', 'update'], -}); diff --git a/lib/stripe.js b/lib/stripe.js index 4250054163..99777370ef 100644 --- a/lib/stripe.js +++ b/lib/stripe.js @@ -55,7 +55,6 @@ const resources = { InvoiceItems: require('./resources/InvoiceItems'), Invoices: require('./resources/Invoices'), IssuerFraudRecords: require('./resources/IssuerFraudRecords'), - LoginLinks: require('./resources/LoginLinks'), OAuth: require('./resources/OAuth'), OrderReturns: require('./resources/OrderReturns'), Orders: require('./resources/Orders'), @@ -81,13 +80,6 @@ const resources = { UsageRecordSummaries: require('./resources/UsageRecordSummaries'), WebhookEndpoints: require('./resources/WebhookEndpoints'), - // The following rely on pre-filled IDs: - ApplicationFeeRefunds: require('./resources/ApplicationFeeRefunds'), - Persons: require('./resources/Persons'), - SubscriptionScheduleRevisions: require('./resources/SubscriptionScheduleRevisions'), - TaxIds: require('./resources/TaxIds'), - TransferReversals: require('./resources/TransferReversals'), - // Namespaced resources Checkout: resourceNamespace('checkout', { Sessions: require('./resources/Checkout/Sessions'), diff --git a/test/resources/ApplicationFeeRefunds.spec.js b/test/resources/ApplicationFeeRefunds.spec.js deleted file mode 100644 index 75be78aa2e..0000000000 --- a/test/resources/ApplicationFeeRefunds.spec.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const APPFEE_TEST_ID = 'appFeeIdTest999'; -const REFUND_TEST_ID = 'refundIdTest999'; - -// Create new CustomerCard instance with pre-filled customerId: -const appFeeRefund = new resources.ApplicationFeeRefunds(stripe, { - feeId: APPFEE_TEST_ID, -}); - -// Use spy from existing resource: -appFeeRefund._request = stripe.customers._request; - -describe('ApplicationFeeRefund Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - appFeeRefund.retrieve(REFUND_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - appFeeRefund.update(REFUND_TEST_ID, { - metadata: {key: 'value'}, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, - data: {metadata: {key: 'value'}}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - appFeeRefund.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds`, - data: {}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/LoginLinks.spec.js b/test/resources/LoginLinks.spec.js deleted file mode 100644 index f8c6c36183..0000000000 --- a/test/resources/LoginLinks.spec.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const ACCOUNT_ID = 'acct_EXPRESS'; - -// Create new LoginLink instance with pre-filled accountId: -const loginLink = new resources.LoginLinks(stripe, {accountId: ACCOUNT_ID}); - -// Use spy from existing resource: -loginLink._request = stripe.customers._request; - -describe('LoginLink Resource', () => { - describe('create', () => { - it('Sends the correct request', () => { - loginLink.create(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/accounts/${ACCOUNT_ID}/login_links`, - headers: {}, - data: {}, - }); - }); - }); -}); diff --git a/test/resources/Persons.spec.js b/test/resources/Persons.spec.js deleted file mode 100644 index 0b199f6715..0000000000 --- a/test/resources/Persons.spec.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const ACCOUNT_TEST_ID = 'acct_123'; -const PERSON_TEST_ID = 'person_123'; - -// Create new Person instance with pre-filled accountId: -const person = new resources.Persons(stripe, {accountId: ACCOUNT_TEST_ID}); - -// Use spy from existing resource: -person._request = stripe.customers._request; - -describe('Person Resource', () => { - describe('create', () => { - it('Sends the correct request', () => { - person.create({ - first_name: 'John', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, - data: {first_name: 'John'}, - headers: {}, - }); - }); - }); - - describe('delete', () => { - it('Sends the correct request', () => { - person.del(PERSON_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - person.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, - data: {}, - headers: {}, - }); - }); - }); - - describe('retrieve', () => { - it('Sends the correct request', () => { - person.retrieve(PERSON_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - person.update(PERSON_TEST_ID, { - first_name: 'John', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, - data: {first_name: 'John'}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/SubscriptionScheduleRevision.spec.js b/test/resources/SubscriptionScheduleRevision.spec.js deleted file mode 100644 index 4c15320d7a..0000000000 --- a/test/resources/SubscriptionScheduleRevision.spec.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const SCHEDULE_TEST_ID = 'sub_sched_123'; -const REVISION_TEST_ID = 'sub_sched_rev_123'; - -// Create new SubscriptionScheduleRevision instance with pre-filled scheduleId: -const revision = new resources.SubscriptionScheduleRevisions(stripe, { - scheduleId: SCHEDULE_TEST_ID, -}); - -// Use spy from existing resource: -revision._request = stripe.customers._request; - -describe('SubscriptionScheduleRevision Resource', () => { - describe('list', () => { - it('Sends the correct request', () => { - revision.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions`, - data: {}, - headers: {}, - }); - }); - }); - - describe('retrieve', () => { - it('Sends the correct request', () => { - revision.retrieve(REVISION_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions/${REVISION_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/TaxIds.spec.js b/test/resources/TaxIds.spec.js deleted file mode 100644 index fda30f9faa..0000000000 --- a/test/resources/TaxIds.spec.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const CUSTOMER_TEST_ID = 'cus_123'; -const TAX_ID_TEST_ID = 'txi_123'; - -const taxId = new resources.TaxIds(stripe, {customerId: CUSTOMER_TEST_ID}); - -// Use spy from existing resource: -taxId._request = stripe.customers._request; - -describe('TaxId Resource', () => { - describe('create', () => { - it('Sends the correct request', () => { - const data = { - type: 'eu_vat', - value: '11111', - }; - taxId.create(data); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, - data, - headers: {}, - }); - }); - }); - - describe('delete', () => { - it('Sends the correct request', () => { - taxId.del(TAX_ID_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - taxId.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, - data: {}, - headers: {}, - }); - }); - }); - - describe('retrieve', () => { - it('Sends the correct request', () => { - taxId.retrieve(TAX_ID_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/TransferReversals.spec.js b/test/resources/TransferReversals.spec.js deleted file mode 100644 index 3b0c9e67fb..0000000000 --- a/test/resources/TransferReversals.spec.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const TRANSFER_TEST_ID = 'transferIdTest999'; -const REVERSAL_TEST_ID = 'reversalIdTest999'; - -// Create new CustomerCard instance with pre-filled customerId: -const transferReversal = new resources.TransferReversals(stripe, { - transferId: TRANSFER_TEST_ID, -}); - -// Use spy from existing resource: -transferReversal._request = stripe.customers._request; - -describe('TransferReversal Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - transferReversal.retrieve(REVERSAL_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('create', () => { - it('Sends the correct request', () => { - transferReversal.create({ - amount: 100, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, - data: {amount: 100}, - headers: {}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - transferReversal.update(REVERSAL_TEST_ID, { - metadata: {key: 'value'}, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, - data: {metadata: {key: 'value'}}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - transferReversal.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, - data: {}, - headers: {}, - }); - }); - }); -}); From b3cfe88b9dcbf502f2e23d0433f15cd55a82f8b3 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 19:48:51 -0700 Subject: [PATCH 03/10] Remove urlData --- lib/StripeResource.js | 16 +--------------- lib/makeRequest.js | 4 ++-- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/lib/StripeResource.js b/lib/StripeResource.js index a252123451..e11876781a 100644 --- a/lib/StripeResource.js +++ b/lib/StripeResource.js @@ -8,8 +8,6 @@ const uuid = require('uuid/v4'); const utils = require('./utils'); const Error = require('./Error'); -const hasOwn = {}.hasOwnProperty; - const defaultHttpAgent = new http.Agent({keepAlive: true}); const defaultHttpsAgent = new https.Agent({keepAlive: true}); @@ -25,9 +23,8 @@ StripeResource.MAX_BUFFERED_REQUEST_METRICS = 100; /** * Encapsulates request logic for a Stripe Resource */ -function StripeResource(stripe, urlData) { +function StripeResource(stripe) { this._stripe = stripe; - this._urlData = urlData || {}; this.basePath = utils.makeURLInterpolator( this.basePath || stripe.getApiField('basePath') @@ -81,17 +78,6 @@ StripeResource.prototype = { .replace(/\\/g, '/')}`; // ugly workaround for Windows }, - createUrlData() { - const urlData = {}; - // Merge in baseData - for (const i in this._urlData) { - if (hasOwn.call(this._urlData, i)) { - urlData[i] = this._urlData[i]; - } - } - return urlData; - }, - // DEPRECATED: Here for backcompat in case users relied on this. wrapTimeout: utils.callbackifyPromiseWithTimeout, diff --git a/lib/makeRequest.js b/lib/makeRequest.js index 81bfbc6d49..e637fc99bc 100644 --- a/lib/makeRequest.js +++ b/lib/makeRequest.js @@ -17,7 +17,7 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { const args = [].slice.call(requestArgs); // Generate and validate url params. - const urlData = self.createUrlData(); + const urlData = {}; for (let i = 0, l = urlParams.length; i < l; ++i) { var path; @@ -25,7 +25,7 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { // grabs the "next" argument for use as a URL parameter. const arg = args[0]; - let param = urlParams[i]; + const param = urlParams[i]; if (param == 'id' && typeof arg !== 'string') { path = self.createResourcePathWithSymbols(spec.path); From aeabd825d672617a8627458f8a0163982eb38e70 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 20:54:06 -0700 Subject: [PATCH 04/10] Extract urlParams from path instead of manual definition Verified this is no different with: ```js const urlParams = utils.extractUrlParams(spec.path || ''); if ( !(spec.urlParams || []).every((x, i) => urlParams[i] === x) || (spec.urlParams || []).length !== urlParams.length ) { throw Error( 'mismatch' + JSON.stringify(urlParams) + JSON.stringify(spec.urlParams) ); } ``` inside StripeMethod --- lib/StripeMethod.js | 2 ++ lib/makeRequest.js | 5 +---- lib/utils.js | 9 +++++++++ test/utils.spec.js | 10 ++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/StripeMethod.js b/lib/StripeMethod.js index 99f18426a7..68a5558ef4 100644 --- a/lib/StripeMethod.js +++ b/lib/StripeMethod.js @@ -20,6 +20,8 @@ const makeAutoPaginationMethods = require('./autoPagination') * @param [spec.host] Hostname for the request. */ function stripeMethod(spec) { + spec.urlParams = utils.extractUrlParams(spec.path || ''); + return function() { const self = this; const args = [].slice.call(arguments); diff --git a/lib/makeRequest.js b/lib/makeRequest.js index e637fc99bc..57f08d5268 100644 --- a/lib/makeRequest.js +++ b/lib/makeRequest.js @@ -4,10 +4,7 @@ const utils = require('./utils'); function getRequestOpts(self, requestArgs, spec, overrideData) { // Extract spec values with defaults. - const commandPath = - typeof spec.path == 'function' - ? spec.path - : utils.makeURLInterpolator(spec.path || ''); + const commandPath = utils.makeURLInterpolator(spec.path || ''); const requestMethod = (spec.method || 'GET').toUpperCase(); const urlParams = spec.urlParams || []; const encode = spec.encode || ((data) => data); diff --git a/lib/utils.js b/lib/utils.js index ae8ddfd778..d2aeb370e1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -66,6 +66,15 @@ const utils = (module.exports = { }; })(), + extractUrlParams: (path) => { + const params = path.match(/\{\w+\}/g); + if (!params) { + return []; + } + + return params.map((param) => param.replace(/[{}]/g, '')); + }, + /** * Return the data argument from a list of arguments */ diff --git a/test/utils.spec.js b/test/utils.spec.js index 202da2f67c..861998fc76 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -22,6 +22,16 @@ describe('utils', () => { }); }); + describe('extractUrlParams', () => { + it('works with multiple params', () => { + expect( + utils.extractUrlParams( + 'accounts/{accountId}/external_accounts/{externalAccountId}' + ) + ).to.deep.equal(['accountId', 'externalAccountId']); + }); + }); + describe('stringifyRequestData', () => { it('Handles basic types', () => { expect( From 7842939f03eb00a78ab0b93e36b0c351ea257bd8 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 21:28:31 -0700 Subject: [PATCH 05/10] Remove manually specified urlParams --- lib/StripeMethod.basic.js | 3 --- lib/resources/Accounts.js | 15 --------------- lib/resources/ApplicationFees.js | 4 ---- lib/resources/BitcoinReceivers.js | 1 - lib/resources/Charges.js | 1 - lib/resources/CreditNotes.js | 1 - lib/resources/Customers.js | 11 ----------- lib/resources/Disputes.js | 5 ++++- lib/resources/Invoices.js | 6 ------ lib/resources/Issuing/Authorizations.js | 2 -- lib/resources/Issuing/Cards.js | 1 - lib/resources/Orders.js | 6 ++++-- lib/resources/PaymentIntents.js | 3 --- lib/resources/PaymentMethods.js | 2 -- lib/resources/Payouts.js | 1 - lib/resources/Recipients.js | 5 ----- lib/resources/Reviews.js | 1 - lib/resources/Sources.js | 2 -- lib/resources/SubscriptionSchedules.js | 4 ---- lib/resources/Subscriptions.js | 1 - lib/resources/Topups.js | 1 - lib/resources/Transfers.js | 4 ---- lib/resources/UsageRecordSummaries.js | 1 - lib/resources/UsageRecords.js | 1 - 24 files changed, 8 insertions(+), 74 deletions(-) diff --git a/lib/StripeMethod.basic.js b/lib/StripeMethod.basic.js index efbd6a48a0..c807ea1849 100644 --- a/lib/StripeMethod.basic.js +++ b/lib/StripeMethod.basic.js @@ -15,19 +15,16 @@ module.exports = { retrieve: stripeMethod({ method: 'GET', path: '/{id}', - urlParams: ['id'], }), update: stripeMethod({ method: 'POST', path: '{id}', - urlParams: ['id'], }), // Avoid 'delete' keyword in JS del: stripeMethod({ method: 'DELETE', path: '{id}', - urlParams: ['id'], }), }; diff --git a/lib/resources/Accounts.js b/lib/resources/Accounts.js index 75e25acf1d..a1a318804e 100644 --- a/lib/resources/Accounts.js +++ b/lib/resources/Accounts.js @@ -20,20 +20,17 @@ module.exports = StripeResource.extend({ update: stripeMethod({ method: 'POST', path: 'accounts/{id}', - urlParams: ['id'], }), // Avoid 'delete' keyword in JS del: stripeMethod({ method: 'DELETE', path: 'accounts/{id}', - urlParams: ['id'], }), reject: stripeMethod({ method: 'POST', path: 'accounts/{id}/reject', - urlParams: ['id'], }), retrieve(id) { @@ -43,7 +40,6 @@ module.exports = StripeResource.extend({ return stripeMethod({ method: 'GET', path: 'accounts/{id}', - urlParams: ['id'], }).apply(this, arguments); } else { if (id === null || id === undefined) { @@ -64,32 +60,27 @@ module.exports = StripeResource.extend({ createExternalAccount: stripeMethod({ method: 'POST', path: 'accounts/{accountId}/external_accounts', - urlParams: ['accountId'], }), listExternalAccounts: stripeMethod({ method: 'GET', path: 'accounts/{accountId}/external_accounts', - urlParams: ['accountId'], methodType: 'list', }), retrieveExternalAccount: stripeMethod({ method: 'GET', path: 'accounts/{accountId}/external_accounts/{externalAccountId}', - urlParams: ['accountId', 'externalAccountId'], }), updateExternalAccount: stripeMethod({ method: 'POST', path: 'accounts/{accountId}/external_accounts/{externalAccountId}', - urlParams: ['accountId', 'externalAccountId'], }), deleteExternalAccount: stripeMethod({ method: 'DELETE', path: 'accounts/{accountId}/external_accounts/{externalAccountId}', - urlParams: ['accountId', 'externalAccountId'], }), /** @@ -99,7 +90,6 @@ module.exports = StripeResource.extend({ createLoginLink: stripeMethod({ method: 'POST', path: 'accounts/{accountId}/login_links', - urlParams: ['accountId'], }), /** @@ -109,31 +99,26 @@ module.exports = StripeResource.extend({ createPerson: stripeMethod({ method: 'POST', path: 'accounts/{accountId}/persons', - urlParams: ['accountId'], }), listPersons: stripeMethod({ method: 'GET', path: 'accounts/{accountId}/persons', - urlParams: ['accountId'], methodType: 'list', }), retrievePerson: stripeMethod({ method: 'GET', path: 'accounts/{accountId}/persons/{personId}', - urlParams: ['accountId', 'personId'], }), updatePerson: stripeMethod({ method: 'POST', path: 'accounts/{accountId}/persons/{personId}', - urlParams: ['accountId', 'personId'], }), deletePerson: stripeMethod({ method: 'DELETE', path: 'accounts/{accountId}/persons/{personId}', - urlParams: ['accountId', 'personId'], }), }); diff --git a/lib/resources/ApplicationFees.js b/lib/resources/ApplicationFees.js index 3c676057f3..0a439cc1d0 100644 --- a/lib/resources/ApplicationFees.js +++ b/lib/resources/ApplicationFees.js @@ -11,25 +11,21 @@ module.exports = StripeResource.extend({ createRefund: stripeMethod({ method: 'POST', path: '/{feeId}/refunds', - urlParams: ['feeId'], }), listRefunds: stripeMethod({ method: 'GET', path: '/{feeId}/refunds', - urlParams: ['feeId'], methodType: 'list', }), retrieveRefund: stripeMethod({ method: 'GET', path: '/{feeId}/refunds/{refundId}', - urlParams: ['feeId', 'refundId'], }), updateRefund: stripeMethod({ method: 'POST', path: '/{feeId}/refunds/{refundId}', - urlParams: ['feeId', 'refundId'], }), }); diff --git a/lib/resources/BitcoinReceivers.js b/lib/resources/BitcoinReceivers.js index 7e4fe033c6..1ee13383e0 100644 --- a/lib/resources/BitcoinReceivers.js +++ b/lib/resources/BitcoinReceivers.js @@ -11,7 +11,6 @@ module.exports = StripeResource.extend({ listTransactions: stripeMethod({ method: 'GET', path: '/{id}/transactions', - urlParams: ['id'], methodType: 'list', }), }); diff --git a/lib/resources/Charges.js b/lib/resources/Charges.js index c29a54e1fd..1c5dd469eb 100644 --- a/lib/resources/Charges.js +++ b/lib/resources/Charges.js @@ -11,6 +11,5 @@ module.exports = StripeResource.extend({ capture: stripeMethod({ method: 'POST', path: '/{id}/capture', - urlParams: ['id'], }), }); diff --git a/lib/resources/CreditNotes.js b/lib/resources/CreditNotes.js index 5bf04705c5..e38dd295ca 100644 --- a/lib/resources/CreditNotes.js +++ b/lib/resources/CreditNotes.js @@ -11,6 +11,5 @@ module.exports = StripeResource.extend({ voidCreditNote: stripeMethod({ method: 'POST', path: '/{id}/void', - urlParams: ['id'], }), }); diff --git a/lib/resources/Customers.js b/lib/resources/Customers.js index cc57d9c108..1255184b93 100644 --- a/lib/resources/Customers.js +++ b/lib/resources/Customers.js @@ -15,7 +15,6 @@ module.exports = StripeResource.extend({ deleteDiscount: stripeMethod({ method: 'DELETE', path: '/{customerId}/discount', - urlParams: ['customerId'], }), /** @@ -25,38 +24,32 @@ module.exports = StripeResource.extend({ createSource: stripeMethod({ method: 'POST', path: '/{customerId}/sources', - urlParams: ['customerId'], }), listSources: stripeMethod({ method: 'GET', path: '/{customerId}/sources', - urlParams: ['customerId'], methodType: 'list', }), retrieveSource: stripeMethod({ method: 'GET', path: '/{customerId}/sources/{sourceId}', - urlParams: ['customerId', 'sourceId'], }), updateSource: stripeMethod({ method: 'POST', path: '/{customerId}/sources/{sourceId}', - urlParams: ['customerId', 'sourceId'], }), deleteSource: stripeMethod({ method: 'DELETE', path: '/{customerId}/sources/{sourceId}', - urlParams: ['customerId', 'sourceId'], }), verifySource: stripeMethod({ method: 'POST', path: '/{customerId}/sources/{sourceId}/verify', - urlParams: ['customerId', 'sourceId'], }), /** @@ -66,25 +59,21 @@ module.exports = StripeResource.extend({ createTaxId: stripeMethod({ method: 'POST', path: '/{customerId}/tax_ids', - urlParams: ['customerId'], }), deleteTaxId: stripeMethod({ method: 'DELETE', path: '/{customerId}/tax_ids/{taxIdId}', - urlParams: ['customerId', 'taxIdId'], }), listTaxIds: stripeMethod({ method: 'GET', path: '/{customerId}/tax_ids', - urlParams: ['customerId'], methodType: 'list', }), retrieveTaxId: stripeMethod({ method: 'GET', path: '/{customerId}/tax_ids/{taxIdId}', - urlParams: ['customerId', 'taxIdId'], }), }); diff --git a/lib/resources/Disputes.js b/lib/resources/Disputes.js index 836bf663f7..1d476249a0 100644 --- a/lib/resources/Disputes.js +++ b/lib/resources/Disputes.js @@ -8,5 +8,8 @@ module.exports = StripeResource.extend({ includeBasic: ['list', 'retrieve', 'update'], - close: stripeMethod({method: 'POST', path: '/{id}/close', urlParams: ['id']}), + close: stripeMethod({ + method: 'POST', + path: '/{id}/close', + }), }); diff --git a/lib/resources/Invoices.js b/lib/resources/Invoices.js index 6de26da88c..5faca3ff0c 100644 --- a/lib/resources/Invoices.js +++ b/lib/resources/Invoices.js @@ -11,13 +11,11 @@ module.exports = StripeResource.extend({ finalizeInvoice: stripeMethod({ method: 'POST', path: '{id}/finalize', - urlParams: ['id'], }), listLineItems: stripeMethod({ method: 'GET', path: '{id}/lines', - urlParams: ['id'], }), listUpcomingLineItems: stripeMethod({ @@ -28,13 +26,11 @@ module.exports = StripeResource.extend({ markUncollectible: stripeMethod({ method: 'POST', path: '{id}/mark_uncollectible', - urlParams: ['id'], }), pay: stripeMethod({ method: 'POST', path: '{id}/pay', - urlParams: ['id'], }), retrieveUpcoming: stripeMethod({ @@ -45,12 +41,10 @@ module.exports = StripeResource.extend({ sendInvoice: stripeMethod({ method: 'POST', path: '{id}/send', - urlParams: ['id'], }), voidInvoice: stripeMethod({ method: 'POST', path: '{id}/void', - urlParams: ['id'], }), }); diff --git a/lib/resources/Issuing/Authorizations.js b/lib/resources/Issuing/Authorizations.js index af8a3f55f2..1be1546969 100644 --- a/lib/resources/Issuing/Authorizations.js +++ b/lib/resources/Issuing/Authorizations.js @@ -11,12 +11,10 @@ module.exports = StripeResource.extend({ approve: stripeMethod({ method: 'POST', path: '/{id}/approve', - urlParams: ['id'], }), decline: stripeMethod({ method: 'POST', path: '/{id}/decline', - urlParams: ['id'], }), }); diff --git a/lib/resources/Issuing/Cards.js b/lib/resources/Issuing/Cards.js index 9f5e41b876..81475c9524 100644 --- a/lib/resources/Issuing/Cards.js +++ b/lib/resources/Issuing/Cards.js @@ -11,6 +11,5 @@ module.exports = StripeResource.extend({ retrieveDetails: stripeMethod({ method: 'GET', path: '/{id}/details', - urlParams: ['id'], }), }); diff --git a/lib/resources/Orders.js b/lib/resources/Orders.js index e368bae4bd..b242e3cf30 100644 --- a/lib/resources/Orders.js +++ b/lib/resources/Orders.js @@ -8,11 +8,13 @@ module.exports = StripeResource.extend({ includeBasic: ['create', 'list', 'retrieve', 'update'], - pay: stripeMethod({method: 'POST', path: '/{id}/pay', urlParams: ['id']}), + pay: stripeMethod({ + method: 'POST', + path: '/{id}/pay', + }), returnOrder: stripeMethod({ method: 'POST', path: '/{id}/returns', - urlParams: ['id'], }), }); diff --git a/lib/resources/PaymentIntents.js b/lib/resources/PaymentIntents.js index df99d2a36b..54da65e251 100644 --- a/lib/resources/PaymentIntents.js +++ b/lib/resources/PaymentIntents.js @@ -11,18 +11,15 @@ module.exports = StripeResource.extend({ cancel: stripeMethod({ method: 'POST', path: '/{id}/cancel', - urlParams: ['id'], }), capture: stripeMethod({ method: 'POST', path: '/{id}/capture', - urlParams: ['id'], }), confirm: stripeMethod({ method: 'POST', path: '/{id}/confirm', - urlParams: ['id'], }), }); diff --git a/lib/resources/PaymentMethods.js b/lib/resources/PaymentMethods.js index be727a6bbd..38e3bd893a 100644 --- a/lib/resources/PaymentMethods.js +++ b/lib/resources/PaymentMethods.js @@ -11,12 +11,10 @@ module.exports = StripeResource.extend({ attach: stripeMethod({ method: 'POST', path: '/{id}/attach', - urlParams: ['id'], }), detach: stripeMethod({ method: 'POST', path: '/{id}/detach', - urlParams: ['id'], }), }); diff --git a/lib/resources/Payouts.js b/lib/resources/Payouts.js index 384688e803..31785ef458 100644 --- a/lib/resources/Payouts.js +++ b/lib/resources/Payouts.js @@ -11,6 +11,5 @@ module.exports = StripeResource.extend({ cancel: stripeMethod({ method: 'POST', path: '/{id}/cancel', - urlParams: ['id'], }), }); diff --git a/lib/resources/Recipients.js b/lib/resources/Recipients.js index 2cff998537..84e594e701 100644 --- a/lib/resources/Recipients.js +++ b/lib/resources/Recipients.js @@ -15,31 +15,26 @@ module.exports = StripeResource.extend({ createCard: stripeMethod({ method: 'POST', path: '/{id}/cards', - urlParams: ['id'], }), listCards: stripeMethod({ method: 'GET', path: '/{id}/cards', - urlParams: ['id'], methodType: 'list', }), retrieveCard: stripeMethod({ method: 'GET', path: '/{recipientId}/cards/{cardId}', - urlParams: ['recipientId', 'cardId'], }), updateCard: stripeMethod({ method: 'POST', path: '/{recipientId}/cards/{cardId}', - urlParams: ['recipientId', 'cardId'], }), deleteCard: stripeMethod({ method: 'DELETE', path: '/{recipientId}/cards/{cardId}', - urlParams: ['recipientId', 'cardId'], }), }); diff --git a/lib/resources/Reviews.js b/lib/resources/Reviews.js index 40a150512d..8bbd670cff 100644 --- a/lib/resources/Reviews.js +++ b/lib/resources/Reviews.js @@ -11,6 +11,5 @@ module.exports = StripeResource.extend({ approve: stripeMethod({ method: 'POST', path: '/{id}/approve', - urlParams: ['id'], }), }); diff --git a/lib/resources/Sources.js b/lib/resources/Sources.js index ed213880d7..6afc7bbfe0 100644 --- a/lib/resources/Sources.js +++ b/lib/resources/Sources.js @@ -11,13 +11,11 @@ module.exports = StripeResource.extend({ listSourceTransactions: stripeMethod({ method: 'GET', path: '/{id}/source_transactions', - urlParams: ['id'], methodType: 'list', }), verify: stripeMethod({ method: 'POST', path: '/{id}/verify', - urlParams: ['id'], }), }); diff --git a/lib/resources/SubscriptionSchedules.js b/lib/resources/SubscriptionSchedules.js index e78ed46ef1..e803533c2c 100644 --- a/lib/resources/SubscriptionSchedules.js +++ b/lib/resources/SubscriptionSchedules.js @@ -11,25 +11,21 @@ module.exports = StripeResource.extend({ cancel: stripeMethod({ method: 'POST', path: '/{id}/cancel', - urlParams: ['id'], }), release: stripeMethod({ method: 'POST', path: '/{id}/release', - urlParams: ['id'], }), listRevisions: stripeMethod({ method: 'GET', path: '/{scheduleId}/revisions', - urlParams: ['scheduleId'], methodType: 'list', }), retrieveRevision: stripeMethod({ method: 'GET', path: '/{scheduleId}/revisions/{revisionId}', - urlParams: ['scheduleId', 'revisionId'], }), }); diff --git a/lib/resources/Subscriptions.js b/lib/resources/Subscriptions.js index 72290a31a5..3b404c2eb8 100644 --- a/lib/resources/Subscriptions.js +++ b/lib/resources/Subscriptions.js @@ -11,6 +11,5 @@ module.exports = StripeResource.extend({ deleteDiscount: stripeMethod({ method: 'DELETE', path: '/{id}/discount', - urlParams: ['id'], }), }); diff --git a/lib/resources/Topups.js b/lib/resources/Topups.js index d2f487a8d7..eecb88207d 100644 --- a/lib/resources/Topups.js +++ b/lib/resources/Topups.js @@ -11,6 +11,5 @@ module.exports = StripeResource.extend({ cancel: stripeMethod({ method: 'POST', path: '/{id}/cancel', - urlParams: ['id'], }), }); diff --git a/lib/resources/Transfers.js b/lib/resources/Transfers.js index 3bbe6f8d9e..75f0007ac7 100644 --- a/lib/resources/Transfers.js +++ b/lib/resources/Transfers.js @@ -14,25 +14,21 @@ module.exports = StripeResource.extend({ createReversal: stripeMethod({ method: 'POST', path: '/{id}/reversals', - urlParams: ['id'], }), listReversals: stripeMethod({ method: 'GET', path: '/{id}/reversals', - urlParams: ['id'], methodType: 'list', }), retrieveReversal: stripeMethod({ method: 'GET', path: '/{transferId}/reversals/{reversalId}', - urlParams: ['transferId', 'reversalId'], }), updateReversal: stripeMethod({ method: 'POST', path: '/{transferId}/reversals/{reversalId}', - urlParams: ['transferId', 'reversalId'], }), }); diff --git a/lib/resources/UsageRecordSummaries.js b/lib/resources/UsageRecordSummaries.js index 8a59a43ef6..db4722188a 100644 --- a/lib/resources/UsageRecordSummaries.js +++ b/lib/resources/UsageRecordSummaries.js @@ -9,7 +9,6 @@ module.exports = StripeResource.extend({ list: stripeMethod({ method: 'GET', path: '{subscriptionItem}/usage_record_summaries', - urlParams: ['subscriptionItem'], methodType: 'list', }), }); diff --git a/lib/resources/UsageRecords.js b/lib/resources/UsageRecords.js index c45d448a65..ad8960b8b2 100644 --- a/lib/resources/UsageRecords.js +++ b/lib/resources/UsageRecords.js @@ -9,6 +9,5 @@ module.exports = StripeResource.extend({ create: stripeMethod({ method: 'POST', path: '/{id}/usage_records', - urlParams: ['id'], }), }); From e52219b22f54fec74ca4221a321fea5e847ea68d Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 21:40:57 -0700 Subject: [PATCH 06/10] Add a deprecation error message --- lib/StripeResource.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/StripeResource.js b/lib/StripeResource.js index e11876781a..cfe509156a 100644 --- a/lib/StripeResource.js +++ b/lib/StripeResource.js @@ -23,8 +23,13 @@ StripeResource.MAX_BUFFERED_REQUEST_METRICS = 100; /** * Encapsulates request logic for a Stripe Resource */ -function StripeResource(stripe) { +function StripeResource(stripe, deprecatedUrlData) { this._stripe = stripe; + if (deprecatedUrlData) { + throw new Error( + 'Support for curried url params was dropped in stripe-node v7.0.0. Instead, pass two ids.' + ); + } this.basePath = utils.makeURLInterpolator( this.basePath || stripe.getApiField('basePath') From e5eccb85dc87dd4406766c97131445629ea1e6c2 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 21:48:47 -0700 Subject: [PATCH 07/10] Revert "Delete nested resource files" This reverts commit d88a3e715b20cbe9478b05140e825c381bc5f817. --- lib/resources/ApplicationFeeRefunds.js | 21 +++++ lib/resources/LoginLinks.js | 9 +++ lib/resources/Persons.js | 9 +++ .../SubscriptionScheduleRevisions.js | 9 +++ lib/resources/TaxIds.js | 9 +++ lib/resources/TransferReversals.js | 9 +++ lib/stripe.js | 8 ++ test/resources/ApplicationFeeRefunds.spec.js | 56 +++++++++++++ test/resources/LoginLinks.spec.js | 27 +++++++ test/resources/Persons.spec.js | 80 +++++++++++++++++++ .../SubscriptionScheduleRevision.spec.js | 42 ++++++++++ test/resources/TaxIds.spec.js | 67 ++++++++++++++++ test/resources/TransferReversals.spec.js | 70 ++++++++++++++++ 13 files changed, 416 insertions(+) create mode 100644 lib/resources/ApplicationFeeRefunds.js create mode 100644 lib/resources/LoginLinks.js create mode 100644 lib/resources/Persons.js create mode 100644 lib/resources/SubscriptionScheduleRevisions.js create mode 100644 lib/resources/TaxIds.js create mode 100644 lib/resources/TransferReversals.js create mode 100644 test/resources/ApplicationFeeRefunds.spec.js create mode 100644 test/resources/LoginLinks.spec.js create mode 100644 test/resources/Persons.spec.js create mode 100644 test/resources/SubscriptionScheduleRevision.spec.js create mode 100644 test/resources/TaxIds.spec.js create mode 100644 test/resources/TransferReversals.spec.js diff --git a/lib/resources/ApplicationFeeRefunds.js b/lib/resources/ApplicationFeeRefunds.js new file mode 100644 index 0000000000..68d92045be --- /dev/null +++ b/lib/resources/ApplicationFeeRefunds.js @@ -0,0 +1,21 @@ +'use strict'; + +const StripeResource = require('../StripeResource'); + +/** + * ApplicationFeeRefunds is a unique resource in that, upon instantiation, + * requires an application fee id , and therefore each of its methods only + * require the refundId argument. + * + * This streamlines the API specifically for the case of accessing refunds + * on a returned application fee object. + * + * E.g. applicationFeeObject.refunds.retrieve(refundId) + * (As opposed to the also-supported stripe.applicationFees.retrieveRefund(chargeId, + * refundId)) + */ +module.exports = StripeResource.extend({ + path: 'application_fees/{feeId}/refunds', + + includeBasic: ['create', 'list', 'retrieve', 'update'], +}); diff --git a/lib/resources/LoginLinks.js b/lib/resources/LoginLinks.js new file mode 100644 index 0000000000..842a447ddb --- /dev/null +++ b/lib/resources/LoginLinks.js @@ -0,0 +1,9 @@ +'use strict'; + +const StripeResource = require('../StripeResource'); + +module.exports = StripeResource.extend({ + path: 'accounts/{accountId}/login_links', + + includeBasic: ['create'], +}); diff --git a/lib/resources/Persons.js b/lib/resources/Persons.js new file mode 100644 index 0000000000..921561ea64 --- /dev/null +++ b/lib/resources/Persons.js @@ -0,0 +1,9 @@ +'use strict'; + +const StripeResource = require('../StripeResource'); + +module.exports = StripeResource.extend({ + path: 'accounts/{accountId}/persons', + + includeBasic: ['create', 'del', 'list', 'retrieve', 'update'], +}); diff --git a/lib/resources/SubscriptionScheduleRevisions.js b/lib/resources/SubscriptionScheduleRevisions.js new file mode 100644 index 0000000000..7748b9a721 --- /dev/null +++ b/lib/resources/SubscriptionScheduleRevisions.js @@ -0,0 +1,9 @@ +'use strict'; + +const StripeResource = require('../StripeResource'); + +module.exports = StripeResource.extend({ + path: 'subscription_schedules/{scheduleId}/revisions', + + includeBasic: ['list', 'retrieve'], +}); diff --git a/lib/resources/TaxIds.js b/lib/resources/TaxIds.js new file mode 100644 index 0000000000..7cc865bd87 --- /dev/null +++ b/lib/resources/TaxIds.js @@ -0,0 +1,9 @@ +'use strict'; + +const StripeResource = require('../StripeResource'); + +module.exports = StripeResource.extend({ + path: 'customers/{customerId}/tax_ids', + + includeBasic: ['create', 'del', 'list', 'retrieve'], +}); diff --git a/lib/resources/TransferReversals.js b/lib/resources/TransferReversals.js new file mode 100644 index 0000000000..207b653491 --- /dev/null +++ b/lib/resources/TransferReversals.js @@ -0,0 +1,9 @@ +'use strict'; + +const StripeResource = require('../StripeResource'); + +module.exports = StripeResource.extend({ + path: 'transfers/{transferId}/reversals', + + includeBasic: ['create', 'list', 'retrieve', 'update'], +}); diff --git a/lib/stripe.js b/lib/stripe.js index 99777370ef..4250054163 100644 --- a/lib/stripe.js +++ b/lib/stripe.js @@ -55,6 +55,7 @@ const resources = { InvoiceItems: require('./resources/InvoiceItems'), Invoices: require('./resources/Invoices'), IssuerFraudRecords: require('./resources/IssuerFraudRecords'), + LoginLinks: require('./resources/LoginLinks'), OAuth: require('./resources/OAuth'), OrderReturns: require('./resources/OrderReturns'), Orders: require('./resources/Orders'), @@ -80,6 +81,13 @@ const resources = { UsageRecordSummaries: require('./resources/UsageRecordSummaries'), WebhookEndpoints: require('./resources/WebhookEndpoints'), + // The following rely on pre-filled IDs: + ApplicationFeeRefunds: require('./resources/ApplicationFeeRefunds'), + Persons: require('./resources/Persons'), + SubscriptionScheduleRevisions: require('./resources/SubscriptionScheduleRevisions'), + TaxIds: require('./resources/TaxIds'), + TransferReversals: require('./resources/TransferReversals'), + // Namespaced resources Checkout: resourceNamespace('checkout', { Sessions: require('./resources/Checkout/Sessions'), diff --git a/test/resources/ApplicationFeeRefunds.spec.js b/test/resources/ApplicationFeeRefunds.spec.js new file mode 100644 index 0000000000..75be78aa2e --- /dev/null +++ b/test/resources/ApplicationFeeRefunds.spec.js @@ -0,0 +1,56 @@ +'use strict'; + +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; + +const APPFEE_TEST_ID = 'appFeeIdTest999'; +const REFUND_TEST_ID = 'refundIdTest999'; + +// Create new CustomerCard instance with pre-filled customerId: +const appFeeRefund = new resources.ApplicationFeeRefunds(stripe, { + feeId: APPFEE_TEST_ID, +}); + +// Use spy from existing resource: +appFeeRefund._request = stripe.customers._request; + +describe('ApplicationFeeRefund Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { + appFeeRefund.retrieve(REFUND_TEST_ID); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, + data: {}, + headers: {}, + }); + }); + }); + + describe('update', () => { + it('Sends the correct request', () => { + appFeeRefund.update(REFUND_TEST_ID, { + metadata: {key: 'value'}, + }); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'POST', + url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, + data: {metadata: {key: 'value'}}, + headers: {}, + }); + }); + }); + + describe('list', () => { + it('Sends the correct request', () => { + appFeeRefund.list(); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds`, + data: {}, + headers: {}, + }); + }); + }); +}); diff --git a/test/resources/LoginLinks.spec.js b/test/resources/LoginLinks.spec.js new file mode 100644 index 0000000000..f8c6c36183 --- /dev/null +++ b/test/resources/LoginLinks.spec.js @@ -0,0 +1,27 @@ +'use strict'; + +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; + +const ACCOUNT_ID = 'acct_EXPRESS'; + +// Create new LoginLink instance with pre-filled accountId: +const loginLink = new resources.LoginLinks(stripe, {accountId: ACCOUNT_ID}); + +// Use spy from existing resource: +loginLink._request = stripe.customers._request; + +describe('LoginLink Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { + loginLink.create(); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'POST', + url: `/v1/accounts/${ACCOUNT_ID}/login_links`, + headers: {}, + data: {}, + }); + }); + }); +}); diff --git a/test/resources/Persons.spec.js b/test/resources/Persons.spec.js new file mode 100644 index 0000000000..0b199f6715 --- /dev/null +++ b/test/resources/Persons.spec.js @@ -0,0 +1,80 @@ +'use strict'; + +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; + +const ACCOUNT_TEST_ID = 'acct_123'; +const PERSON_TEST_ID = 'person_123'; + +// Create new Person instance with pre-filled accountId: +const person = new resources.Persons(stripe, {accountId: ACCOUNT_TEST_ID}); + +// Use spy from existing resource: +person._request = stripe.customers._request; + +describe('Person Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { + person.create({ + first_name: 'John', + }); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'POST', + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, + data: {first_name: 'John'}, + headers: {}, + }); + }); + }); + + describe('delete', () => { + it('Sends the correct request', () => { + person.del(PERSON_TEST_ID); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'DELETE', + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, + data: {}, + headers: {}, + }); + }); + }); + + describe('list', () => { + it('Sends the correct request', () => { + person.list(); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, + data: {}, + headers: {}, + }); + }); + }); + + describe('retrieve', () => { + it('Sends the correct request', () => { + person.retrieve(PERSON_TEST_ID); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, + data: {}, + headers: {}, + }); + }); + }); + + describe('update', () => { + it('Sends the correct request', () => { + person.update(PERSON_TEST_ID, { + first_name: 'John', + }); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'POST', + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, + data: {first_name: 'John'}, + headers: {}, + }); + }); + }); +}); diff --git a/test/resources/SubscriptionScheduleRevision.spec.js b/test/resources/SubscriptionScheduleRevision.spec.js new file mode 100644 index 0000000000..4c15320d7a --- /dev/null +++ b/test/resources/SubscriptionScheduleRevision.spec.js @@ -0,0 +1,42 @@ +'use strict'; + +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; + +const SCHEDULE_TEST_ID = 'sub_sched_123'; +const REVISION_TEST_ID = 'sub_sched_rev_123'; + +// Create new SubscriptionScheduleRevision instance with pre-filled scheduleId: +const revision = new resources.SubscriptionScheduleRevisions(stripe, { + scheduleId: SCHEDULE_TEST_ID, +}); + +// Use spy from existing resource: +revision._request = stripe.customers._request; + +describe('SubscriptionScheduleRevision Resource', () => { + describe('list', () => { + it('Sends the correct request', () => { + revision.list(); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions`, + data: {}, + headers: {}, + }); + }); + }); + + describe('retrieve', () => { + it('Sends the correct request', () => { + revision.retrieve(REVISION_TEST_ID); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions/${REVISION_TEST_ID}`, + data: {}, + headers: {}, + }); + }); + }); +}); diff --git a/test/resources/TaxIds.spec.js b/test/resources/TaxIds.spec.js new file mode 100644 index 0000000000..fda30f9faa --- /dev/null +++ b/test/resources/TaxIds.spec.js @@ -0,0 +1,67 @@ +'use strict'; + +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; + +const CUSTOMER_TEST_ID = 'cus_123'; +const TAX_ID_TEST_ID = 'txi_123'; + +const taxId = new resources.TaxIds(stripe, {customerId: CUSTOMER_TEST_ID}); + +// Use spy from existing resource: +taxId._request = stripe.customers._request; + +describe('TaxId Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { + const data = { + type: 'eu_vat', + value: '11111', + }; + taxId.create(data); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'POST', + url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, + data, + headers: {}, + }); + }); + }); + + describe('delete', () => { + it('Sends the correct request', () => { + taxId.del(TAX_ID_TEST_ID); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'DELETE', + url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, + data: {}, + headers: {}, + }); + }); + }); + + describe('list', () => { + it('Sends the correct request', () => { + taxId.list(); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, + data: {}, + headers: {}, + }); + }); + }); + + describe('retrieve', () => { + it('Sends the correct request', () => { + taxId.retrieve(TAX_ID_TEST_ID); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, + data: {}, + headers: {}, + }); + }); + }); +}); diff --git a/test/resources/TransferReversals.spec.js b/test/resources/TransferReversals.spec.js new file mode 100644 index 0000000000..3b0c9e67fb --- /dev/null +++ b/test/resources/TransferReversals.spec.js @@ -0,0 +1,70 @@ +'use strict'; + +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; + +const TRANSFER_TEST_ID = 'transferIdTest999'; +const REVERSAL_TEST_ID = 'reversalIdTest999'; + +// Create new CustomerCard instance with pre-filled customerId: +const transferReversal = new resources.TransferReversals(stripe, { + transferId: TRANSFER_TEST_ID, +}); + +// Use spy from existing resource: +transferReversal._request = stripe.customers._request; + +describe('TransferReversal Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { + transferReversal.retrieve(REVERSAL_TEST_ID); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, + data: {}, + headers: {}, + }); + }); + }); + + describe('create', () => { + it('Sends the correct request', () => { + transferReversal.create({ + amount: 100, + }); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'POST', + url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, + data: {amount: 100}, + headers: {}, + }); + }); + }); + + describe('update', () => { + it('Sends the correct request', () => { + transferReversal.update(REVERSAL_TEST_ID, { + metadata: {key: 'value'}, + }); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'POST', + url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, + data: {metadata: {key: 'value'}}, + headers: {}, + }); + }); + }); + + describe('list', () => { + it('Sends the correct request', () => { + transferReversal.list(); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, + data: {}, + headers: {}, + }); + }); + }); +}); From 71d5200f64655e200708a5ec5d5c23fbf39b79db Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 22:08:15 -0700 Subject: [PATCH 08/10] Fix nested resources for non-curried urlParams and update tests to demonstrate their use --- lib/StripeMethod.js | 6 ++++-- lib/resources/ApplicationFeeRefunds.js | 12 ------------ test/resources/ApplicationFeeRefunds.spec.js | 15 +++------------ test/resources/LoginLinks.spec.js | 9 +-------- test/resources/Persons.spec.js | 17 +++++------------ .../SubscriptionScheduleRevision.spec.js | 16 +++++----------- test/resources/TaxIds.spec.js | 14 ++++---------- test/resources/TransferReversals.spec.js | 17 ++++------------- 8 files changed, 26 insertions(+), 80 deletions(-) diff --git a/lib/StripeMethod.js b/lib/StripeMethod.js index 68a5558ef4..dd8c6b846e 100644 --- a/lib/StripeMethod.js +++ b/lib/StripeMethod.js @@ -20,14 +20,16 @@ const makeAutoPaginationMethods = require('./autoPagination') * @param [spec.host] Hostname for the request. */ function stripeMethod(spec) { - spec.urlParams = utils.extractUrlParams(spec.path || ''); - return function() { const self = this; const args = [].slice.call(arguments); const callback = typeof args[args.length - 1] == 'function' && args.pop(); + spec.urlParams = utils.extractUrlParams( + self.createResourcePathWithSymbols(spec.path || '') + ); + const requestPromise = utils.callbackifyPromiseWithTimeout( makeRequest(self, args, spec, {}), callback diff --git a/lib/resources/ApplicationFeeRefunds.js b/lib/resources/ApplicationFeeRefunds.js index 68d92045be..bc09bd53b8 100644 --- a/lib/resources/ApplicationFeeRefunds.js +++ b/lib/resources/ApplicationFeeRefunds.js @@ -2,18 +2,6 @@ const StripeResource = require('../StripeResource'); -/** - * ApplicationFeeRefunds is a unique resource in that, upon instantiation, - * requires an application fee id , and therefore each of its methods only - * require the refundId argument. - * - * This streamlines the API specifically for the case of accessing refunds - * on a returned application fee object. - * - * E.g. applicationFeeObject.refunds.retrieve(refundId) - * (As opposed to the also-supported stripe.applicationFees.retrieveRefund(chargeId, - * refundId)) - */ module.exports = StripeResource.extend({ path: 'application_fees/{feeId}/refunds', diff --git a/test/resources/ApplicationFeeRefunds.spec.js b/test/resources/ApplicationFeeRefunds.spec.js index 75be78aa2e..82e36e219b 100644 --- a/test/resources/ApplicationFeeRefunds.spec.js +++ b/test/resources/ApplicationFeeRefunds.spec.js @@ -1,24 +1,15 @@ 'use strict'; -const resources = require('../../lib/stripe').resources; const stripe = require('../../testUtils').getSpyableStripe(); const expect = require('chai').expect; const APPFEE_TEST_ID = 'appFeeIdTest999'; const REFUND_TEST_ID = 'refundIdTest999'; -// Create new CustomerCard instance with pre-filled customerId: -const appFeeRefund = new resources.ApplicationFeeRefunds(stripe, { - feeId: APPFEE_TEST_ID, -}); - -// Use spy from existing resource: -appFeeRefund._request = stripe.customers._request; - describe('ApplicationFeeRefund Resource', () => { describe('retrieve', () => { it('Sends the correct request', () => { - appFeeRefund.retrieve(REFUND_TEST_ID); + stripe.applicationFeeRefunds.retrieve(APPFEE_TEST_ID, REFUND_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, @@ -30,7 +21,7 @@ describe('ApplicationFeeRefund Resource', () => { describe('update', () => { it('Sends the correct request', () => { - appFeeRefund.update(REFUND_TEST_ID, { + stripe.applicationFeeRefunds.update(APPFEE_TEST_ID, REFUND_TEST_ID, { metadata: {key: 'value'}, }); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -44,7 +35,7 @@ describe('ApplicationFeeRefund Resource', () => { describe('list', () => { it('Sends the correct request', () => { - appFeeRefund.list(); + stripe.applicationFeeRefunds.list(APPFEE_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds`, diff --git a/test/resources/LoginLinks.spec.js b/test/resources/LoginLinks.spec.js index f8c6c36183..af54de161d 100644 --- a/test/resources/LoginLinks.spec.js +++ b/test/resources/LoginLinks.spec.js @@ -1,21 +1,14 @@ 'use strict'; -const resources = require('../../lib/stripe').resources; const stripe = require('../../testUtils').getSpyableStripe(); const expect = require('chai').expect; const ACCOUNT_ID = 'acct_EXPRESS'; -// Create new LoginLink instance with pre-filled accountId: -const loginLink = new resources.LoginLinks(stripe, {accountId: ACCOUNT_ID}); - -// Use spy from existing resource: -loginLink._request = stripe.customers._request; - describe('LoginLink Resource', () => { describe('create', () => { it('Sends the correct request', () => { - loginLink.create(); + stripe.loginLinks.create(ACCOUNT_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', url: `/v1/accounts/${ACCOUNT_ID}/login_links`, diff --git a/test/resources/Persons.spec.js b/test/resources/Persons.spec.js index 0b199f6715..0936e4cc6c 100644 --- a/test/resources/Persons.spec.js +++ b/test/resources/Persons.spec.js @@ -1,22 +1,15 @@ 'use strict'; -const resources = require('../../lib/stripe').resources; const stripe = require('../../testUtils').getSpyableStripe(); const expect = require('chai').expect; const ACCOUNT_TEST_ID = 'acct_123'; const PERSON_TEST_ID = 'person_123'; -// Create new Person instance with pre-filled accountId: -const person = new resources.Persons(stripe, {accountId: ACCOUNT_TEST_ID}); - -// Use spy from existing resource: -person._request = stripe.customers._request; - describe('Person Resource', () => { describe('create', () => { it('Sends the correct request', () => { - person.create({ + stripe.persons.create(ACCOUNT_TEST_ID, { first_name: 'John', }); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -30,7 +23,7 @@ describe('Person Resource', () => { describe('delete', () => { it('Sends the correct request', () => { - person.del(PERSON_TEST_ID); + stripe.persons.del(ACCOUNT_TEST_ID, PERSON_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, @@ -42,7 +35,7 @@ describe('Person Resource', () => { describe('list', () => { it('Sends the correct request', () => { - person.list(); + stripe.persons.list(ACCOUNT_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, @@ -54,7 +47,7 @@ describe('Person Resource', () => { describe('retrieve', () => { it('Sends the correct request', () => { - person.retrieve(PERSON_TEST_ID); + stripe.persons.retrieve(ACCOUNT_TEST_ID, PERSON_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, @@ -66,7 +59,7 @@ describe('Person Resource', () => { describe('update', () => { it('Sends the correct request', () => { - person.update(PERSON_TEST_ID, { + stripe.persons.update(ACCOUNT_TEST_ID, PERSON_TEST_ID, { first_name: 'John', }); expect(stripe.LAST_REQUEST).to.deep.equal({ diff --git a/test/resources/SubscriptionScheduleRevision.spec.js b/test/resources/SubscriptionScheduleRevision.spec.js index 4c15320d7a..ba17bb95ad 100644 --- a/test/resources/SubscriptionScheduleRevision.spec.js +++ b/test/resources/SubscriptionScheduleRevision.spec.js @@ -1,24 +1,15 @@ 'use strict'; -const resources = require('../../lib/stripe').resources; const stripe = require('../../testUtils').getSpyableStripe(); const expect = require('chai').expect; const SCHEDULE_TEST_ID = 'sub_sched_123'; const REVISION_TEST_ID = 'sub_sched_rev_123'; -// Create new SubscriptionScheduleRevision instance with pre-filled scheduleId: -const revision = new resources.SubscriptionScheduleRevisions(stripe, { - scheduleId: SCHEDULE_TEST_ID, -}); - -// Use spy from existing resource: -revision._request = stripe.customers._request; - describe('SubscriptionScheduleRevision Resource', () => { describe('list', () => { it('Sends the correct request', () => { - revision.list(); + stripe.subscriptionScheduleRevisions.list(SCHEDULE_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions`, @@ -30,7 +21,10 @@ describe('SubscriptionScheduleRevision Resource', () => { describe('retrieve', () => { it('Sends the correct request', () => { - revision.retrieve(REVISION_TEST_ID); + stripe.subscriptionScheduleRevisions.retrieve( + SCHEDULE_TEST_ID, + REVISION_TEST_ID + ); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions/${REVISION_TEST_ID}`, diff --git a/test/resources/TaxIds.spec.js b/test/resources/TaxIds.spec.js index fda30f9faa..6062de4c70 100644 --- a/test/resources/TaxIds.spec.js +++ b/test/resources/TaxIds.spec.js @@ -1,17 +1,11 @@ 'use strict'; -const resources = require('../../lib/stripe').resources; const stripe = require('../../testUtils').getSpyableStripe(); const expect = require('chai').expect; const CUSTOMER_TEST_ID = 'cus_123'; const TAX_ID_TEST_ID = 'txi_123'; -const taxId = new resources.TaxIds(stripe, {customerId: CUSTOMER_TEST_ID}); - -// Use spy from existing resource: -taxId._request = stripe.customers._request; - describe('TaxId Resource', () => { describe('create', () => { it('Sends the correct request', () => { @@ -19,7 +13,7 @@ describe('TaxId Resource', () => { type: 'eu_vat', value: '11111', }; - taxId.create(data); + stripe.taxIds.create(CUSTOMER_TEST_ID, data); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, @@ -31,7 +25,7 @@ describe('TaxId Resource', () => { describe('delete', () => { it('Sends the correct request', () => { - taxId.del(TAX_ID_TEST_ID); + stripe.taxIds.del(CUSTOMER_TEST_ID, TAX_ID_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, @@ -43,7 +37,7 @@ describe('TaxId Resource', () => { describe('list', () => { it('Sends the correct request', () => { - taxId.list(); + stripe.taxIds.list(CUSTOMER_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, @@ -55,7 +49,7 @@ describe('TaxId Resource', () => { describe('retrieve', () => { it('Sends the correct request', () => { - taxId.retrieve(TAX_ID_TEST_ID); + stripe.taxIds.retrieve(CUSTOMER_TEST_ID, TAX_ID_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, diff --git a/test/resources/TransferReversals.spec.js b/test/resources/TransferReversals.spec.js index 3b0c9e67fb..8c8dbeffd7 100644 --- a/test/resources/TransferReversals.spec.js +++ b/test/resources/TransferReversals.spec.js @@ -1,24 +1,15 @@ 'use strict'; -const resources = require('../../lib/stripe').resources; const stripe = require('../../testUtils').getSpyableStripe(); const expect = require('chai').expect; const TRANSFER_TEST_ID = 'transferIdTest999'; const REVERSAL_TEST_ID = 'reversalIdTest999'; -// Create new CustomerCard instance with pre-filled customerId: -const transferReversal = new resources.TransferReversals(stripe, { - transferId: TRANSFER_TEST_ID, -}); - -// Use spy from existing resource: -transferReversal._request = stripe.customers._request; - describe('TransferReversal Resource', () => { describe('retrieve', () => { it('Sends the correct request', () => { - transferReversal.retrieve(REVERSAL_TEST_ID); + stripe.transferReversals.retrieve(TRANSFER_TEST_ID, REVERSAL_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, @@ -30,7 +21,7 @@ describe('TransferReversal Resource', () => { describe('create', () => { it('Sends the correct request', () => { - transferReversal.create({ + stripe.transferReversals.create(TRANSFER_TEST_ID, { amount: 100, }); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -44,7 +35,7 @@ describe('TransferReversal Resource', () => { describe('update', () => { it('Sends the correct request', () => { - transferReversal.update(REVERSAL_TEST_ID, { + stripe.transferReversals.update(TRANSFER_TEST_ID, REVERSAL_TEST_ID, { metadata: {key: 'value'}, }); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -58,7 +49,7 @@ describe('TransferReversal Resource', () => { describe('list', () => { it('Sends the correct request', () => { - transferReversal.list(); + stripe.transferReversals.list(TRANSFER_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, From f650b77386508a343e70958bb4f2b1f9ee0471fa Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Thu, 9 May 2019 22:23:20 -0700 Subject: [PATCH 09/10] Refactor makeRequest --- lib/makeRequest.js | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/lib/makeRequest.js b/lib/makeRequest.js index 57f08d5268..c6b105b980 100644 --- a/lib/makeRequest.js +++ b/lib/makeRequest.js @@ -9,39 +9,23 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { const urlParams = spec.urlParams || []; const encode = spec.encode || ((data) => data); const host = spec.host; + const path = self.createResourcePathWithSymbols(spec.path); // Don't mutate args externally. const args = [].slice.call(requestArgs); // Generate and validate url params. - const urlData = {}; - for (let i = 0, l = urlParams.length; i < l; ++i) { - var path; - - // Note that we shift the args array after every iteration so this just - // grabs the "next" argument for use as a URL parameter. - const arg = args[0]; - - const param = urlParams[i]; - - if (param == 'id' && typeof arg !== 'string') { - path = self.createResourcePathWithSymbols(spec.path); - throw new Error( - `Stripe: "id" must be a string, but got: ${typeof arg} (on API request to \`${requestMethod} ${path}\`)` - ); - } - - if (!arg) { - path = self.createResourcePathWithSymbols(spec.path); + const urlData = urlParams.reduce((urlData, param) => { + const arg = args.shift(); + if (typeof arg !== 'string') { throw new Error( - `Stripe: Argument "${ - urlParams[i] - }" required, but got: ${arg} (on API request to \`${requestMethod} ${path}\`)` + `Stripe: Argument "${param}" must be a string, but got: ${arg} (on API request to \`${requestMethod} ${path}\`)` ); } - urlData[param] = args.shift(); - } + urlData[param] = arg; + return urlData; + }, {}); // Pull request data and options (headers, auth) from args. const dataFromArgs = utils.getDataFromArgs(args); @@ -50,7 +34,6 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { // Validate that there are no more args. if (args.length) { - path = self.createResourcePathWithSymbols(spec.path); throw new Error( `Stripe: Unknown arguments (${args}). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options. (on API request to ${requestMethod} \`${path}\`)` ); From d58bbf8a648d0390147dbd2fc74a68fe8c8052c5 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Fri, 10 May 2019 12:30:57 -0700 Subject: [PATCH 10/10] Revert "Revert "Delete nested resource files"" This reverts commit e5eccb85dc87dd4406766c97131445629ea1e6c2. --- lib/resources/ApplicationFeeRefunds.js | 9 --- lib/resources/LoginLinks.js | 9 --- lib/resources/Persons.js | 9 --- .../SubscriptionScheduleRevisions.js | 9 --- lib/resources/TaxIds.js | 9 --- lib/resources/TransferReversals.js | 9 --- lib/stripe.js | 8 -- test/resources/ApplicationFeeRefunds.spec.js | 47 ------------ test/resources/LoginLinks.spec.js | 20 ----- test/resources/Persons.spec.js | 73 ------------------- .../SubscriptionScheduleRevision.spec.js | 36 --------- test/resources/TaxIds.spec.js | 61 ---------------- test/resources/TransferReversals.spec.js | 61 ---------------- 13 files changed, 360 deletions(-) delete mode 100644 lib/resources/ApplicationFeeRefunds.js delete mode 100644 lib/resources/LoginLinks.js delete mode 100644 lib/resources/Persons.js delete mode 100644 lib/resources/SubscriptionScheduleRevisions.js delete mode 100644 lib/resources/TaxIds.js delete mode 100644 lib/resources/TransferReversals.js delete mode 100644 test/resources/ApplicationFeeRefunds.spec.js delete mode 100644 test/resources/LoginLinks.spec.js delete mode 100644 test/resources/Persons.spec.js delete mode 100644 test/resources/SubscriptionScheduleRevision.spec.js delete mode 100644 test/resources/TaxIds.spec.js delete mode 100644 test/resources/TransferReversals.spec.js diff --git a/lib/resources/ApplicationFeeRefunds.js b/lib/resources/ApplicationFeeRefunds.js deleted file mode 100644 index bc09bd53b8..0000000000 --- a/lib/resources/ApplicationFeeRefunds.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'application_fees/{feeId}/refunds', - - includeBasic: ['create', 'list', 'retrieve', 'update'], -}); diff --git a/lib/resources/LoginLinks.js b/lib/resources/LoginLinks.js deleted file mode 100644 index 842a447ddb..0000000000 --- a/lib/resources/LoginLinks.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'accounts/{accountId}/login_links', - - includeBasic: ['create'], -}); diff --git a/lib/resources/Persons.js b/lib/resources/Persons.js deleted file mode 100644 index 921561ea64..0000000000 --- a/lib/resources/Persons.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'accounts/{accountId}/persons', - - includeBasic: ['create', 'del', 'list', 'retrieve', 'update'], -}); diff --git a/lib/resources/SubscriptionScheduleRevisions.js b/lib/resources/SubscriptionScheduleRevisions.js deleted file mode 100644 index 7748b9a721..0000000000 --- a/lib/resources/SubscriptionScheduleRevisions.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'subscription_schedules/{scheduleId}/revisions', - - includeBasic: ['list', 'retrieve'], -}); diff --git a/lib/resources/TaxIds.js b/lib/resources/TaxIds.js deleted file mode 100644 index 7cc865bd87..0000000000 --- a/lib/resources/TaxIds.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'customers/{customerId}/tax_ids', - - includeBasic: ['create', 'del', 'list', 'retrieve'], -}); diff --git a/lib/resources/TransferReversals.js b/lib/resources/TransferReversals.js deleted file mode 100644 index 207b653491..0000000000 --- a/lib/resources/TransferReversals.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -module.exports = StripeResource.extend({ - path: 'transfers/{transferId}/reversals', - - includeBasic: ['create', 'list', 'retrieve', 'update'], -}); diff --git a/lib/stripe.js b/lib/stripe.js index 4250054163..99777370ef 100644 --- a/lib/stripe.js +++ b/lib/stripe.js @@ -55,7 +55,6 @@ const resources = { InvoiceItems: require('./resources/InvoiceItems'), Invoices: require('./resources/Invoices'), IssuerFraudRecords: require('./resources/IssuerFraudRecords'), - LoginLinks: require('./resources/LoginLinks'), OAuth: require('./resources/OAuth'), OrderReturns: require('./resources/OrderReturns'), Orders: require('./resources/Orders'), @@ -81,13 +80,6 @@ const resources = { UsageRecordSummaries: require('./resources/UsageRecordSummaries'), WebhookEndpoints: require('./resources/WebhookEndpoints'), - // The following rely on pre-filled IDs: - ApplicationFeeRefunds: require('./resources/ApplicationFeeRefunds'), - Persons: require('./resources/Persons'), - SubscriptionScheduleRevisions: require('./resources/SubscriptionScheduleRevisions'), - TaxIds: require('./resources/TaxIds'), - TransferReversals: require('./resources/TransferReversals'), - // Namespaced resources Checkout: resourceNamespace('checkout', { Sessions: require('./resources/Checkout/Sessions'), diff --git a/test/resources/ApplicationFeeRefunds.spec.js b/test/resources/ApplicationFeeRefunds.spec.js deleted file mode 100644 index 82e36e219b..0000000000 --- a/test/resources/ApplicationFeeRefunds.spec.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const APPFEE_TEST_ID = 'appFeeIdTest999'; -const REFUND_TEST_ID = 'refundIdTest999'; - -describe('ApplicationFeeRefund Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - stripe.applicationFeeRefunds.retrieve(APPFEE_TEST_ID, REFUND_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - stripe.applicationFeeRefunds.update(APPFEE_TEST_ID, REFUND_TEST_ID, { - metadata: {key: 'value'}, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, - data: {metadata: {key: 'value'}}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - stripe.applicationFeeRefunds.list(APPFEE_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds`, - data: {}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/LoginLinks.spec.js b/test/resources/LoginLinks.spec.js deleted file mode 100644 index af54de161d..0000000000 --- a/test/resources/LoginLinks.spec.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const ACCOUNT_ID = 'acct_EXPRESS'; - -describe('LoginLink Resource', () => { - describe('create', () => { - it('Sends the correct request', () => { - stripe.loginLinks.create(ACCOUNT_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/accounts/${ACCOUNT_ID}/login_links`, - headers: {}, - data: {}, - }); - }); - }); -}); diff --git a/test/resources/Persons.spec.js b/test/resources/Persons.spec.js deleted file mode 100644 index 0936e4cc6c..0000000000 --- a/test/resources/Persons.spec.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const ACCOUNT_TEST_ID = 'acct_123'; -const PERSON_TEST_ID = 'person_123'; - -describe('Person Resource', () => { - describe('create', () => { - it('Sends the correct request', () => { - stripe.persons.create(ACCOUNT_TEST_ID, { - first_name: 'John', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, - data: {first_name: 'John'}, - headers: {}, - }); - }); - }); - - describe('delete', () => { - it('Sends the correct request', () => { - stripe.persons.del(ACCOUNT_TEST_ID, PERSON_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - stripe.persons.list(ACCOUNT_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, - data: {}, - headers: {}, - }); - }); - }); - - describe('retrieve', () => { - it('Sends the correct request', () => { - stripe.persons.retrieve(ACCOUNT_TEST_ID, PERSON_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - stripe.persons.update(ACCOUNT_TEST_ID, PERSON_TEST_ID, { - first_name: 'John', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, - data: {first_name: 'John'}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/SubscriptionScheduleRevision.spec.js b/test/resources/SubscriptionScheduleRevision.spec.js deleted file mode 100644 index ba17bb95ad..0000000000 --- a/test/resources/SubscriptionScheduleRevision.spec.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const SCHEDULE_TEST_ID = 'sub_sched_123'; -const REVISION_TEST_ID = 'sub_sched_rev_123'; - -describe('SubscriptionScheduleRevision Resource', () => { - describe('list', () => { - it('Sends the correct request', () => { - stripe.subscriptionScheduleRevisions.list(SCHEDULE_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions`, - data: {}, - headers: {}, - }); - }); - }); - - describe('retrieve', () => { - it('Sends the correct request', () => { - stripe.subscriptionScheduleRevisions.retrieve( - SCHEDULE_TEST_ID, - REVISION_TEST_ID - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions/${REVISION_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/TaxIds.spec.js b/test/resources/TaxIds.spec.js deleted file mode 100644 index 6062de4c70..0000000000 --- a/test/resources/TaxIds.spec.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; - -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const CUSTOMER_TEST_ID = 'cus_123'; -const TAX_ID_TEST_ID = 'txi_123'; - -describe('TaxId Resource', () => { - describe('create', () => { - it('Sends the correct request', () => { - const data = { - type: 'eu_vat', - value: '11111', - }; - stripe.taxIds.create(CUSTOMER_TEST_ID, data); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, - data, - headers: {}, - }); - }); - }); - - describe('delete', () => { - it('Sends the correct request', () => { - stripe.taxIds.del(CUSTOMER_TEST_ID, TAX_ID_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - stripe.taxIds.list(CUSTOMER_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, - data: {}, - headers: {}, - }); - }); - }); - - describe('retrieve', () => { - it('Sends the correct request', () => { - stripe.taxIds.retrieve(CUSTOMER_TEST_ID, TAX_ID_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/TransferReversals.spec.js b/test/resources/TransferReversals.spec.js deleted file mode 100644 index 8c8dbeffd7..0000000000 --- a/test/resources/TransferReversals.spec.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; - -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const TRANSFER_TEST_ID = 'transferIdTest999'; -const REVERSAL_TEST_ID = 'reversalIdTest999'; - -describe('TransferReversal Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - stripe.transferReversals.retrieve(TRANSFER_TEST_ID, REVERSAL_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('create', () => { - it('Sends the correct request', () => { - stripe.transferReversals.create(TRANSFER_TEST_ID, { - amount: 100, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, - data: {amount: 100}, - headers: {}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - stripe.transferReversals.update(TRANSFER_TEST_ID, REVERSAL_TEST_ID, { - metadata: {key: 'value'}, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, - data: {metadata: {key: 'value'}}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - stripe.transferReversals.list(TRANSFER_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, - data: {}, - headers: {}, - }); - }); - }); -});