Skip to content

Commit 82af8b4

Browse files
authored
ncps - expand inline guest (#2356)
1 parent ef84ca5 commit 82af8b4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: src/hosted-buttons/utils.js

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getClientID,
88
getMerchantID as getSDKMerchantID,
99
} from "@paypal/sdk-client/src";
10+
import { FUNDING } from "@paypal/sdk-constants/src";
1011

1112
import type {
1213
ButtonVariables,
@@ -208,6 +209,14 @@ export const buildHostedButtonOnApprove = ({
208209
merchant_id: merchantId,
209210
context_id: data.orderID,
210211
}),
212+
}).then((response) => {
213+
// The "Debit or Credit Card" button does not open a popup
214+
// so we need to redirect to the thank you page for buyers who complete
215+
// a checkout via "Debit or Credit Card".
216+
if (data.paymentSource === FUNDING.CARD) {
217+
window.location = `${baseUrl}/ncp/payment/${hostedButtonId}/${data.orderID}`;
218+
}
219+
return response;
211220
});
212221
};
213222
};

Diff for: src/hosted-buttons/utils.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,28 @@ describe("buildHostedButtonOnApprove", () => {
264264
);
265265
expect.assertions(1);
266266
});
267+
268+
describe("inline guest", () => {
269+
const onApprove = buildHostedButtonOnApprove({
270+
hostedButtonId,
271+
merchantId,
272+
});
273+
// $FlowIssue
274+
request.mockImplementation(() =>
275+
// eslint-disable-next-line compat/compat
276+
Promise.resolve({
277+
body: {},
278+
})
279+
);
280+
281+
test("redirects from the merchant's site to a thank you page", async () => {
282+
expect(window.location.href).toBe("http://localhost:3000/");
283+
await onApprove({ orderID, paymentSource: "card" });
284+
expect(window.location).toBe(
285+
"https://example.com/ncp/payment/B1234567890/EC-1234567890"
286+
);
287+
});
288+
});
267289
});
268290

269291
/* eslint-enable no-restricted-globals, promise/no-native */

0 commit comments

Comments
 (0)