From bb96be753f2c9027ffdd35ef5108b232dfeef25d Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Wed, 27 Jun 2018 16:07:50 -0400 Subject: [PATCH] Add support for the PaymentIntent resource This feature is currently gated so the tests are stubbed for now. --- lib/resources/PaymentIntents.js | 28 ++++++++ lib/stripe.js | 1 + test/resources/PaymentIntents.spec.js | 99 +++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 lib/resources/PaymentIntents.js create mode 100644 test/resources/PaymentIntents.spec.js diff --git a/lib/resources/PaymentIntents.js b/lib/resources/PaymentIntents.js new file mode 100644 index 0000000000..fae0950b27 --- /dev/null +++ b/lib/resources/PaymentIntents.js @@ -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'], + }), +}); + diff --git a/lib/stripe.js b/lib/stripe.js index 9e5b564d67..461ac23a08 100644 --- a/lib/stripe.js +++ b/lib/stripe.js @@ -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'), diff --git a/test/resources/PaymentIntents.spec.js b/test/resources/PaymentIntents.spec.js new file mode 100644 index 0000000000..b8a88fb38c --- /dev/null +++ b/test/resources/PaymentIntents.spec.js @@ -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: {}, + }); + }); + }); +});