Skip to content

Commit 6233848

Browse files
authored
Merge pull request #10 from umbraco/hotfix/13_improve-js-to-redirect-to-checkout-page
Improve js to redirect buyer to stripe checkout page
2 parents e0c9a4f + b96cab0 commit 6233848

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/Umbraco.Commerce.PaymentProviders.Stripe/StripeCheckoutPaymentProvider.cs

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
using Stripe;
2-
using Stripe.Checkout;
31
using System;
42
using System.Collections.Generic;
53
using System.Linq;
64
using System.Net.Http;
75
using System.Net.Http.Formatting;
86
using System.Threading;
97
using System.Threading.Tasks;
8+
using Stripe;
9+
using Stripe.Checkout;
1010
using Umbraco.Commerce.Common.Logging;
1111
using Umbraco.Commerce.Core;
1212
using Umbraco.Commerce.Core.Api;
1313
using Umbraco.Commerce.Core.Models;
1414
using Umbraco.Commerce.Core.PaymentProviders;
1515
using Umbraco.Commerce.Extensions;
16-
1716
using CustomerService = Stripe.CustomerService;
1817
using RefundService = Stripe.RefundService;
1918

@@ -224,23 +223,15 @@ public override async Task<PaymentFormResult> GenerateFormAsync(PaymentProviderC
224223
{ "stripeSessionId", session.Id },
225224
{ "stripeCustomerId", session.CustomerId }
226225
},
227-
Form = new PaymentForm(ctx.Urls.ContinueUrl, PaymentFormMethod.Post)
226+
Form = new PaymentForm(ctx.Urls.ErrorUrl, PaymentFormMethod.Post)
228227
.WithAttribute("onsubmit", "return handleStripeCheckout(event)")
229-
.WithJsFile("https://js.stripe.com/v3/")
230228
.WithJs(@"
231-
var stripe = Stripe('" + publicKey + @"');
232229
window.handleStripeCheckout = function (e) {
233230
e.preventDefault();
234-
stripe.redirectToCheckout({
235-
sessionId: '" + session.Id + @"'
236-
}).then(function (result) {
237-
// If `redirectToCheckout` fails due to a browser or network
238-
// error, display the localized error message to your customer
239-
// using `result.error.message`.
240-
});
231+
window.location.href = '" + session.Url + @"';
241232
return false;
242233
}
243-
")
234+
"),
244235
};
245236
}
246237

@@ -347,7 +338,7 @@ private async Task<CallbackResult> ProcessWebhookCallbackAsync(PaymentProviderCo
347338
stripeSession.PaymentIntentId,
348339
new PaymentIntentGetOptions
349340
{
350-
Expand = new List<string>(new []
341+
Expand = new List<string>(new[]
351342
{
352343
"latest_charge",
353344
"review"
@@ -379,9 +370,9 @@ private async Task<CallbackResult> ProcessWebhookCallbackAsync(PaymentProviderCo
379370
var subscription = await subscriptionService.GetAsync(
380371
stripeSession.SubscriptionId,
381372
new SubscriptionGetOptions
382-
{
373+
{
383374
Expand = new List<string>(new[]
384-
{
375+
{
385376
"latest_invoice",
386377
"latest_invoice.charge",
387378
"latest_invoice.charge.review",

version.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "13.1.0",
3+
"version": "13.1.1",
44
"assemblyVersion": {
55
"precision": "build"
66
},

0 commit comments

Comments
 (0)