Skip to content

Commit

Permalink
Add support for the PaymentMethod resource
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Feb 25, 2019
1 parent f5a2f49 commit 30dd739
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/resources/PaymentMethods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

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

module.exports = StripeResource.extend({

path: 'payment_methods',
includeBasic: ['create', 'list', 'retrieve', 'update'],

attach: stripeMethod({
method: 'POST',
path: '{paymentMethodId}/attach',
urlParams: ['paymentMethodId'],
}),

detach: stripeMethod({
method: 'POST',
path: '{paymentMethodId}/detach',
urlParams: ['paymentMethodId'],
}),
});
1 change: 1 addition & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var resources = {
OrderReturns: require('./resources/OrderReturns'),
Orders: require('./resources/Orders'),
PaymentIntents: require('./resources/PaymentIntents'),
PaymentMethods: require('./resources/PaymentMethods'),
Payouts: require('./resources/Payouts'),
Plans: require('./resources/Plans'),
Products: require('./resources/Products'),
Expand Down
87 changes: 87 additions & 0 deletions test/resources/PaymentMethods.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict';

var stripe = require('../../testUtils').getSpyableStripe();
var expect = require('chai').expect;

describe('PaymentMethods Resource', function() {
describe('retrieve', function() {
it('Sends the correct request', function() {
stripe.paymentMethods.retrieve('pm_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/payment_methods/pm_123',
headers: {},
data: {},
});
});
});

describe('create', function() {
it('Sends the correct request', function() {
var data = {
type: 'card',
card: {
token: 'tok_123',
},
};
stripe.paymentMethods.create(data);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_methods',
headers: {},
data: data,
});
});
});

describe('list', function() {
it('Sends the correct request', function() {
stripe.paymentMethods.list({customer: 'cus_123'});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/payment_methods',
headers: {},
data: {customer: 'cus_123'},
});
});
});

describe('update', function() {
it('Sends the correct request', function() {
var data = {
metadata: {key: 'value'},
};
stripe.paymentMethods.update('pm_123', data);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_methods/pm_123',
headers: {},
data: data,
});
});
});

describe('attach', function() {
it('Sends the correct request', function() {
stripe.paymentMethods.attach('pm_123', {customer: 'cus_123'});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_methods/pm_123/attach',
headers: {},
data: {customer: 'cus_123'}
});
});
});

describe('detach', function() {
it('Sends the correct request', function() {
stripe.paymentMethods.detach('pm_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_methods/pm_123/detach',
headers: {},
data: {}
});
});
});
});

0 comments on commit 30dd739

Please sign in to comment.