Skip to content

Commit 218ef5d

Browse files
authored
chore: implement resume interface for redirect (#59)
1 parent 590797c commit 218ef5d

File tree

1 file changed

+11
-14
lines changed
  • client/components/paypalPayments/oneTimePayment/html/src/advanced/redirect

1 file changed

+11
-14
lines changed

client/components/paypalPayments/oneTimePayment/html/src/advanced/redirect/app.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ async function onPayPalLoaded() {
66
components: ["paypal-payments"],
77
pageType: "checkout",
88
});
9+
const paypalPaymentSession = sdkInstance.createPayPalOneTimePaymentSession(
10+
paymentSessionOptions,
11+
);
912

10-
setupPayPalButton(sdkInstance);
13+
if (paypalPaymentSession.hasReturned()) {
14+
await paypalPaymentSession.resume();
15+
} else {
16+
setupPayPalButton(paypalPaymentSession);
17+
}
1118
} catch (error) {
1219
console.error(error);
1320
}
@@ -29,11 +36,7 @@ const paymentSessionOptions = {
2936
},
3037
};
3138

32-
async function setupPayPalButton(sdkInstance) {
33-
const paypalPaymentSession = sdkInstance.createPayPalOneTimePaymentSession(
34-
paymentSessionOptions,
35-
);
36-
39+
async function setupPayPalButton(paypalPaymentSession) {
3740
const enableAutoRedirect = document.querySelector("#enable-auto-redirect");
3841
const paypalButton = document.querySelector("#paypal-button");
3942
paypalButton.removeAttribute("hidden");
@@ -74,21 +77,15 @@ async function getBrowserSafeClientToken() {
7477
}
7578

7679
async function createRedirectOrder() {
77-
const returnUrl = new URL(window.location);
78-
returnUrl.searchParams.set("flowState", "approve");
79-
80-
const cancelUrl = new URL(window.location);
81-
cancelUrl.searchParams.set("flowState", "cancel");
82-
8380
const orderPayload = {
8481
intent: "CAPTURE",
8582
paymentSource: {
8683
paypal: {
8784
experienceContext: {
8885
shippingPreference: "NO_SHIPPING",
8986
userAction: "CONTINUE",
90-
returnUrl,
91-
cancelUrl,
87+
returnUrl: window.location.href,
88+
cancelUrl: window.location.href,
9289
},
9390
},
9491
},

0 commit comments

Comments
 (0)