mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 10:42:45 +03:00
Removed coupons from subscriptions when the price changes
refs https://github.com/TryGhost/Team/issues/1092 refs https://github.com/TryGhost/Team/issues/1135 This was missed in the initial due to the issue tracking the task being superceded, and the task not being copied across to the superceding issue. A new method to remove coupons has been added, as opposed to updating the existing change subscription price method, because the removal of a coupon is not the concern of an auxillary stripe service, but a busines concern that should be explicit in the members-api codebase.
This commit is contained in:
parent
4b005da248
commit
2fcafcc8dc
@ -861,11 +861,14 @@ module.exports = class MemberRepository {
|
||||
|
||||
const subscriptionItem = subscription.items.data[0];
|
||||
|
||||
if (data.subscription.price !== subscription.price) {
|
||||
updatedSubscription = await this._stripeAPIService.updateSubscriptionItemPrice(
|
||||
subscription.id,
|
||||
subscriptionItem.id,
|
||||
data.subscription.price
|
||||
);
|
||||
updatedSubscription = await this._stripeAPIService.removeCouponFromSubscription(subscription.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.subscription.cancel_at_period_end !== undefined) {
|
||||
|
@ -508,6 +508,19 @@ module.exports = class StripeService {
|
||||
return subscription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} id - The ID of the subscription to remove coupon from
|
||||
*
|
||||
* @returns {Promise<import('stripe').Stripe.Subscription>}
|
||||
*/
|
||||
async removeCouponFromSubscription(id) {
|
||||
await this._rateLimitBucket.throttle();
|
||||
const subscription = await this._stripe.subscriptions.update(id, {
|
||||
coupon: ''
|
||||
});
|
||||
return subscription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} subscriptionId - The ID of the Subscription to modify
|
||||
* @param {string} id - The ID of the SubscriptionItem
|
||||
|
Loading…
Reference in New Issue
Block a user