From 51419c905468f4504f79bbd28a17e076077dd1bf Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Wed, 8 May 2019 00:35:36 -0700 Subject: [PATCH] Remove deprecated methods --- lib/StripeMethod.basic.js | 95 ---- lib/resources/ApplicationFees.js | 6 - lib/resources/Balance.js | 12 - lib/resources/BitcoinReceivers.js | 2 +- lib/resources/ChargeRefunds.js | 20 - lib/resources/Charges.js | 64 +-- lib/resources/CustomerCards.js | 19 - lib/resources/CustomerSubscriptions.js | 30 -- lib/resources/Customers.js | 123 +---- lib/resources/Disputes.js | 2 +- lib/resources/FileLinks.js | 9 +- lib/resources/InvoiceItems.js | 10 +- lib/resources/Issuing/Authorizations.js | 2 +- lib/resources/Issuing/Cardholders.js | 9 +- lib/resources/Issuing/Cards.js | 9 +- lib/resources/Issuing/Disputes.js | 9 +- lib/resources/Issuing/Transactions.js | 2 +- lib/resources/Payouts.js | 16 +- lib/resources/RecipientCards.js | 19 - lib/resources/Recipients.js | 14 +- lib/resources/Sources.js | 2 +- lib/resources/SubscriptionSchedules.js | 9 +- lib/resources/Topups.js | 9 +- lib/resources/Transfers.js | 28 +- lib/stripe.js | 7 - package.json | 2 +- test/flows.spec.js | 155 ++---- test/resources/ApplicationFees.spec.js | 14 - test/resources/Balance.spec.js | 49 -- test/resources/ChargeRefunds.spec.js | 70 --- test/resources/Charges.spec.js | 123 ----- test/resources/CustomerCards.spec.js | 82 ---- test/resources/CustomerSubscriptions.spec.js | 100 ---- test/resources/Customers.spec.js | 482 ------------------- test/resources/FileUploads.spec.js | 138 ------ test/resources/Payouts.spec.js | 12 - test/resources/RecipientCards.spec.js | 82 ---- test/resources/Transfers.spec.js | 36 -- test/stripe.spec.js | 2 +- 39 files changed, 58 insertions(+), 1816 deletions(-) delete mode 100644 lib/resources/ChargeRefunds.js delete mode 100644 lib/resources/CustomerCards.js delete mode 100644 lib/resources/CustomerSubscriptions.js delete mode 100644 lib/resources/RecipientCards.js delete mode 100644 test/resources/ChargeRefunds.spec.js delete mode 100644 test/resources/CustomerCards.spec.js delete mode 100644 test/resources/CustomerSubscriptions.spec.js delete mode 100644 test/resources/FileUploads.spec.js delete mode 100644 test/resources/RecipientCards.spec.js diff --git a/lib/StripeMethod.basic.js b/lib/StripeMethod.basic.js index 1db6b8efbf..efbd6a48a0 100644 --- a/lib/StripeMethod.basic.js +++ b/lib/StripeMethod.basic.js @@ -1,8 +1,6 @@ 'use strict'; -const isPlainObject = require('lodash.isplainobject'); const stripeMethod = require('./StripeMethod'); -const utils = require('./utils'); module.exports = { create: stripeMethod({ @@ -32,97 +30,4 @@ module.exports = { path: '{id}', urlParams: ['id'], }), - - setMetadata(id, key, value, auth, cb) { - const self = this; - const data = key; - const isObject = isPlainObject(key); - // We assume null for an empty object - const isNull = data === null || (isObject && !Object.keys(data).length); - - // Allow optional passing of auth & cb: - if ((isNull || isObject) && typeof value == 'string') { - auth = value; - } else if (typeof auth != 'string') { - if (!cb && typeof auth == 'function') { - cb = auth; - } - auth = null; - } - - const urlData = this.createUrlData(); - const path = this.createFullPath(`/${id}`, urlData); - - return utils.callbackifyPromiseWithTimeout( - new Promise((resolve, reject) => { - if (isNull) { - // Reset metadata: - sendMetadata(null, auth); - } else if (!isObject) { - // Set individual metadata property: - const metadata = {}; - metadata[key] = value; - sendMetadata(metadata, auth); - } else { - // Set entire metadata object after resetting it: - this._request( - 'POST', - null, - path, - {metadata: null}, - auth, - {}, - (err, response) => { - if (err) { - return reject(err); - } - sendMetadata(data, auth); - } - ); - } - - function sendMetadata(metadata, auth) { - self._request( - 'POST', - null, - path, - {metadata}, - auth, - {}, - (err, response) => { - if (err) { - reject(err); - } else { - resolve(response.metadata); - } - } - ); - } - }), - cb - ); - }, - - getMetadata(id, auth, cb) { - if (!cb && typeof auth == 'function') { - cb = auth; - auth = null; - } - - const urlData = this.createUrlData(); - const path = this.createFullPath(`/${id}`, urlData); - - return utils.callbackifyPromiseWithTimeout( - new Promise((resolve, reject) => { - this._request('GET', null, path, {}, auth, {}, (err, response) => { - if (err) { - reject(err); - } else { - resolve(response.metadata); - } - }); - }), - cb - ); - }, }; diff --git a/lib/resources/ApplicationFees.js b/lib/resources/ApplicationFees.js index d3261bf216..3c676057f3 100644 --- a/lib/resources/ApplicationFees.js +++ b/lib/resources/ApplicationFees.js @@ -8,12 +8,6 @@ module.exports = StripeResource.extend({ includeBasic: ['list', 'retrieve'], - refund: stripeMethod({ - method: 'POST', - path: '/{id}/refund', - urlParams: ['id'], - }), - createRefund: stripeMethod({ method: 'POST', path: '/{feeId}/refunds', diff --git a/lib/resources/Balance.js b/lib/resources/Balance.js index 1a351806dd..cdb30b26a5 100644 --- a/lib/resources/Balance.js +++ b/lib/resources/Balance.js @@ -9,16 +9,4 @@ module.exports = StripeResource.extend({ retrieve: stripeMethod({ method: 'GET', }), - - listTransactions: stripeMethod({ - method: 'GET', - path: 'history', - methodType: 'list', - }), - - retrieveTransaction: stripeMethod({ - method: 'GET', - path: 'history/{transactionId}', - urlParams: ['transactionId'], - }), }); diff --git a/lib/resources/BitcoinReceivers.js b/lib/resources/BitcoinReceivers.js index 2642e1e9b3..7e4fe033c6 100644 --- a/lib/resources/BitcoinReceivers.js +++ b/lib/resources/BitcoinReceivers.js @@ -6,7 +6,7 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'bitcoin/receivers', - includeBasic: ['list', 'retrieve', 'getMetadata'], + includeBasic: ['list', 'retrieve'], listTransactions: stripeMethod({ method: 'GET', diff --git a/lib/resources/ChargeRefunds.js b/lib/resources/ChargeRefunds.js deleted file mode 100644 index 693a79b0db..0000000000 --- a/lib/resources/ChargeRefunds.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -/** - * ChargeRefunds is a unique resource in that, upon instantiation, - * requires a chargeId, and therefore each of its methods only - * require the refundId argument. - * - * This streamlines the API specifically for the case of accessing refunds - * on a returned charge object. - * - * E.g. chargeObject.refunds.retrieve(refundId) - * (As opposed to the also-supported stripe.charges.retrieveRefund(chargeId, - * refundId)) - */ -module.exports = StripeResource.extend({ - path: 'charges/{chargeId}/refunds', - includeBasic: ['create', 'list', 'retrieve', 'update'], -}); diff --git a/lib/resources/Charges.js b/lib/resources/Charges.js index 4702bc5bf5..c29a54e1fd 100644 --- a/lib/resources/Charges.js +++ b/lib/resources/Charges.js @@ -6,73 +6,11 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'charges', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'list', 'retrieve', 'update'], capture: stripeMethod({ method: 'POST', path: '/{id}/capture', urlParams: ['id'], }), - - refund: stripeMethod({ - method: 'POST', - path: '/{id}/refund', - urlParams: ['id'], - }), - - updateDispute: stripeMethod({ - method: 'POST', - path: '/{id}/dispute', - urlParams: ['id'], - }), - - closeDispute: stripeMethod({ - method: 'POST', - path: '/{id}/dispute/close', - urlParams: ['id'], - }), - - /** - * Charge: Refund methods - * (Deprecated) - */ - createRefund: stripeMethod({ - method: 'POST', - path: '/{id}/refunds', - urlParams: ['id'], - }), - - listRefunds: stripeMethod({ - method: 'GET', - path: '/{id}/refunds', - urlParams: ['id'], - methodType: 'list', - }), - - retrieveRefund: stripeMethod({ - method: 'GET', - path: '/{chargeId}/refunds/{refundId}', - urlParams: ['chargeId', 'refundId'], - }), - - updateRefund: stripeMethod({ - method: 'POST', - path: '/{chargeId}/refunds/{refundId}', - urlParams: ['chargeId', 'refundId'], - }), - - markAsSafe(chargeId) { - return this.update(chargeId, {fraud_details: {user_report: 'safe'}}); - }, - - markAsFraudulent(chargeId) { - return this.update(chargeId, {fraud_details: {user_report: 'fraudulent'}}); - }, }); diff --git a/lib/resources/CustomerCards.js b/lib/resources/CustomerCards.js deleted file mode 100644 index 194d85bec0..0000000000 --- a/lib/resources/CustomerCards.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -/** - * CustomerCard is a unique resource in that, upon instantiation, - * requires a customerId, and therefore each of its methods only - * require the cardId argument. - * - * This streamlines the API specifically for the case of accessing cards - * on a returned customer object. - * - * E.g. customerObject.cards.retrieve(cardId) - * (As opposed to the also-supported stripe.customers.retrieveCard(custId, cardId)) - */ -module.exports = StripeResource.extend({ - path: 'customers/{customerId}/cards', - includeBasic: ['create', 'list', 'retrieve', 'update', 'del'], -}); diff --git a/lib/resources/CustomerSubscriptions.js b/lib/resources/CustomerSubscriptions.js deleted file mode 100644 index 6cde760a2f..0000000000 --- a/lib/resources/CustomerSubscriptions.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); -const stripeMethod = StripeResource.method; - -/** - * CustomerSubscription is a unique resource in that, upon instantiation, - * requires a customerId, and therefore each of its methods only - * require the subscriptionId argument. - * - * This streamlines the API specifically for the case of accessing cards - * on a returned customer object. - * - * E.g. customerObject.cards.retrieve(cardId) - * (As opposed to the also-supported stripe.customers.retrieveCard(custId, cardId)) - */ -module.exports = StripeResource.extend({ - path: 'customers/{customerId}/subscriptions', - includeBasic: ['create', 'list', 'retrieve', 'update', 'del'], - - /** - * Customer: Discount methods - */ - - deleteDiscount: stripeMethod({ - method: 'DELETE', - path: '/{subscriptionId}/discount', - urlParams: ['customerId', 'subscriptionId'], - }), -}); diff --git a/lib/resources/Customers.js b/lib/resources/Customers.js index 7cce50e42c..609d9316c3 100644 --- a/lib/resources/Customers.js +++ b/lib/resources/Customers.js @@ -1,119 +1,20 @@ 'use strict'; const StripeResource = require('../StripeResource'); -const utils = require('../utils'); const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'customers', - includeBasic: [ - 'create', - 'del', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'del', 'list', 'retrieve', 'update'], /** - * Customer: Subscription methods + * Customer: Discount methods */ - _legacyUpdateSubscription: stripeMethod({ - method: 'POST', - path: '{id}/subscription', - urlParams: ['id'], - }), - - _newstyleUpdateSubscription: stripeMethod({ - method: 'POST', - path: '/{customerId}/subscriptions/{subscriptionId}', - urlParams: ['customerId', 'subscriptionId'], - }), - - _legacyCancelSubscription: stripeMethod({ - method: 'DELETE', - path: '{id}/subscription', - urlParams: ['id'], - }), - - _newstyleCancelSubscription: stripeMethod({ + deleteDiscount: stripeMethod({ method: 'DELETE', - path: '/{customerId}/subscriptions/{subscriptionId}', - urlParams: ['customerId', 'subscriptionId'], - }), - - createSubscription: stripeMethod({ - method: 'POST', - path: '/{id}/subscriptions', - urlParams: ['id'], - }), - - listSubscriptions: stripeMethod({ - method: 'GET', - path: '/{id}/subscriptions', - urlParams: ['id'], - methodType: 'list', - }), - - retrieveSubscription: stripeMethod({ - method: 'GET', - path: '/{customerId}/subscriptions/{subscriptionId}', - urlParams: ['customerId', 'subscriptionId'], - }), - - updateSubscription(customerId, subscriptionId) { - if (typeof subscriptionId == 'string') { - return this._newstyleUpdateSubscription(...arguments); - } else { - return this._legacyUpdateSubscription(...arguments); - } - }, - - cancelSubscription(customerId, subscriptionId) { - // This is a hack, but it lets us maximize our overloading. - // Precarious assumption: If it's not an auth key it _could_ be a sub id: - if (typeof subscriptionId == 'string' && !utils.isAuthKey(subscriptionId)) { - return this._newstyleCancelSubscription(...arguments); - } else { - return this._legacyCancelSubscription(...arguments); - } - }, - - /** - * Customer: Card methods - */ - - createCard: stripeMethod({ - method: 'POST', - path: '/{customerId}/cards', - urlParams: ['customerId'], - }), - - listCards: stripeMethod({ - method: 'GET', - path: '/{customerId}/cards', + path: '/{customerId}/discount', urlParams: ['customerId'], - methodType: 'list', - }), - - retrieveCard: stripeMethod({ - method: 'GET', - path: '/{customerId}/cards/{cardId}', - urlParams: ['customerId', 'cardId'], - }), - - updateCard: stripeMethod({ - method: 'POST', - path: '/{customerId}/cards/{cardId}', - urlParams: ['customerId', 'cardId'], - }), - - deleteCard: stripeMethod({ - method: 'DELETE', - path: '/{customerId}/cards/{cardId}', - urlParams: ['customerId', 'cardId'], }), /** @@ -157,22 +58,6 @@ module.exports = StripeResource.extend({ urlParams: ['customerId', 'sourceId'], }), - /** - * Customer: Discount methods - */ - - deleteDiscount: stripeMethod({ - method: 'DELETE', - path: '/{customerId}/discount', - urlParams: ['customerId'], - }), - - deleteSubscriptionDiscount: stripeMethod({ - method: 'DELETE', - path: '/{customerId}/subscriptions/{subscriptionId}/discount', - urlParams: ['customerId', 'subscriptionId'], - }), - /** * Customer: TaxId methods */ diff --git a/lib/resources/Disputes.js b/lib/resources/Disputes.js index 83c5526c25..506bb4f196 100644 --- a/lib/resources/Disputes.js +++ b/lib/resources/Disputes.js @@ -6,7 +6,7 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'disputes', - includeBasic: ['list', 'retrieve', 'update', 'setMetadata', 'getMetadata'], + includeBasic: ['list', 'retrieve', 'update'], close: stripeMethod({ method: 'POST', diff --git a/lib/resources/FileLinks.js b/lib/resources/FileLinks.js index 8c264d061a..1fbec9db2d 100644 --- a/lib/resources/FileLinks.js +++ b/lib/resources/FileLinks.js @@ -4,12 +4,5 @@ const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'file_links', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'list', 'retrieve', 'update'], }); diff --git a/lib/resources/InvoiceItems.js b/lib/resources/InvoiceItems.js index c4a2142097..bbd1badef0 100644 --- a/lib/resources/InvoiceItems.js +++ b/lib/resources/InvoiceItems.js @@ -2,13 +2,5 @@ module.exports = require('../StripeResource').extend({ path: 'invoiceitems', - includeBasic: [ - 'create', - 'del', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'del', 'list', 'retrieve', 'update'], }); diff --git a/lib/resources/Issuing/Authorizations.js b/lib/resources/Issuing/Authorizations.js index 85756a6935..af8a3f55f2 100644 --- a/lib/resources/Issuing/Authorizations.js +++ b/lib/resources/Issuing/Authorizations.js @@ -6,7 +6,7 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'issuing/authorizations', - includeBasic: ['list', 'retrieve', 'update', 'setMetadata', 'getMetadata'], + includeBasic: ['list', 'retrieve', 'update'], approve: stripeMethod({ method: 'POST', diff --git a/lib/resources/Issuing/Cardholders.js b/lib/resources/Issuing/Cardholders.js index 58dd2630b9..8a4e4cfa12 100644 --- a/lib/resources/Issuing/Cardholders.js +++ b/lib/resources/Issuing/Cardholders.js @@ -4,12 +4,5 @@ const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'issuing/cardholders', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'list', 'retrieve', 'update'], }); diff --git a/lib/resources/Issuing/Cards.js b/lib/resources/Issuing/Cards.js index f8026ab5fc..9f5e41b876 100644 --- a/lib/resources/Issuing/Cards.js +++ b/lib/resources/Issuing/Cards.js @@ -6,14 +6,7 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'issuing/cards', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'list', 'retrieve', 'update'], retrieveDetails: stripeMethod({ method: 'GET', diff --git a/lib/resources/Issuing/Disputes.js b/lib/resources/Issuing/Disputes.js index a26015a3ca..6286648ac1 100644 --- a/lib/resources/Issuing/Disputes.js +++ b/lib/resources/Issuing/Disputes.js @@ -4,12 +4,5 @@ const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'issuing/disputes', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'list', 'retrieve', 'update'], }); diff --git a/lib/resources/Issuing/Transactions.js b/lib/resources/Issuing/Transactions.js index 789292ff2a..18eb82e87a 100644 --- a/lib/resources/Issuing/Transactions.js +++ b/lib/resources/Issuing/Transactions.js @@ -4,5 +4,5 @@ const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'issuing/transactions', - includeBasic: ['list', 'retrieve', 'update', 'setMetadata', 'getMetadata'], + includeBasic: ['list', 'retrieve', 'update'], }); diff --git a/lib/resources/Payouts.js b/lib/resources/Payouts.js index 8cd32d9c9c..d750fc1887 100644 --- a/lib/resources/Payouts.js +++ b/lib/resources/Payouts.js @@ -6,25 +6,11 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'payouts', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'list', 'retrieve', 'update'], cancel: stripeMethod({ method: 'POST', path: '{id}/cancel', urlParams: ['id'], }), - - listTransactions: stripeMethod({ - method: 'GET', - path: '{id}/transactions', - urlParams: ['id'], - methodType: 'list', - }), }); diff --git a/lib/resources/RecipientCards.js b/lib/resources/RecipientCards.js deleted file mode 100644 index 0dc675bdcc..0000000000 --- a/lib/resources/RecipientCards.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -const StripeResource = require('../StripeResource'); - -/** - * RecipientCard is similar to CustomerCard in that, upon instantiation, it - * requires a recipientId, and therefore each of its methods only - * require the cardId argument. - * - * This streamlines the API specifically for the case of accessing cards - * on a returned recipient object. - * - * E.g. recipientObject.cards.retrieve(cardId) - * (As opposed to the also-supported stripe.recipients.retrieveCard(recipientId, cardId)) - */ -module.exports = StripeResource.extend({ - path: 'recipients/{recipientId}/cards', - includeBasic: ['create', 'list', 'retrieve', 'update', 'del'], -}); diff --git a/lib/resources/Recipients.js b/lib/resources/Recipients.js index e9adaec076..490dd1c669 100644 --- a/lib/resources/Recipients.js +++ b/lib/resources/Recipients.js @@ -5,15 +5,11 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'recipients', - includeBasic: [ - 'create', - 'del', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'del', 'list', 'retrieve', 'update'], + + /** + * Recipient: Card methods + */ createCard: stripeMethod({ method: 'POST', diff --git a/lib/resources/Sources.js b/lib/resources/Sources.js index 78e7a87675..ed213880d7 100644 --- a/lib/resources/Sources.js +++ b/lib/resources/Sources.js @@ -6,7 +6,7 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'sources', - includeBasic: ['create', 'retrieve', 'update', 'setMetadata', 'getMetadata'], + includeBasic: ['create', 'retrieve', 'update'], listSourceTransactions: stripeMethod({ method: 'GET', diff --git a/lib/resources/SubscriptionSchedules.js b/lib/resources/SubscriptionSchedules.js index f135a0ef2a..d9cef43be9 100644 --- a/lib/resources/SubscriptionSchedules.js +++ b/lib/resources/SubscriptionSchedules.js @@ -6,14 +6,7 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'subscription_schedules', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'list', 'retrieve', 'update'], release: stripeMethod({ method: 'POST', diff --git a/lib/resources/Topups.js b/lib/resources/Topups.js index ef57d1ff3f..d3ea5023db 100644 --- a/lib/resources/Topups.js +++ b/lib/resources/Topups.js @@ -5,14 +5,7 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'topups', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], + includeBasic: ['create', 'list', 'retrieve', 'update'], cancel: stripeMethod({ method: 'POST', diff --git a/lib/resources/Transfers.js b/lib/resources/Transfers.js index 2a0cb92ddf..3bbe6f8d9e 100644 --- a/lib/resources/Transfers.js +++ b/lib/resources/Transfers.js @@ -6,33 +6,7 @@ const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'transfers', - includeBasic: [ - 'create', - 'list', - 'retrieve', - 'update', - 'setMetadata', - 'getMetadata', - ], - - reverse: stripeMethod({ - method: 'POST', - path: '/{id}/reversals', - urlParams: ['id'], - }), - - cancel: stripeMethod({ - method: 'POST', - path: '{id}/cancel', - urlParams: ['id'], - }), - - listTransactions: stripeMethod({ - method: 'GET', - path: '{id}/transactions', - urlParams: ['id'], - methodType: 'list', - }), + includeBasic: ['create', 'list', 'retrieve', 'update'], /** * Transfer: Reversal methods diff --git a/lib/stripe.js b/lib/stripe.js index f64be33a08..4250054163 100644 --- a/lib/stripe.js +++ b/lib/stripe.js @@ -64,7 +64,6 @@ const resources = { Payouts: require('./resources/Payouts'), Plans: require('./resources/Plans'), Products: require('./resources/Products'), - RecipientCards: require('./resources/RecipientCards'), Recipients: require('./resources/Recipients'), Refunds: require('./resources/Refunds'), Reviews: require('./resources/Reviews'), @@ -84,9 +83,6 @@ const resources = { // The following rely on pre-filled IDs: ApplicationFeeRefunds: require('./resources/ApplicationFeeRefunds'), - ChargeRefunds: require('./resources/ChargeRefunds'), - CustomerCards: require('./resources/CustomerCards'), - CustomerSubscriptions: require('./resources/CustomerSubscriptions'), Persons: require('./resources/Persons'), SubscriptionScheduleRevisions: require('./resources/SubscriptionScheduleRevisions'), TaxIds: require('./resources/TaxIds'), @@ -121,9 +117,6 @@ const resources = { }), }; -// For backwards compatibility, `Files` is aliased to `FileUploads` -resources.FileUploads = resources.Files; - Stripe.StripeResource = require('./StripeResource'); Stripe.resources = resources; diff --git a/package.json b/package.json index cb01587ae0..ca65b5e495 100644 --- a/package.json +++ b/package.json @@ -57,4 +57,4 @@ "report": "nyc -r text -r lcov report", "coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" } -} \ No newline at end of file +} diff --git a/test/flows.spec.js b/test/flows.spec.js index 5df1029065..28a98be4a6 100644 --- a/test/flows.spec.js +++ b/test/flows.spec.js @@ -52,13 +52,14 @@ describe('Flows', function() { cleanup.deleteCustomer(customer.id); cleanup.deletePlan(plan.id); - return stripe.customers.updateSubscription(customer.id, { + return stripe.subscriptions.create({ + customer: customer.id, plan: plan.id, }); }) ).to.eventually.have.property('status', 'active')); - it('Allows me to: Create a plan and subscribe a customer to it, and update subscription (multi-subs API)', () => { + it('Allows me to: Create a plan and subscribe a customer to it, and update subscription', () => { let plan; return expect( Promise.all([ @@ -81,19 +82,16 @@ describe('Flows', function() { cleanup.deleteCustomer(customer.id); cleanup.deletePlan(plan.id); - return stripe.customers.createSubscription(customer.id, { + return stripe.subscriptions.create({ + customer: customer.id, plan: plan.id, }); }) .then((subscription) => - stripe.customers.updateSubscription( - subscription.customer, - subscription.id, - { - plan: plan.id, - quantity: '3', - } - ) + stripe.subscriptions.update(subscription.id, { + plan: plan.id, + quantity: 3, + }) ) .then((subscription) => [subscription.status, subscription.quantity]) ).to.eventually.deep.equal(['active', 3]); @@ -104,8 +102,9 @@ describe('Flows', function() { stripe.customers.create(CUSTOMER_DETAILS).then((customer) => { cleanup.deleteCustomer(customer.id); - return stripe.customers - .updateSubscription(customer.id, { + return stripe.subscriptions + .create({ + customer: customer.id, plan: `someNonExistentPlan${testUtils.getRandomString()}`, }) .then( @@ -135,18 +134,24 @@ describe('Flows', function() { }, }), stripe.customers.create(CUSTOMER_DETAILS), - ]).then((j) => { - const plan = j[0]; - const customer = j[1]; + ]) + .then((j) => { + const plan = j[0]; + const customer = j[1]; - cleanup.deleteCustomer(customer.id); - cleanup.deletePlan(plan.id); + cleanup.deleteCustomer(customer.id); + cleanup.deletePlan(plan.id); - return stripe.customers.updateSubscription(customer.id, { - plan: plan.id, - cancel_at_period_end: true, - }); - }) + return stripe.subscriptions.create({ + customer: customer.id, + plan: plan.id, + }); + }) + .then((subscription) => + stripe.subscriptions.update(subscription.id, { + cancel_at_period_end: true, + }) + ) ).to.eventually.have.property('cancel_at_period_end', true)); describe('Plan name variations', () => { @@ -226,102 +231,6 @@ describe('Flows', function() { }); }); - describe('Metadata flow', () => { - it('Can save and retrieve metadata', () => { - let customer; - return expect( - stripe.customers - .create(CUSTOMER_DETAILS) - .then((cust) => { - customer = cust; - cleanup.deleteCustomer(cust.id); - return stripe.customers.setMetadata(cust.id, {foo: '123'}); - }) - .then(() => stripe.customers.getMetadata(customer.id)) - ).to.eventually.deep.equal({foo: '123'}); - }); - it('Can reset metadata', () => { - let customer; - return expect( - stripe.customers - .create(CUSTOMER_DETAILS) - .then((cust) => { - customer = cust; - cleanup.deleteCustomer(cust.id); - return stripe.customers.setMetadata(cust.id, {baz: '123'}); - }) - .then(() => stripe.customers.setMetadata(customer.id, null)) - .then(() => stripe.customers.getMetadata(customer.id)) - ).to.eventually.deep.equal({}); - }); - it('Resets metadata when setting new metadata', () => { - let customer; - return expect( - stripe.customers - .create(CUSTOMER_DETAILS) - .then((cust) => { - customer = cust; - cleanup.deleteCustomer(cust.id); - return stripe.customers.setMetadata(cust.id, {foo: '123'}); - }) - .then(() => stripe.customers.setMetadata(customer.id, {baz: '456'})) - ).to.eventually.deep.equal({baz: '456'}); - }); - it('Can set individual key/value pairs', () => { - let customer; - return expect( - stripe.customers - .create(CUSTOMER_DETAILS) - .then((cust) => { - customer = cust; - cleanup.deleteCustomer(cust.id); - }) - .then(() => stripe.customers.setMetadata(customer.id, 'baz', 456)) - .then(() => stripe.customers.setMetadata(customer.id, '_other_', 999)) - .then(() => stripe.customers.setMetadata(customer.id, 'foo', 123)) - .then(() => - // Change foo - stripe.customers.setMetadata(customer.id, 'foo', 222) - ) - .then(() => - // Delete baz - stripe.customers.setMetadata(customer.id, 'baz', null) - ) - .then(() => stripe.customers.getMetadata(customer.id)) - ).to.eventually.deep.equal({_other_: '999', foo: '222'}); - }); - it('Can set individual key/value pairs [with per request token]', () => { - let customer; - const authToken = testUtils.getUserStripeKey(); - return expect( - stripe.customers - .create(CUSTOMER_DETAILS) - .then((cust) => { - customer = cust; - cleanup.deleteCustomer(cust.id); - }) - .then(() => - stripe.customers.setMetadata(customer.id, {baz: 456}, authToken) - ) - .then(() => - stripe.customers.setMetadata(customer.id, '_other_', 999, authToken) - ) - .then(() => - stripe.customers.setMetadata(customer.id, 'foo', 123, authToken) - ) - .then(() => - // Change foo - stripe.customers.setMetadata(customer.id, 'foo', 222, authToken) - ) - .then(() => - // Delete baz - stripe.customers.setMetadata(customer.id, 'baz', null, authToken) - ) - .then(() => stripe.customers.getMetadata(customer.id, authToken)) - ).to.eventually.deep.equal({_other_: '999', foo: '222'}); - }); - }); - describe('Expanding', () => { describe('A customer within a charge', () => { it('Allows you to expand a customer object', () => @@ -517,13 +426,13 @@ describe('Flows', function() { }); }); - describe('FileUpload', () => { + describe('File', () => { it('Allows you to upload a file as a stream', () => { const testFilename = path.join(__dirname, 'resources/data/minimal.pdf'); const f = fs.createReadStream(testFilename); return expect( - stripe.fileUploads + stripe.files .create({ purpose: 'dispute_evidence', file: { @@ -541,7 +450,7 @@ describe('Flows', function() { const f = fs.readFileSync(testFilename); return expect( - stripe.fileUploads + stripe.files .create({ purpose: 'dispute_evidence', file: { @@ -564,7 +473,7 @@ describe('Flows', function() { mockedStream.emit('error', fakeError); }); - stripe.fileUploads + stripe.files .create({ purpose: 'dispute_evidence', file: { diff --git a/test/resources/ApplicationFees.spec.js b/test/resources/ApplicationFees.spec.js index 74487d76df..4264714106 100644 --- a/test/resources/ApplicationFees.spec.js +++ b/test/resources/ApplicationFees.spec.js @@ -16,20 +16,6 @@ describe('ApplicationFee Resource', () => { }); }); - describe('refund', () => { - it('Sends the correct request', () => { - stripe.applicationFees.refund('applicationFeeIdExample3242', { - amount: 23, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/application_fees/applicationFeeIdExample3242/refund', - data: {amount: 23}, - headers: {}, - }); - }); - }); - describe('refunds', () => { it('Sends the correct update request', () => { stripe.applicationFees.updateRefund( diff --git a/test/resources/Balance.spec.js b/test/resources/Balance.spec.js index c1e8a3f686..83acd76cbb 100644 --- a/test/resources/Balance.spec.js +++ b/test/resources/Balance.spec.js @@ -26,53 +26,4 @@ describe('Balance Resource', () => { }); }); }); - - describe('listTransactions', () => { - it('Sends the correct request', () => { - stripe.balance.listTransactions(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/balance/history', - data: {}, - headers: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.balance.listTransactions('aGN0bIwXnHdw5645VABjPdSn8nWY7G11'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/balance/history', - data: {}, - headers: {}, - auth: 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11', - }); - }); - }); - - describe('retrieveTransaction', () => { - it('Sends the correct request', () => { - stripe.balance.retrieveTransaction('transactionIdFoo'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/balance/history/transactionIdFoo', - data: {}, - headers: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.balance.retrieveTransaction( - 'transactionIdFoo', - 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11' - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/balance/history/transactionIdFoo', - data: {}, - headers: {}, - auth: 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11', - }); - }); - }); }); diff --git a/test/resources/ChargeRefunds.spec.js b/test/resources/ChargeRefunds.spec.js deleted file mode 100644 index 4bba3c1cae..0000000000 --- a/test/resources/ChargeRefunds.spec.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const CHARGE_TEST_ID = 'chargeIdTest999'; -const REFUND_TEST_ID = 'refundIdTest999'; - -// Create new CustomerCard instance with pre-filled customerId: -const chargeRefund = new resources.ChargeRefunds(stripe, { - chargeId: CHARGE_TEST_ID, -}); - -// Use spy from existing resource: -chargeRefund._request = stripe.customers._request; - -describe('ChargeRefund Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - chargeRefund.retrieve(REFUND_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/charges/${CHARGE_TEST_ID}/refunds/${REFUND_TEST_ID}`, - data: {}, - headers: {}, - }); - }); - }); - - describe('create', () => { - it('Sends the correct request', () => { - chargeRefund.create({ - amount: 100, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/charges/${CHARGE_TEST_ID}/refunds`, - data: {amount: 100}, - headers: {}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - chargeRefund.update(REFUND_TEST_ID, { - metadata: {key: 'value'}, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/charges/${CHARGE_TEST_ID}/refunds/${REFUND_TEST_ID}`, - data: {metadata: {key: 'value'}}, - headers: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - chargeRefund.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/charges/${CHARGE_TEST_ID}/refunds`, - data: {}, - headers: {}, - }); - }); - }); -}); diff --git a/test/resources/Charges.spec.js b/test/resources/Charges.spec.js index f0c82a4362..3c4aa224e7 100644 --- a/test/resources/Charges.spec.js +++ b/test/resources/Charges.spec.js @@ -79,127 +79,4 @@ describe('Charge Resource', () => { }); }); }); - - describe('refund', () => { - it('Sends the correct request', () => { - stripe.charges.refund('chargeIdExample3242', {amount: 23}); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/charges/chargeIdExample3242/refund', - headers: {}, - data: {amount: 23}, - }); - }); - - it('Incorrect arguments result in an error', () => { - expect( - stripe.charges.refund('chargeIdExample123', 39392) - ).to.be.eventually.rejectedWith(/unknown arguments/i); - - expect( - stripe.charges.refund({potato: 'chargeIdExample123'}) - ).to.be.eventually.rejectedWith(/must be a string, but got: object/i); - - expect(stripe.charges.refund(442)).to.be.eventually.rejectedWith( - /must be a string, but got: number/i - ); - }); - }); - - describe('refunds', () => { - it('Sends the correct update request', () => { - stripe.charges.updateRefund( - 'chargeIdExample3242', - 'refundIdExample2312', - {metadata: {key: 'value'}} - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/charges/chargeIdExample3242/refunds/refundIdExample2312', - headers: {}, - data: {metadata: {key: 'value'}}, - }); - }); - - it('Sends the correct create request', () => { - stripe.charges.createRefund('chargeIdExample3242', {amount: 100}); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/charges/chargeIdExample3242/refunds', - headers: {}, - data: {amount: 100}, - }); - }); - - it('Sends the correct list request', () => { - stripe.charges.listRefunds('chargeIdExample3242'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/charges/chargeIdExample3242/refunds', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct retrieve request', () => { - stripe.charges.retrieveRefund( - 'chargeIdExample3242', - 'refundIdExample2312' - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/charges/chargeIdExample3242/refunds/refundIdExample2312', - headers: {}, - data: {}, - }); - }); - }); - - describe('updateDispute', () => { - it('Sends the correct request', () => { - stripe.charges.updateDispute('chargeIdExample3242', {evidence: 'foo'}); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/charges/chargeIdExample3242/dispute', - headers: {}, - data: {evidence: 'foo'}, - }); - }); - }); - - describe('closeDispute', () => { - it('Sends the correct request', () => { - stripe.charges.closeDispute('chargeIdExample3242', {}); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/charges/chargeIdExample3242/dispute/close', - headers: {}, - data: {}, - }); - }); - }); - - describe('markAsFraudulent', () => { - it('Sends the correct request', () => { - stripe.charges.markAsFraudulent('chargeIdExample3242'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/charges/chargeIdExample3242', - data: {fraud_details: {user_report: 'fraudulent'}}, - headers: {}, - }); - }); - }); - - describe('markAsSafe', () => { - it('Sends the correct request', () => { - stripe.charges.markAsSafe('chargeIdExample3242'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/charges/chargeIdExample3242', - data: {fraud_details: {user_report: 'safe'}}, - headers: {}, - }); - }); - }); }); diff --git a/test/resources/CustomerCards.spec.js b/test/resources/CustomerCards.spec.js deleted file mode 100644 index 4a9812f792..0000000000 --- a/test/resources/CustomerCards.spec.js +++ /dev/null @@ -1,82 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const CUSTOMER_TEST_ID = 'customerIdTest999'; - -// Create new CustomerCard instance with pre-filled customerId: -const customerCard = new resources.CustomerCards(stripe, { - customerId: CUSTOMER_TEST_ID, -}); - -// Use spy from existing resource: -customerCard._request = stripe.customers._request; - -describe('CustomerCard Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - customerCard.retrieve('cardIdFoo456'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/customers/${CUSTOMER_TEST_ID}/cards/cardIdFoo456`, - headers: {}, - data: {}, - }); - }); - }); - - describe('create', () => { - it('Sends the correct request', () => { - customerCard.create({ - number: '123456', - exp_month: '12', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/customers/${CUSTOMER_TEST_ID}/cards`, - headers: {}, - data: {number: '123456', exp_month: '12'}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - customerCard.update('cardIdFoo456', { - name: 'Bob M. Baz', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/customers/${CUSTOMER_TEST_ID}/cards/cardIdFoo456`, - headers: {}, - data: {name: 'Bob M. Baz'}, - }); - }); - }); - - describe('del', () => { - it('Sends the correct request', () => { - customerCard.del('cardIdFoo456'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: `/v1/customers/${CUSTOMER_TEST_ID}/cards/cardIdFoo456`, - headers: {}, - data: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - customerCard.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/customers/${CUSTOMER_TEST_ID}/cards`, - headers: {}, - data: {}, - }); - }); - }); -}); diff --git a/test/resources/CustomerSubscriptions.spec.js b/test/resources/CustomerSubscriptions.spec.js deleted file mode 100644 index 842902464c..0000000000 --- a/test/resources/CustomerSubscriptions.spec.js +++ /dev/null @@ -1,100 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const CUSTOMER_TEST_ID = 'customerIdTest999'; - -// Create new CustomerSubscription instance with pre-filled customerId: -const customerSubscription = new resources.CustomerSubscriptions(stripe, { - customerId: CUSTOMER_TEST_ID, -}); - -// Use spy from existing resource: -customerSubscription._request = stripe.customers._request; - -describe('CustomerSubscription Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - customerSubscription.retrieve('subscriptionIdFoo456'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions/subscriptionIdFoo456`, - headers: {}, - data: {}, - }); - }); - }); - - describe('create', () => { - it('Sends the correct request', () => { - customerSubscription.create({ - plan: 'gold', - quantity: '12', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions`, - headers: {}, - data: {plan: 'gold', quantity: '12'}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - customerSubscription.update('subscriptionIdFoo456', { - name: 'Bob M. Baz', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions/subscriptionIdFoo456`, - headers: {}, - data: {name: 'Bob M. Baz'}, - }); - }); - }); - - describe('del', () => { - it('Sends the correct request', () => { - customerSubscription.del('subscriptionIdFoo456'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions/subscriptionIdFoo456`, - headers: {}, - data: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - customerSubscription.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions`, - headers: {}, - data: {}, - }); - }); - }); - - describe('Discount methods', () => { - describe('deleteDiscount', () => { - it('Sends the correct request', () => { - customerSubscription.deleteDiscount( - 'customerIdFoo321', - 'subscriptionIdBar654' - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: - '/v1/customers/customerIdFoo321/subscriptions/subscriptionIdBar654/discount', - headers: {}, - data: {}, - }); - }); - }); - }); -}); diff --git a/test/resources/Customers.spec.js b/test/resources/Customers.spec.js index ee3d0adf3b..57881bb790 100644 --- a/test/resources/Customers.spec.js +++ b/test/resources/Customers.spec.js @@ -164,91 +164,6 @@ describe('Customers Resource', () => { }); }); - describe('Subscription methods', () => { - describe('updateSubscription', () => { - it('Sends the correct request', () => { - stripe.customers.updateSubscription('cus_123', { - plan: 'fooPlan', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/subscription', - headers: {}, - data: {plan: 'fooPlan'}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.updateSubscription( - 'cus_123', - { - plan: 'fooPlan', - }, - TEST_AUTH_KEY - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/subscription', - headers: {}, - data: {plan: 'fooPlan'}, - auth: TEST_AUTH_KEY, - }); - }); - }); - - describe('cancelSubscription', () => { - it('Sends the correct request', () => { - stripe.customers.cancelSubscription('cus_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscription', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.cancelSubscription('cus_123', TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscription', - headers: {}, - data: {}, - auth: TEST_AUTH_KEY, - }); - }); - - describe('With at_period_end defined', () => { - it('Sends the correct request', () => { - stripe.customers.cancelSubscription('cus_123', {at_period_end: true}); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscription', - headers: {}, - data: {at_period_end: true}, - }); - }); - }); - - describe('With at_period_end defined [with specified auth]', () => { - it('Sends the correct request', () => { - stripe.customers.cancelSubscription( - 'cus_123', - {at_period_end: true}, - TEST_AUTH_KEY - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscription', - headers: {}, - data: {at_period_end: true}, - auth: TEST_AUTH_KEY, - }); - }); - }); - }); - }); - describe('Discount methods', () => { describe('deleteDiscount', () => { it('Sends the correct request', () => { @@ -261,227 +176,6 @@ describe('Customers Resource', () => { }); }); }); - - describe('deleteSubscriptionDiscount', () => { - it('Sends the correct request', () => { - stripe.customers.deleteSubscriptionDiscount('cus_123', 'sub_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscriptions/sub_123/discount', - headers: {}, - data: {}, - }); - }); - }); - }); - - describe('Metadata methods', () => { - describe('setMetadata', () => { - describe('When deleting metadata', () => { - it('Sends the correct request', () => { - stripe.customers.setMetadata('cus_123', null); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123', - headers: {}, - data: { - metadata: null, - }, - }); - }); - }); - - describe('When setting new metadata', () => { - it('Sends one request to get current, and another to set new data', () => - expect( - new Promise((resolve, reject) => { - stripe.customers - .setMetadata('cus_123', { - foo: 123, - baz: 456, - }) - .then(() => { - const reqs = stripe.REQUESTS; - resolve([ - // Last two requests - reqs[reqs.length - 2], - reqs[reqs.length - 1], - ]); - }); - }) - ).to.eventually.deep.equal([ - { - // First reset metadata: - method: 'POST', - url: '/v1/customers/cus_123', - headers: {}, - data: {metadata: null}, - }, - { - // Then set new metadata: - method: 'POST', - url: '/v1/customers/cus_123', - headers: {}, - data: { - metadata: {foo: 123, baz: 456}, - }, - }, - ])); - }); - - describe('When setting with an auth key', () => { - it('Sends the correct request, including the specified auth key', () => { - stripe.customers.setMetadata('cus_123', null, TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123', - headers: {}, - data: { - metadata: null, - }, - auth: TEST_AUTH_KEY, - }); - stripe.customers.setMetadata('cus_123', 'a', '1234', TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123', - headers: {}, - data: { - metadata: {a: '1234'}, - }, - auth: TEST_AUTH_KEY, - }); - stripe.customers.setMetadata('cus_123', 'a', null, TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123', - headers: {}, - data: { - metadata: {a: null}, - }, - auth: TEST_AUTH_KEY, - }); - }); - }); - }); - }); - - describe('Card methods', () => { - describe('retrieveCard', () => { - it('Sends the correct request', () => { - stripe.customers.retrieveCard('cus_123', 'card_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/customers/cus_123/cards/card_123', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.retrieveCard('cus_123', 'card_123', TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/customers/cus_123/cards/card_123', - headers: {}, - data: {}, - auth: TEST_AUTH_KEY, - }); - }); - }); - - describe('createCard', () => { - it('Sends the correct request', () => { - stripe.customers.createCard('cus_123', { - number: '123456', - exp_month: '12', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/cards', - headers: {}, - data: {number: '123456', exp_month: '12'}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.createCard( - 'cus_123', - { - number: '123456', - exp_month: '12', - }, - TEST_AUTH_KEY - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/cards', - headers: {}, - data: {number: '123456', exp_month: '12'}, - auth: TEST_AUTH_KEY, - }); - }); - }); - - describe('updateCard', () => { - it('Sends the correct request', () => { - stripe.customers.updateCard('cus_123', 'card_123', { - name: 'Bob M. Baz', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/cards/card_123', - headers: {}, - data: {name: 'Bob M. Baz'}, - }); - }); - }); - - describe('deleteCard', () => { - it('Sends the correct request', () => { - stripe.customers.deleteCard('cus_123', 'card_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/cards/card_123', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.deleteCard('cus_123', 'card_123', TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/cards/card_123', - headers: {}, - data: {}, - auth: TEST_AUTH_KEY, - }); - }); - }); - - describe('listCards', () => { - it('Sends the correct request', () => { - stripe.customers.listCards('cus_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/customers/cus_123/cards', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.listCards('cus_123', TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/customers/cus_123/cards', - headers: {}, - data: {}, - auth: TEST_AUTH_KEY, - }); - }); - }); }); describe('Source methods', () => { @@ -624,182 +318,6 @@ describe('Customers Resource', () => { }); }); - describe('Subscription methods', () => { - describe('retrieveSubscription', () => { - it('Sends the correct request', () => { - stripe.customers.retrieveSubscription('cus_123', 'sub_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/customers/cus_123/subscriptions/sub_123', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.retrieveSubscription( - 'cus_123', - 'sub_123', - TEST_AUTH_KEY - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/customers/cus_123/subscriptions/sub_123', - headers: {}, - data: {}, - auth: TEST_AUTH_KEY, - }); - }); - }); - - describe('createSubscription', () => { - it('Sends the correct request', () => { - stripe.customers.createSubscription('cus_123', { - plan: 'gold', - quantity: '12', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/subscriptions', - headers: {}, - data: {plan: 'gold', quantity: '12'}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.createSubscription( - 'cus_123', - { - plan: 'gold', - quantity: '12', - }, - TEST_AUTH_KEY - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/subscriptions', - headers: {}, - data: {plan: 'gold', quantity: '12'}, - auth: TEST_AUTH_KEY, - }); - }); - }); - - describe('updateSubscription (new-style api)', () => { - it('Sends the correct request', () => { - stripe.customers.updateSubscription('cus_123', 'sub_123', { - quantity: '2', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/subscriptions/sub_123', - headers: {}, - data: {quantity: '2'}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.updateSubscription( - 'cus_123', - 'sub_123', - { - quantity: '2', - }, - TEST_AUTH_KEY - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/customers/cus_123/subscriptions/sub_123', - headers: {}, - data: {quantity: '2'}, - auth: TEST_AUTH_KEY, - }); - }); - }); - - describe('cancelSubscription (new-style api)', () => { - it('Sends the correct request', () => { - stripe.customers.cancelSubscription('cus_123', 'sub_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscriptions/sub_123', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.cancelSubscription( - 'cus_123', - 'sub_123', - TEST_AUTH_KEY - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscriptions/sub_123', - headers: {}, - data: {}, - auth: TEST_AUTH_KEY, - }); - }); - - describe('With at_period_end defined', () => { - it('Sends the correct request', () => { - stripe.customers.cancelSubscription('cus_123', 'sub_123', { - at_period_end: true, - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscriptions/sub_123', - headers: {}, - data: {at_period_end: true}, - }); - }); - }); - - describe('With at_period_end defined [with specified auth]', () => { - it('Sends the correct request', () => { - stripe.customers.cancelSubscription( - 'cus_123', - 'sub_123', - {at_period_end: true}, - TEST_AUTH_KEY - ); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: '/v1/customers/cus_123/subscriptions/sub_123', - headers: {}, - data: {at_period_end: true}, - auth: TEST_AUTH_KEY, - }); - }); - }); - }); - - describe('listSubscriptions', () => { - it('Sends the correct request', () => { - stripe.customers.listSubscriptions('cus_123'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/customers/cus_123/subscriptions', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.customers.listSubscriptions('cus_123', TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/customers/cus_123/subscriptions', - headers: {}, - data: {}, - auth: TEST_AUTH_KEY, - }); - }); - }); - }); - describe('TaxId methods', () => { describe('retrieveTaxId', () => { it('Sends the correct request', () => { diff --git a/test/resources/FileUploads.spec.js b/test/resources/FileUploads.spec.js deleted file mode 100644 index 06669b84ed..0000000000 --- a/test/resources/FileUploads.spec.js +++ /dev/null @@ -1,138 +0,0 @@ -'use strict'; - -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; -const fs = require('fs'); -const path = require('path'); - -const TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; - -describe('File Uploads Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - stripe.fileUploads.retrieve('fil_12345'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/files/fil_12345', - headers: {}, - data: {}, - }); - }); - - it('Sends the correct request [with specified auth]', () => { - stripe.fileUploads.retrieve('fil_12345', TEST_AUTH_KEY); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/files/fil_12345', - headers: {}, - data: {}, - auth: TEST_AUTH_KEY, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - stripe.fileUploads.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/files', - headers: {}, - data: {}, - }); - }); - }); - - describe('create', () => { - it('Sends the correct file upload request', () => { - const testFilename = path.join(__dirname, 'data/minimal.pdf'); - const f = fs.readFileSync(testFilename); - - stripe.fileUploads.create({ - purpose: 'dispute_evidence', - file: { - data: f, - name: 'minimal.pdf', - type: 'application/octet-stream', - }, - file_link_data: {create: true}, - }); - - expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); - expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); - expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); - }); - - it('Sends the correct file upload request [with specified auth]', () => { - const testFilename = path.join(__dirname, 'data/minimal.pdf'); - const f = fs.readFileSync(testFilename); - - stripe.fileUploads.create( - { - purpose: 'dispute_evidence', - file: { - data: f, - name: 'minimal.pdf', - type: 'application/octet-stream', - }, - file_link_data: {create: true}, - }, - TEST_AUTH_KEY - ); - - expect(stripe.LAST_REQUEST).to.deep.property('host', 'files.stripe.com'); - expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); - expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); - expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); - }); - - it('Streams a file and sends the correct file upload request', () => { - const testFilename = path.join(__dirname, 'data/minimal.pdf'); - const f = fs.createReadStream(testFilename); - - return stripe.fileUploads - .create({ - purpose: 'dispute_evidence', - file: { - data: f, - name: 'minimal.pdf', - type: 'application/octet-stream', - }, - file_link_data: {create: true}, - }) - .then(() => { - expect(stripe.LAST_REQUEST).to.deep.property( - 'host', - 'files.stripe.com' - ); - expect(stripe.LAST_REQUEST).to.deep.property('method', 'POST'); - expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); - }); - }); - - it('Streams a file and sends the correct file upload request [with specified auth]', () => { - const testFilename = path.join(__dirname, 'data/minimal.pdf'); - const f = fs.createReadStream(testFilename); - - return stripe.fileUploads - .create( - { - purpose: 'dispute_evidence', - file: { - data: f, - name: 'minimal.pdf', - type: 'application/octet-stream', - }, - file_link_data: {create: true}, - }, - TEST_AUTH_KEY - ) - .then(() => { - expect(stripe.LAST_REQUEST).to.deep.property( - 'host', - 'files.stripe.com' - ); - }); - }); - }); -}); diff --git a/test/resources/Payouts.spec.js b/test/resources/Payouts.spec.js index 1f1678acae..6db0f5a387 100644 --- a/test/resources/Payouts.spec.js +++ b/test/resources/Payouts.spec.js @@ -70,16 +70,4 @@ describe('Payouts Resource', () => { }); }); }); - - describe('listTransactions', () => { - it('Sends the correct request', () => { - stripe.payouts.listTransactions(PAYOUT_TEST_ID); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/payouts/${PAYOUT_TEST_ID}/transactions`, - headers: {}, - data: {}, - }); - }); - }); }); diff --git a/test/resources/RecipientCards.spec.js b/test/resources/RecipientCards.spec.js deleted file mode 100644 index 885b974912..0000000000 --- a/test/resources/RecipientCards.spec.js +++ /dev/null @@ -1,82 +0,0 @@ -'use strict'; - -const resources = require('../../lib/stripe').resources; -const stripe = require('../../testUtils').getSpyableStripe(); -const expect = require('chai').expect; - -const RECIPIENT_TEST_ID = 'recipientIdTest999'; - -// Create new recipientCard instance with pre-filled recipientId: -const recipientCard = new resources.RecipientCards(stripe, { - recipientId: RECIPIENT_TEST_ID, -}); - -// Use spy from existing resource: -recipientCard._request = stripe.recipients._request; - -describe('RecipientCard Resource', () => { - describe('retrieve', () => { - it('Sends the correct request', () => { - recipientCard.retrieve('cardIdFoo456'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards/cardIdFoo456`, - headers: {}, - data: {}, - }); - }); - }); - - describe('create', () => { - it('Sends the correct request', () => { - recipientCard.create({ - number: '123456', - exp_month: '12', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards`, - headers: {}, - data: {number: '123456', exp_month: '12'}, - }); - }); - }); - - describe('update', () => { - it('Sends the correct request', () => { - recipientCard.update('cardIdFoo456', { - name: 'Bob M. Baz', - }); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards/cardIdFoo456`, - headers: {}, - data: {name: 'Bob M. Baz'}, - }); - }); - }); - - describe('del', () => { - it('Sends the correct request', () => { - recipientCard.del('cardIdFoo456'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'DELETE', - url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards/cardIdFoo456`, - headers: {}, - data: {}, - }); - }); - }); - - describe('list', () => { - it('Sends the correct request', () => { - recipientCard.list(); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards`, - headers: {}, - data: {}, - }); - }); - }); -}); diff --git a/test/resources/Transfers.spec.js b/test/resources/Transfers.spec.js index bc369d8b4d..03c8d2e0e1 100644 --- a/test/resources/Transfers.spec.js +++ b/test/resources/Transfers.spec.js @@ -46,30 +46,6 @@ describe('Transfers Resource', () => { }); }); - describe('cancel', () => { - it('Sends the correct request', () => { - stripe.transfers.cancel('transferId4'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/transfers/transferId4/cancel', - headers: {}, - data: {}, - }); - }); - }); - - describe('reverse', () => { - it('Sends the correct request', () => { - stripe.transfers.reverse('transferId4'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'POST', - url: '/v1/transfers/transferId4/reversals', - headers: {}, - data: {}, - }); - }); - }); - describe('list', () => { it('Sends the correct request', () => { stripe.transfers.list(); @@ -81,16 +57,4 @@ describe('Transfers Resource', () => { }); }); }); - - describe('listTransactions', () => { - it('Sends the correct request', () => { - stripe.transfers.listTransactions('tr_14222'); - expect(stripe.LAST_REQUEST).to.deep.equal({ - method: 'GET', - url: '/v1/transfers/tr_14222/transactions', - headers: {}, - data: {}, - }); - }); - }); }); diff --git a/test/stripe.spec.js b/test/stripe.spec.js index 7304a9d3e5..37fb4b62b8 100644 --- a/test/stripe.spec.js +++ b/test/stripe.spec.js @@ -249,7 +249,7 @@ describe('Stripe Module', function() { it('Given an error the callback will receive it', () => expect( new Promise((resolve, reject) => { - stripe.customers.createCard( + stripe.customers.createSource( 'nonExistentCustId', {card: {}}, (err, customer) => {