Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed Nov 17, 2023
1 parent 0567c70 commit fe860b2
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/hosted-buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@ 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 ?? "";

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 {
Expand All @@ -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({
Expand All @@ -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({
Expand Down

0 comments on commit fe860b2

Please sign in to comment.