Skip to content

Commit

Permalink
Update hosted buttons funding source mapping (#2314)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed Jan 18, 2024
1 parent 5bb0cef commit 18cd546
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
15 changes: 2 additions & 13 deletions src/hosted-buttons/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ export const createAccessToken: CreateAccessToken = memoize<CreateAccessToken>(
const getButtonVariable = (variables: ButtonVariables, key: string): string =>
variables?.find((variable) => variable.name === key)?.value ?? "";

export const getFundingSource = (paymentSource: string): string => {
let fundingSource = paymentSource;
// The SDK uses "credit" for the "Debit or Credit Card" button, but the
// Hosted Buttons API expects "CARD" for the "Debit or Credit Card" button
// as the `funding_source` property.
if (paymentSource === FUNDING.CREDIT) {
fundingSource = FUNDING.CARD;
}
return fundingSource.toUpperCase();
};

export const getHostedButtonDetails: HostedButtonDetailsParams = ({
hostedButtonId,
}) => {
Expand Down Expand Up @@ -133,7 +122,7 @@ export const buildHostedButtonCreateOrder = ({
method: "POST",
body: JSON.stringify({
entry_point: entryPoint,
funding_source: getFundingSource(data.paymentSource),
funding_source: data.paymentSource.toUpperCase(),
merchant_id: merchantId,
...userInputs,
}),
Expand Down Expand Up @@ -163,7 +152,7 @@ export const buildHostedButtonOnApprove = ({
// The "Debit or Credit Card" button does not open a popup
// so we need to open a new popup for buyers who complete
// a checkout via "Debit or Credit Card".
if (data.paymentSource === FUNDING.CREDIT) {
if (data.paymentSource === FUNDING.CARD) {
const url = `${baseUrl}/ncp/payment/${hostedButtonId}/${data.orderID}`;
if (supportsPopups()) {
popup(url, {
Expand Down
10 changes: 2 additions & 8 deletions src/hosted-buttons/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
import {
buildHostedButtonCreateOrder,
buildHostedButtonOnApprove,
getFundingSource,
getHostedButtonDetails,
} from "./utils";

Expand Down Expand Up @@ -142,22 +141,17 @@ describe("buildHostedButtonOnApprove", () => {

// $FlowIssue
supportsPopups.mockImplementation(() => true);
await onApprove({ orderID, paymentSource: "credit" });
await onApprove({ orderID, paymentSource: "card" });
expect(popup).toHaveBeenCalled();

// but redirects if popups are not supported
// $FlowIssue
supportsPopups.mockImplementation(() => false);
await onApprove({ orderID, paymentSource: "credit" });
await onApprove({ orderID, paymentSource: "card" });
expect(window.location).toMatch(
`/ncp/payment/${hostedButtonId}/${orderID}`
);

expect.assertions(2);
});
});

test("getFundingSource", () => {
expect(getFundingSource("paypal")).toEqual("PAYPAL");
expect(getFundingSource("credit")).toEqual("CARD");
});

0 comments on commit 18cd546

Please sign in to comment.