mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
🐛 Fixed cancelling subscriptions when destroying
refs https://github.com/TryGhost/Ghost/issues/12711 We must wait for the stripeSubscriptions relation to be loaded before attempting to loop through them. As well as this we should use `upsert` so that we can edit a subscription record by `subscription_id`, rather than the (internal) `id`
This commit is contained in:
parent
8b4e5f9a92
commit
095c624172
1 changed files with 7 additions and 3 deletions
|
@ -169,16 +169,20 @@ module.exports = class MemberRepository {
|
|||
}
|
||||
|
||||
if (this._stripeAPIService && options.cancelStripeSubscriptions) {
|
||||
await member.related('stripeSubscriptions');
|
||||
await member.related('stripeSubscriptions').fetch();
|
||||
const subscriptions = member.related('stripeSubscriptions');
|
||||
for (const subscription of subscriptions.models) {
|
||||
if (subscription.get('status') !== 'canceled') {
|
||||
const updatedSubscription = await this._stripeAPIService.cancelSubscription(
|
||||
subscription.get('subscription_id')
|
||||
);
|
||||
await this._StripeCustomerSubscription.update({
|
||||
|
||||
await this._StripeCustomerSubscription.upsert({
|
||||
status: updatedSubscription.status
|
||||
}, options);
|
||||
}, {
|
||||
subscription_id: updatedSubscription.id
|
||||
});
|
||||
|
||||
await this._MemberPaidSubscriptionEvent.add({
|
||||
member_id: member.id,
|
||||
source: 'stripe',
|
||||
|
|
Loading…
Add table
Reference in a new issue