Skip to content

Commit

Permalink
pass down the exact action
Browse files Browse the repository at this point in the history
  • Loading branch information
ravishekhar committed Dec 19, 2024
1 parent 17a09bc commit 4b0f29f
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/lib/appSwitchResume.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,47 @@ export type AppSwitchResumeParams = {|
buttonSessionID: string,
payerID?: string,
billingToken?: string,
paymentID?: string,
subscriptionID?: string,
checkoutState: "onApprove" | "onCancel" | "onError",
|};

export function getAppSwitchResumeParams(): AppSwitchResumeParams | null {
const urlHash = String(window.location.hash).replace("#", "");
const isPostApprovalAction = [
APP_SWITCH_RETURN_HASH.ONAPPROVE,
APP_SWITCH_RETURN_HASH.ONCANCEL,
APP_SWITCH_RETURN_HASH.ONERROR,
].includes(urlHash);
if (!isPostApprovalAction) {
return null;
}
// eslint-disable-next-line compat/compat
const search = new URLSearchParams(location.search);
const orderID = search.get("orderID");
const payerID = search.get("payerID");
const vaultSessionID = search.get("vaultSessionID");
const buttonSessionID = search.get("buttonSessionID");
const billingToken = search.get("billingToken");
const paymentID = search.get("paymentID");
const subscriptionID = search.get("subscriptionID");
if (buttonSessionID) {
const params: AppSwitchResumeParams = {
orderID,
vaultSessionID,
buttonSessionID,
payerID,
billingToken,
paymentID,
subscriptionID,
checkoutState: urlHash,
};
return params;
}
return null;
}

export function isAppSwitchResumeFlow(): boolean {
const hash = String(window.location.hash).replace("#", "");
const isPostApprovalAction = [
APP_SWITCH_RETURN_HASH.ONAPPROVE,
APP_SWITCH_RETURN_HASH.ONCANCEL,
APP_SWITCH_RETURN_HASH.ONERROR,
].includes(hash);
const params = getAppSwitchResumeParams();
return isPostApprovalAction && params !== null;
return params !== null;
}

0 comments on commit 4b0f29f

Please sign in to comment.