From 4ac1a2c21e0f4f58d4297dec6660e5766dec4eb8 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Thu, 25 Aug 2022 13:00:48 +0530 Subject: [PATCH] Added paid subscription cancel email alert refs TryGhost/Team#1826 - triggers paid subscription cancellation alert for staff users - passes tier and subscription information for the email - loads tier info from DB for the subscription tier --- ghost/members-api/lib/repositories/member.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ghost/members-api/lib/repositories/member.js b/ghost/members-api/lib/repositories/member.js index c88e8c1a70..7f6fa48b00 100644 --- a/ghost/members-api/lib/repositories/member.js +++ b/ghost/members-api/lib/repositories/member.js @@ -1203,6 +1203,22 @@ module.exports = class MemberRepository { member_id: member.id, from_plan: subscriptionModel.get('plan_id') }, sharedOptions); + + if (this._labsService.isSet('emailAlerts')) { + const subscriptionPriceData = _.get(updatedSubscription, 'items.data[0].price'); + let ghostProduct; + try { + ghostProduct = await this._productRepository.get({stripe_product_id: subscriptionPriceData.product}, {...sharedOptions, forUpdate: true}); + } catch (e) { + ghostProduct = null; + } + await this.staffService.notifyPaidSubscriptionCancel({ + member: member.toJSON(), + subscription: updatedSubscription, + cancellationReason: data.subscription.cancellationReason, + tier: ghostProduct?.toJSON() + }); + } } else { updatedSubscription = await this._stripeAPIService.continueSubscriptionAtPeriodEnd( data.subscription.subscription_id