From 2b27716116b1c159c9b6609b27bcb591a4b02490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20N=C3=A9meth?= Date: Wed, 15 Jan 2025 19:43:05 +0100 Subject: [PATCH] Fixing end date --- .../Handlers/SubscriptionStripeWebhookEventHandler.cs | 6 +++++- 1 file changed, 5 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..96055500f 100644 --- a/src/Modules/OrchardCore.Commerce.Payment.Stripe/Handlers/SubscriptionStripeWebhookEventHandler.cs +++ b/src/Modules/OrchardCore.Commerce.Payment.Stripe/Handlers/SubscriptionStripeWebhookEventHandler.cs @@ -54,7 +54,11 @@ 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: + // 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;