fix(stripe): correcting webhook
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user