Skip to content

Commit

Permalink
Merge pull request #473 from stripe/remi-add-payment-intent
Browse files Browse the repository at this point in the history
Add support for the PaymentIntent resource
  • Loading branch information
ob-stripe authored Jun 28, 2018
2 parents 88055df + bb96be7 commit 34113d2
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/resources/PaymentIntents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

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

module.exports = StripeResource.extend({
path: 'payment_intents',
includeBasic: ['create', 'list', 'retrieve', 'update'],

cancel: stripeMethod({
method: 'POST',
path: '{paymentIntentId}/cancel',
urlParams: ['paymentIntentId'],
}),

capture: stripeMethod({
method: 'POST',
path: '{paymentIntentId}/capture',
urlParams: ['paymentIntentId'],
}),

confirm: stripeMethod({
method: 'POST',
path: '{paymentIntentId}/confirm',
urlParams: ['paymentIntentId'],
}),
});

1 change: 1 addition & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var resources = {
InvoiceItems: require('./resources/InvoiceItems'),
IssuerFraudRecords: require('./resources/IssuerFraudRecords'),
LoginLinks: require('./resources/LoginLinks'),
PaymentIntents: require('./resources/PaymentIntents'),
Payouts: require('./resources/Payouts'),
Plans: require('./resources/Plans'),
RecipientCards: require('./resources/RecipientCards'),
Expand Down
99 changes: 99 additions & 0 deletions test/resources/PaymentIntents.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use strict';

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

var PAYMENT_INTENT_TEST_ID = 'pi_123';

describe('Payment Intents Resource', function() {
describe('create', function() {
it('Sends the correct request', function() {
var params = {
allowed_source_types: ['card'],
amount: 200,
currency: 'usd',
};
stripe.paymentIntents.create(params);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_intents',
headers: {},
data: params,
});
});
});

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

describe('retrieve', function() {
it('Sends the correct request', function() {
stripe.paymentIntents.retrieve(PAYMENT_INTENT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID,
headers: {},
data: {},
});
});
});

describe('update', function() {
it('Sends the correct request', function() {
stripe.paymentIntents.update(PAYMENT_INTENT_TEST_ID, {
metadata: {key: 'value'},
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID,
headers: {},
data: {metadata: {key: 'value'}},
});
});
});

describe('cancel', function() {
it('Sends the correct request', function() {
stripe.paymentIntents.cancel(PAYMENT_INTENT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID + '/cancel',
headers: {},
data: {},
});
});
});

describe('capture', function() {
it('Sends the correct request', function() {
stripe.paymentIntents.capture(PAYMENT_INTENT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID + '/capture',
headers: {},
data: {},
});
});
});

describe('confirm', function() {
it('Sends the correct request', function() {
stripe.paymentIntents.confirm(PAYMENT_INTENT_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID + '/confirm',
headers: {},
data: {},
});
});
});
});

0 comments on commit 34113d2

Please sign in to comment.