Skip to content

Commit 314c53a

Browse files
committed
Fallback to & delimiter
1 parent e3c2381 commit 314c53a

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/lib/appSwitchResume.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ function getParamsFromHashFragment(): { [string]: string } {
2727
return {};
2828
}
2929

30+
// Check for ? delimiter first (e.g. #payment?token=...)
3031
const questionMarkIndex = hashString.indexOf("?");
3132
if (questionMarkIndex !== -1) {
3233
const queryString = hashString.slice(questionMarkIndex + 1);
33-
return Object.fromEntries(
34-
// eslint-disable-next-line compat/compat
35-
new URLSearchParams(queryString)
36-
);
34+
return Object.fromEntries(new URLSearchParams(queryString));
35+
}
36+
37+
// Fallback to & delimiter (e.g. #payment&token=...)
38+
const ampersandIndex = hashString.indexOf("&");
39+
if (ampersandIndex !== -1) {
40+
const queryString = hashString.slice(ampersandIndex + 1);
41+
return Object.fromEntries(new URLSearchParams(queryString));
3742
}
3843

3944
return {};

src/lib/appSwithResume.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ describe("app switch resume flow", () => {
184184
expect(isAppSwitchResumeFlow()).toEqual(true);
185185
});
186186

187+
test("should extract resume params when hash uses & delimiter instead of ?", () => {
188+
// Real-world case: URL like /ppcp-js-sdk?clientSideDelay=0#payment&token=...&PayerID=...
189+
vi.spyOn(window, "location", "get").mockReturnValue({
190+
hash: `#payment&token=${orderID}&PayerID=PP-payer-122&button_session_id=${buttonSessionID}`,
191+
search: "?clientSideDelay=0&serverSideDelay=0",
192+
});
193+
194+
const params = getAppSwitchResumeParams();
195+
196+
expect(params).toEqual({
197+
buttonSessionID,
198+
checkoutState: "onApprove",
199+
orderID,
200+
payerID: "PP-payer-122",
201+
});
202+
expect(isAppSwitchResumeFlow()).toEqual(true);
203+
});
204+
187205
test("should extract vault resume params from hash fragment", () => {
188206
vi.spyOn(window, "location", "get").mockReturnValue({
189207
hash: `#/step3?button_session_id=${buttonSessionID}&token=${orderID}&approval_token_id=VA-3`,

0 commit comments

Comments
 (0)