Skip to content

Commit

Permalink
Explicitly define basic methods. (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcr-stripe authored Jul 28, 2021
1 parent 604d2ec commit 93ce450
Show file tree
Hide file tree
Showing 65 changed files with 1,091 additions and 65 deletions.
2 changes: 2 additions & 0 deletions lib/StripeMethod.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const stripeMethod = require('./StripeMethod');

// DEPRECATED: These were kept for backwards compatibility in case users were
// using this, but basic methods are now explicitly defined on a resource.
module.exports = {
create: stripeMethod({
method: 'POST',
Expand Down
2 changes: 2 additions & 0 deletions lib/StripeResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function StripeResource(stripe, deprecatedUrlData) {
this.resourcePath = this.path;
this.path = utils.makeURLInterpolator(this.path);

// DEPRECATED: This was kept for backwards compatibility in case users were
// using this, but basic methods are now explicitly defined on a resource.
if (this.includeBasic) {
this.includeBasic.forEach(function(methodName) {
this[methodName] = StripeResource.BASIC_METHODS[methodName];
Expand Down
6 changes: 5 additions & 1 deletion lib/resources/AccountLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
'use strict';

const StripeResource = require('../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'account_links',

includeBasic: ['create'],
create: stripeMethod({
method: 'POST',
path: '',
}),
});
22 changes: 21 additions & 1 deletion lib/resources/ApplePayDomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@
'use strict';

const StripeResource = require('../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'apple_pay/domains',

includeBasic: ['create', 'retrieve', 'list', 'del'],
create: stripeMethod({
method: 'POST',
path: '',
}),

retrieve: stripeMethod({
method: 'GET',
path: '/{domain}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),

del: stripeMethod({
method: 'DELETE',
path: '/{domain}',
}),
});
11 changes: 10 additions & 1 deletion lib/resources/ApplicationFees.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ const stripeMethod = StripeResource.method;
module.exports = StripeResource.extend({
path: 'application_fees',

includeBasic: ['retrieve', 'list'],
retrieve: stripeMethod({
method: 'GET',
path: '/{id}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),

createRefund: stripeMethod({
method: 'POST',
Expand Down
12 changes: 11 additions & 1 deletion lib/resources/BalanceTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
'use strict';

const StripeResource = require('../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'balance_transactions',

includeBasic: ['retrieve', 'list'],
retrieve: stripeMethod({
method: 'GET',
path: '/{id}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),
});
22 changes: 21 additions & 1 deletion lib/resources/BillingPortal/Configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@
'use strict';

const StripeResource = require('../../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'billing_portal/configurations',

includeBasic: ['create', 'retrieve', 'update', 'list'],
create: stripeMethod({
method: 'POST',
path: '',
}),

retrieve: stripeMethod({
method: 'GET',
path: '/{configuration}',
}),

update: stripeMethod({
method: 'POST',
path: '/{configuration}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),
});
6 changes: 5 additions & 1 deletion lib/resources/BillingPortal/Sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
'use strict';

const StripeResource = require('../../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'billing_portal/sessions',

includeBasic: ['create'],
create: stripeMethod({
method: 'POST',
path: '',
}),
});
21 changes: 20 additions & 1 deletion lib/resources/Charges.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ const stripeMethod = StripeResource.method;
module.exports = StripeResource.extend({
path: 'charges',

includeBasic: ['create', 'retrieve', 'update', 'list'],
create: stripeMethod({
method: 'POST',
path: '',
}),

retrieve: stripeMethod({
method: 'GET',
path: '/{charge}',
}),

update: stripeMethod({
method: 'POST',
path: '/{charge}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),

capture: stripeMethod({
method: 'POST',
Expand Down
16 changes: 15 additions & 1 deletion lib/resources/Checkout/Sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ const stripeMethod = StripeResource.method;
module.exports = StripeResource.extend({
path: 'checkout/sessions',

includeBasic: ['create', 'retrieve', 'list'],
create: stripeMethod({
method: 'POST',
path: '',
}),

retrieve: stripeMethod({
method: 'GET',
path: '/{session}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),

listLineItems: stripeMethod({
method: 'GET',
Expand Down
12 changes: 11 additions & 1 deletion lib/resources/CountrySpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
'use strict';

const StripeResource = require('../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'country_specs',

includeBasic: ['retrieve', 'list'],
retrieve: stripeMethod({
method: 'GET',
path: '/{country}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),
});
27 changes: 26 additions & 1 deletion lib/resources/Coupons.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,34 @@
'use strict';

const StripeResource = require('../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'coupons',

includeBasic: ['create', 'retrieve', 'update', 'list', 'del'],
create: stripeMethod({
method: 'POST',
path: '',
}),

retrieve: stripeMethod({
method: 'GET',
path: '/{coupon}',
}),

update: stripeMethod({
method: 'POST',
path: '/{coupon}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),

del: stripeMethod({
method: 'DELETE',
path: '/{coupon}',
}),
});
21 changes: 20 additions & 1 deletion lib/resources/CreditNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ const stripeMethod = StripeResource.method;
module.exports = StripeResource.extend({
path: 'credit_notes',

includeBasic: ['create', 'retrieve', 'update', 'list'],
create: stripeMethod({
method: 'POST',
path: '',
}),

retrieve: stripeMethod({
method: 'GET',
path: '/{id}',
}),

update: stripeMethod({
method: 'POST',
path: '/{id}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),

preview: stripeMethod({
method: 'GET',
Expand Down
26 changes: 25 additions & 1 deletion lib/resources/Customers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,31 @@ const stripeMethod = StripeResource.method;
module.exports = StripeResource.extend({
path: 'customers',

includeBasic: ['create', 'retrieve', 'update', 'list', 'del'],
create: stripeMethod({
method: 'POST',
path: '',
}),

retrieve: stripeMethod({
method: 'GET',
path: '/{customer}',
}),

update: stripeMethod({
method: 'POST',
path: '/{customer}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),

del: stripeMethod({
method: 'DELETE',
path: '/{customer}',
}),

deleteDiscount: stripeMethod({
method: 'DELETE',
Expand Down
16 changes: 15 additions & 1 deletion lib/resources/Disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ const stripeMethod = StripeResource.method;
module.exports = StripeResource.extend({
path: 'disputes',

includeBasic: ['retrieve', 'update', 'list'],
retrieve: stripeMethod({
method: 'GET',
path: '/{dispute}',
}),

update: stripeMethod({
method: 'POST',
path: '/{dispute}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),

close: stripeMethod({
method: 'POST',
Expand Down
7 changes: 5 additions & 2 deletions lib/resources/EphemeralKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const stripeMethod = StripeResource.method;
module.exports = StripeResource.extend({
path: 'ephemeral_keys',

includeBasic: ['del'],

create: stripeMethod({
method: 'POST',
path: '',
Expand All @@ -21,4 +19,9 @@ module.exports = StripeResource.extend({
}
},
}),

del: stripeMethod({
method: 'DELETE',
path: '/{key}',
}),
});
12 changes: 11 additions & 1 deletion lib/resources/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
'use strict';

const StripeResource = require('../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'events',

includeBasic: ['retrieve', 'list'],
retrieve: stripeMethod({
method: 'GET',
path: '/{id}',
}),

list: stripeMethod({
method: 'GET',
path: '',
methodType: 'list',
}),
});
Loading

0 comments on commit 93ce450

Please sign in to comment.