Added Stripe webhook listener for subscription created event (#208)

no-issue

Subscription created events are required for migrating Stripe subscriptions from
alternative platforms, which involves creating a new subscription for a customer
(outside of Ghost) before cancelling the original subscription.
This commit is contained in:
Matt Hanley 2020-10-15 11:55:36 +01:00 committed by GitHub
parent 2544212ff7
commit 4359517e75
2 changed files with 9 additions and 0 deletions

View File

@ -346,6 +346,10 @@ module.exports = function MembersApi({
await stripe.handleCustomerSubscriptionUpdatedWebhook(event.data.object);
}
if (event.type === 'customer.subscription.created') {
await stripe.handleCustomerSubscriptionCreatedWebhook(event.data.object);
}
if (event.type === 'invoice.payment_succeeded') {
await stripe.handleInvoicePaymentSucceededWebhook(event.data.object);
}

View File

@ -70,6 +70,7 @@ module.exports = class StripePaymentProcessor {
'checkout.session.completed',
'customer.subscription.deleted',
'customer.subscription.updated',
'customer.subscription.created',
'invoice.payment_succeeded',
'invoice.payment_failed'
]
@ -386,6 +387,10 @@ module.exports = class StripePaymentProcessor {
await this._updateSubscription(subscription);
}
async handleCustomerSubscriptionCreatedWebhook(subscription) {
await this._updateSubscription(subscription);
}
async handleInvoicePaymentSucceededWebhook(invoice) {
const subscription = await retrieve(this._stripe, 'subscriptions', invoice.subscription, {
expand: ['default_payment_method']