mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 07:51:55 +03:00
e476eebd2d
ref https://linear.app/tryghost/issue/ENG-1254 - when a subscription is canceled automatically by Stripe (e.g. due to multiple failed payments), we now send a staff notification - logic before: if a member cancels a sub in Portal, then send a staff notification - logic now: if a subscription was active, but is now set to cancel immediately or at the end of the billing period, then send a staff notification. - with that logic change, we now send a cancellation staff notification when: 1. A member cancels their sub in Portal (existing) 2. A staff member cancels a member sub in Stripe (new) 3. A staff member cancels a member sub in Admin (new) 4. A sub is canceled automatically by Stripe because of multiple failed payments (new) - the copy of the staff notification email has also been updated to take into account 1) manual vs automatic cancellations, and 2) immediate vs end of billing period cancellations
30 lines
730 B
JavaScript
30 lines
730 B
JavaScript
/**
|
|
* @typedef {object} SubscriptionCancelledEventData
|
|
* @prop {string} source
|
|
* @prop {string} memberId
|
|
* @prop {string} tierId
|
|
* @prop {string} subscriptionId
|
|
* @prop {boolean} cancelNow
|
|
* @prop {Date} expiryAt
|
|
* @prop {Date} canceledAt
|
|
*/
|
|
|
|
module.exports = class SubscriptionCancelledEvent {
|
|
/**
|
|
* @param {SubscriptionCancelledEventData} data
|
|
* @param {Date} timestamp
|
|
*/
|
|
constructor(data, timestamp) {
|
|
this.data = data;
|
|
this.timestamp = timestamp;
|
|
}
|
|
|
|
/**
|
|
* @param {SubscriptionCancelledEventData} data
|
|
* @param {Date} [timestamp]
|
|
*/
|
|
static create(data, timestamp) {
|
|
return new SubscriptionCancelledEvent(data, timestamp || new Date);
|
|
}
|
|
};
|