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
This commit is contained in:
Rishabh 2022-08-25 13:00:48 +05:30 committed by Rishabh Garg
parent 216eeb9d71
commit 4ac1a2c21e

View File

@ -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