From fe860b22e034c7bb0c5455cef438e19fe0533982 Mon Sep 17 00:00:00 2001 From: Jesse Shawl Date: Fri, 17 Nov 2023 16:04:45 -0600 Subject: [PATCH] refactor --- src/hosted-buttons/index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/hosted-buttons/index.js b/src/hosted-buttons/index.js index a689b1c941..2eef75b502 100644 --- a/src/hosted-buttons/index.js +++ b/src/hosted-buttons/index.js @@ -27,15 +27,17 @@ type HostedButtonDetailsParams = (HostedButtonsProps) => ZalgoPromise<{| |}, |}>; +type ButtonVariables = $ReadOnlyArray<{| + name: string, + value: string, +|}>; + const headers = { "PayPal-Entry-Point": "SDK", "Content-Type": "application/json", }; -type ButtonVariables = $ReadOnlyArray<{| - name: string, - value: string, -|}>; +const apiUrl = `https://${getSDKHost()}/v1/ncp`; const getButtonVariable = (variables: ButtonVariables, key: string): string => variables.find((variable) => variable.name === key)?.value ?? ""; @@ -43,9 +45,8 @@ const getButtonVariable = (variables: ButtonVariables, key: string): string => export const getHostedButtonDetails: HostedButtonDetailsParams = ({ hostedButtonId, }) => { - const apiUrl = getSDKHost(); return request({ - url: `https://${apiUrl}/v1/ncp/button/${hostedButtonId}`, + url: `${apiUrl}/button/${hostedButtonId}`, headers, }).then(({ body }) => { return { @@ -68,7 +69,7 @@ export const getHostedButtonCreateOrder = ({ }: HostedButtonsProps): CreateOrder => { return () => { return request({ - url: `https://${getSDKHost()}/v1/ncp/orders`, + url: `${apiUrl}/orders`, headers, method: "POST", body: JSON.stringify({ @@ -89,7 +90,7 @@ export const getHostedButtonOnApprove = ({ }: HostedButtonsProps): OnApprove => { return (data) => { return request({ - url: `https://${getSDKHost()}/v1/ncp/orders/${data.orderID}/capture`, + url: `${apiUrl}/orders/${data.orderID}/capture`, headers, method: "POST", body: JSON.stringify({