From aa17a6cde538e323bfa26fc07936cde58f3831cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20N=C3=A9meth?= Date: Thu, 16 Jan 2025 18:52:29 +0100 Subject: [PATCH] OFFI-221: Fixing subscription end date (#513) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixing end date * Update src/Modules/OrchardCore.Commerce.Payment.Stripe/Handlers/SubscriptionStripeWebhookEventHandler.cs Co-authored-by: Sára El-Saig --------- Co-authored-by: Sára El-Saig --- .../Handlers/SubscriptionStripeWebhookEventHandler.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Modules/OrchardCore.Commerce.Payment.Stripe/Handlers/SubscriptionStripeWebhookEventHandler.cs b/src/Modules/OrchardCore.Commerce.Payment.Stripe/Handlers/SubscriptionStripeWebhookEventHandler.cs index b9fea220c..6553b0efd 100644 --- a/src/Modules/OrchardCore.Commerce.Payment.Stripe/Handlers/SubscriptionStripeWebhookEventHandler.cs +++ b/src/Modules/OrchardCore.Commerce.Payment.Stripe/Handlers/SubscriptionStripeWebhookEventHandler.cs @@ -54,7 +54,12 @@ public async Task ReceivedStripeEventAsync(Event stripeEvent) var subscriptionPart = new SubscriptionPart(); subscriptionPart.UserId.Text = user.UserId; subscriptionPart.Status.Text = SubscriptionStatuses.Active; - subscriptionPart.EndDateUtc.Value = invoice.PeriodEnd; + + // invoice.PeriodEnd doesn't show the current period, see Stripe docs: + // https://docs.stripe.com/api/invoices/object#invoice_object-period_end + // "End of the usage period during which invoice items were added to this invoice. This looks back one + // period for a subscription invoice. Use the line item period to get the service period for each price." + subscriptionPart.EndDateUtc.Value = invoice.Lines.Data.Find(data => !data.Proration)?.Period.End; subscriptionPart.PaymentProviderName.Text = StripePaymentProvider.ProviderName; subscriptionPart.IdInPaymentProvider.Text = invoice.SubscriptionId;