fix(stripe): correcting webhook

This commit is contained in:
2025-08-04 17:15:13 -04:00
parent 18532963a8
commit ea8efd21a1
6 changed files with 134 additions and 113 deletions

View File

@@ -11,7 +11,7 @@ namespace Hutopy.Modules.Memberships.Handlers;
internal class StripeWebhookEndpoint(
ITipPaymentNotifier tipPaymentNotifier,
IMembershipNotifier membershipNotifier,
IOptions<StripeOptions> options)
IOptions<StripeOptions> stripeOptions)
: EndpointWithoutRequest
{
public override void Configure()
@@ -28,7 +28,7 @@ internal class StripeWebhookEndpoint(
var json = await streamReader.ReadToEndAsync(ct).ConfigureAwait(false);
var stripeEvent = EventUtility.ConstructEvent(json, signatureHeader, options.Value.WebhookSecret);
var stripeEvent = EventUtility.ConstructEvent(json, signatureHeader, stripeOptions.Value.WebhookSecret);
var stripeSession = stripeEvent.Data.Object as Session;
var stripeSubscription = stripeEvent.Data.Object as Subscription;
@@ -46,13 +46,22 @@ internal class StripeWebhookEndpoint(
stripeSession.Customer?.Email ??
"";
// Get the receipt URL, preferring the one directly on the charge if available
var receiptUrl = stripeSession.Invoice?.HostedInvoiceUrl ?? "";
StripeConfiguration.ApiKey = stripeOptions.Value.SecretKey;
var paymentIntentService = new PaymentIntentService();
var paymentIntent = await paymentIntentService
.GetAsync(
stripeSession.PaymentIntentId,
new PaymentIntentGetOptions { Expand = ["latest_charge"] },
cancellationToken: ct)
.ConfigureAwait(false);
var receiptUrl = paymentIntent.LatestCharge.ReceiptUrl;
var receiptUri = new Uri(receiptUrl);
// Get the receipt URL, preferring the one directly on the charge if available
await tipPaymentNotifier
.NotifyPaymentSucceedAsync(
stripeSession.Id,
receiptUrl,
receiptUri,
customerEmail,
ct)
.ConfigureAwait(false);