Skip to content

Commit

Permalink
Add support for the SetupIntent resource and APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Jun 27, 2019
1 parent de7b272 commit 31b7130
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
Recipients: require('./resources/Recipients'),
Refunds: require('./resources/Refunds'),
Reviews: require('./resources/Reviews'),
SetupIntents: require('./resources/SetupIntents'),
Skus: require('./resources/SKUs'),
Sources: require('./resources/Sources'),
Subscriptions: require('./resources/Subscriptions'),
Expand Down
20 changes: 20 additions & 0 deletions lib/resources/SetupIntents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

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

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

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

cancel: stripeMethod({
method: 'POST',
path: '/{intent}/cancel',
}),

confirm: stripeMethod({
method: 'POST',
path: '/{intent}/confirm',
}),
});
85 changes: 85 additions & 0 deletions test/resources/SetupIntents.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict';

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

const PAYMENT_INTENT_TEST_ID = 'seti_123';

describe('Setup Intents Resource', () => {
describe('create', () => {
it('Sends the correct request', () => {
const params = {
payment_method_types: ['card'],
};
stripe.setupIntents.create(params);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/setup_intents',
headers: {},
data: params,
});
});
});

describe('list', () => {
it('Sends the correct request', () => {
stripe.setupIntents.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/setup_intents',
headers: {},
data: {},
});
});
});

describe('retrieve', () => {
it('Sends the correct request', () => {
stripe.setupIntents.retrieve(PAYMENT_INTENT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: `/v1/setup_intents/${PAYMENT_INTENT_TEST_ID}`,
headers: {},
data: {},
});
});
});

describe('update', () => {
it('Sends the correct request', () => {
stripe.setupIntents.update(PAYMENT_INTENT_TEST_ID, {
metadata: {key: 'value'},
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: `/v1/setup_intents/${PAYMENT_INTENT_TEST_ID}`,
headers: {},
data: {metadata: {key: 'value'}},
});
});
});

describe('cancel', () => {
it('Sends the correct request', () => {
stripe.setupIntents.cancel(PAYMENT_INTENT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: `/v1/setup_intents/${PAYMENT_INTENT_TEST_ID}/cancel`,
headers: {},
data: {},
});
});
});

describe('confirm', () => {
it('Sends the correct request', () => {
stripe.setupIntents.confirm(PAYMENT_INTENT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: `/v1/setup_intents/${PAYMENT_INTENT_TEST_ID}/confirm`,
headers: {},
data: {},
});
});
});
});

0 comments on commit 31b7130

Please sign in to comment.