From 818a0eca759cea0d1374023b03a4e4ce58f5288d Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Wed, 8 May 2019 15:44:37 -0700 Subject: [PATCH] Remove legacy parameter support in invoices.retrieveUpcoming() --- lib/resources/Invoices.js | 66 ++++-------------- test/resources/Invoices.spec.js | 116 ++++++++------------------------ 2 files changed, 40 insertions(+), 142 deletions(-) diff --git a/lib/resources/Invoices.js b/lib/resources/Invoices.js index 39f1dea8f3..6d660ee173 100644 --- a/lib/resources/Invoices.js +++ b/lib/resources/Invoices.js @@ -2,7 +2,6 @@ const StripeResource = require('../StripeResource'); const stripeMethod = StripeResource.method; -const utils = require('../utils'); module.exports = StripeResource.extend({ path: 'invoices', @@ -14,6 +13,17 @@ module.exports = StripeResource.extend({ urlParams: ['id'], }), + listLines: stripeMethod({ + method: 'GET', + path: '{id}/lines', + urlParams: ['id'], + }), + + listLinesUpcoming: stripeMethod({ + method: 'GET', + path: 'upcoming/lines', + }), + markUncollectible: stripeMethod({ method: 'POST', path: '{id}/mark_uncollectible', @@ -26,61 +36,9 @@ module.exports = StripeResource.extend({ urlParams: ['id'], }), - retrieveLines: stripeMethod({ - method: 'GET', - path: '{id}/lines', - urlParams: ['id'], - }), - retrieveUpcoming: stripeMethod({ method: 'GET', - path(urlData) { - let url = 'upcoming?'; - let hasParam = false; - - // If you pass just a hash with the relevant parameters, including customer id inside. - if ( - urlData.invoiceOptionsOrCustomerId && - typeof urlData.invoiceOptionsOrCustomerId === 'object' - ) { - return ( - url + utils.stringifyRequestData(urlData.invoiceOptionsOrCustomerId) - ); - } - - // Legacy implementation where the first parameter is a customer id as a string - if ( - urlData.invoiceOptionsOrCustomerId && - typeof urlData.invoiceOptionsOrCustomerId === 'string' - ) { - url = `${url}customer=${urlData.invoiceOptionsOrCustomerId}`; - hasParam = true; - } - - // Legacy support where second argument is the subscription id - if ( - urlData.invoiceOptionsOrSubscriptionId && - typeof urlData.invoiceOptionsOrSubscriptionId === 'string' - ) { - return `${url + (hasParam ? '&' : '')}subscription=${ - urlData.invoiceOptionsOrSubscriptionId - }`; - } else if ( - urlData.invoiceOptionsOrSubscriptionId && - typeof urlData.invoiceOptionsOrSubscriptionId === 'object' - ) { - return ( - url + - (hasParam ? '&' : '') + - utils.stringifyRequestData(urlData.invoiceOptionsOrSubscriptionId) - ); - } - return url; - }, - urlParams: [ - 'optional!invoiceOptionsOrCustomerId', - 'optional!invoiceOptionsOrSubscriptionId', - ], + path: 'upcoming', }), sendInvoice: stripeMethod({ diff --git a/test/resources/Invoices.spec.js b/test/resources/Invoices.spec.js index b6598d8c38..43bf553780 100644 --- a/test/resources/Invoices.spec.js +++ b/test/resources/Invoices.spec.js @@ -64,9 +64,9 @@ describe('Invoices Resource', () => { }); }); - describe('retrieveLines', () => { + describe('listLines', () => { it('Sends the correct request', () => { - stripe.invoices.retrieveLines('in_123'); + stripe.invoices.listLines('in_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: '/v1/invoices/in_123/lines', @@ -77,101 +77,41 @@ describe('Invoices Resource', () => { }); describe('retrieveUpcoming', () => { - describe('With just a customer ID', () => { - it('Sends the correct request', () => { - stripe.invoices.retrieveUpcoming('cus_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/invoices/upcoming?customer=cus_123', - headers: {}, - data: {}, - }); - }); - }); - - describe('With a subscription ID in addition to a customer ID', () => { - it('Sends the correct request', () => { - stripe.invoices.retrieveUpcoming('cus_123', 'sub_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/invoices/upcoming?customer=cus_123&subscription=sub_123', - headers: {}, - data: {}, - }); - }); - }); - - describe('With an options object that includes `subscription_items`', () => { - it('Sends the correct request', () => { - stripe.invoices.retrieveUpcoming('cus_123', { - subscription_items: [{plan: 'potato'}, {plan: 'rutabaga'}], - }); - - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: - '/v1/invoices/upcoming?customer=cus_123&' + - 'subscription_items[0][plan]=potato&subscription_items[1][plan]=rutabaga', - headers: {}, - data: {}, - }); + it('Sends the correct request', () => { + stripe.invoices.retrieveUpcoming({ + customer: 'cus_abc', + subscription_items: [{plan: 'potato'}, {plan: 'rutabaga'}], }); - }); - describe('Without a customer id but options', () => { - it('Sends the correct request', () => { - stripe.invoices.retrieveUpcoming({ + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: '/v1/invoices/upcoming', + headers: {}, + data: { customer: 'cus_abc', subscription_items: [{plan: 'potato'}, {plan: 'rutabaga'}], - }); - - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: - '/v1/invoices/upcoming?customer=cus_abc&' + - 'subscription_items[0][plan]=potato&subscription_items[1][plan]=rutabaga', - headers: {}, - data: {}, - }); + }, }); }); + }); - describe('With an options object that includes `subscription_items` in addition to a subscription ID', () => { - it('Sends the correct request', () => { - stripe.invoices.retrieveUpcoming('cus_123', 'sub_123', { - subscription_items: [ - {plan: 'potato'}, - {plan: 'rutabaga'}, - {id: 'SOME_ID', deleted: true}, - ], - subscription_prorate: true, - }); - - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/invoices/upcoming?customer=cus_123&subscription=sub_123', - headers: {}, - data: { - subscription_items: [ - {plan: 'potato'}, - {plan: 'rutabaga'}, - {id: 'SOME_ID', deleted: true}, - ], - subscription_prorate: true, - }, - }); + describe('listLinesUpcoming', () => { + it('Sends the correct request', () => { + stripe.invoices.listLinesUpcoming({ + customer: 'cus_abc', + subscription_items: [{plan: 'potato'}, {plan: 'rutabaga'}], + limit: 5, }); - }); - describe('With a options object in addition to a customer ID', () => { - it('Sends the correct request', () => { - stripe.invoices.retrieveUpcoming('cus_123', {plan: 'planId123'}); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/invoices/upcoming?customer=cus_123&plan=planId123', - headers: {}, - data: {}, - }); + expect(stripe.LAST_REQUEST).to.deep.equal({ + method: 'GET', + url: '/v1/invoices/upcoming/lines', + headers: {}, + data: { + customer: 'cus_abc', + subscription_items: [{plan: 'potato'}, {plan: 'rutabaga'}], + limit: 5, + }, }); }); });