diff --git a/ghost/members-importer/lib/MembersCSVImporterStripeUtils.js b/ghost/members-importer/lib/MembersCSVImporterStripeUtils.js index 82f19adb40..113d97295a 100644 --- a/ghost/members-importer/lib/MembersCSVImporterStripeUtils.js +++ b/ghost/members-importer/lib/MembersCSVImporterStripeUtils.js @@ -153,7 +153,8 @@ module.exports = class MembersCSVImporterStripeUtils { await this._stripeAPIService.updateSubscriptionItemPrice( stripeSubscription.id, stripeSubscriptionItem.id, - newStripePrice.id + newStripePrice.id, + {prorationBehavior: 'none'} ); stripePriceId = newStripePrice.id; @@ -167,7 +168,8 @@ module.exports = class MembersCSVImporterStripeUtils { await this._stripeAPIService.updateSubscriptionItemPrice( stripeSubscription.id, stripeSubscriptionItem.id, - stripePriceId + stripePriceId, + {prorationBehavior: 'none'} ); } } diff --git a/ghost/members-importer/test/MembersCSVImporterStripeUtils.test.js b/ghost/members-importer/test/MembersCSVImporterStripeUtils.test.js index 9b1176613d..f76159c72e 100644 --- a/ghost/members-importer/test/MembersCSVImporterStripeUtils.test.js +++ b/ghost/members-importer/test/MembersCSVImporterStripeUtils.test.js @@ -304,7 +304,8 @@ describe('MembersCSVImporterStripeUtils', function () { stripeAPIServiceStub.updateSubscriptionItemPrice.calledWithExactly( stripeCustomer.subscriptions.data[0].id, stripeCustomerSubscriptionItem.id, - GHOST_PRODUCT_STRIPE_PRICE_ID + GHOST_PRODUCT_STRIPE_PRICE_ID, + {prorationBehavior: 'none'} ).should.be.true(); }); @@ -346,7 +347,8 @@ describe('MembersCSVImporterStripeUtils', function () { stripeAPIServiceStub.updateSubscriptionItemPrice.calledWithExactly( stripeCustomer.subscriptions.data[0].id, stripeCustomerSubscriptionItem.id, - NEW_STRIPE_PRICE_ID + NEW_STRIPE_PRICE_ID, + {prorationBehavior: 'none'} ).should.be.true(); }); diff --git a/ghost/stripe/lib/StripeAPI.js b/ghost/stripe/lib/StripeAPI.js index 504b8b0c1f..999e5a0155 100644 --- a/ghost/stripe/lib/StripeAPI.js +++ b/ghost/stripe/lib/StripeAPI.js @@ -698,20 +698,23 @@ module.exports = class StripeAPI { * @param {string} subscriptionId - The ID of the Subscription to modify * @param {string} id - The ID of the SubscriptionItem * @param {string} price - The ID of the new Price + * @param {object} [options={}] - Additional data to set on the subscription object + * @param {('always_invoice'|'create_prorations'|'none')} [options.prorationBehavior='always_invoice'] - The proration behavior to use. See [Stripe docs](https://docs.stripe.com/api/subscriptions/update#update_subscription-proration_behavior) for more info + * @param {string} [options.cancellationReason=null] - The user defined cancellation reason * * @returns {Promise} */ - async updateSubscriptionItemPrice(subscriptionId, id, price) { + async updateSubscriptionItemPrice(subscriptionId, id, price, options = {}) { await this._rateLimitBucket.throttle(); const subscription = await this._stripe.subscriptions.update(subscriptionId, { - proration_behavior: 'always_invoice', + proration_behavior: options.prorationBehavior || 'always_invoice', items: [{ id, price }], cancel_at_period_end: false, metadata: { - cancellation_reason: null + cancellation_reason: options.cancellationReason ?? null } }); return subscription;