From 18cd546cb29a8c91332c16aa3b1031cd6c9f7b78 Mon Sep 17 00:00:00 2001 From: Jesse Shawl Date: Thu, 18 Jan 2024 13:40:37 -0600 Subject: [PATCH] Update hosted buttons funding source mapping (#2314) --- src/hosted-buttons/utils.js | 15 ++------------- src/hosted-buttons/utils.test.js | 10 ++-------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/hosted-buttons/utils.js b/src/hosted-buttons/utils.js index 9c380df316..66134d5919 100644 --- a/src/hosted-buttons/utils.js +++ b/src/hosted-buttons/utils.js @@ -58,17 +58,6 @@ export const createAccessToken: CreateAccessToken = memoize( 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, }) => { @@ -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, }), @@ -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, { diff --git a/src/hosted-buttons/utils.test.js b/src/hosted-buttons/utils.test.js index 8f3add1905..79bff3c42c 100644 --- a/src/hosted-buttons/utils.test.js +++ b/src/hosted-buttons/utils.test.js @@ -7,7 +7,6 @@ import { ZalgoPromise } from "@krakenjs/zalgo-promise/src"; import { buildHostedButtonCreateOrder, buildHostedButtonOnApprove, - getFundingSource, getHostedButtonDetails, } from "./utils"; @@ -142,13 +141,13 @@ 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}` ); @@ -156,8 +155,3 @@ describe("buildHostedButtonOnApprove", () => { expect.assertions(2); }); }); - -test("getFundingSource", () => { - expect(getFundingSource("paypal")).toEqual("PAYPAL"); - expect(getFundingSource("credit")).toEqual("CARD"); -});