From 5136f642529a85563618fb7df56f0ac3ccca8363 Mon Sep 17 00:00:00 2001 From: javayhu Date: Mon, 8 Sep 2025 00:46:15 +0800 Subject: [PATCH] chore: add more logs in subscription webhooks --- src/payment/provider/stripe.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/payment/provider/stripe.ts b/src/payment/provider/stripe.ts index 316fc8e..86ac720 100644 --- a/src/payment/provider/stripe.ts +++ b/src/payment/provider/stripe.ts @@ -521,6 +521,17 @@ export class StripeProvider implements PaymentProvider { /** * Handle successful invoice payment - NEW ARCHITECTURE * Only create payment records here after payment is confirmed + * + * For one-time payments, the order of events may be: + * checkout.session.completed + * invoice.payment_succeeded + * + * For subscription payments, the order of events may be: + * checkout.session.completed + * customer.subscription.created + * customer.subscription.updated + * invoice.payment_succeeded + * * @param invoice Stripe invoice */ private async onInvoicePaymentSucceeded( @@ -671,6 +682,11 @@ export class StripeProvider implements PaymentProvider { /** * Create one-time payment record and process benefits - NEW ARCHITECTURE + * + * The order of events may be: + * checkout.session.completed + * invoice.payment_succeeded + * * @param invoice Stripe invoice */ private async createOneTimePayment(invoice: Stripe.Invoice): Promise { @@ -893,6 +909,13 @@ export class StripeProvider implements PaymentProvider { /** * Update payment record + * + * When subscription is renewed, the order of events may be: + * customer.subscription.updated + * invoice.payment_succeeded + * + * In this case, we need to update the payment record. + * * @param stripeSubscription Stripe subscription */ private async onUpdateSubscription(