Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the SetupIntent resource and APIs #652

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 SETUP_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(SETUP_INTENT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: `/v1/setup_intents/${SETUP_INTENT_TEST_ID}`,
headers: {},
data: {},
});
});
});

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

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

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