@paypal/checkout-components
Advanced tools
Comparing version 5.0.347 to 5.0.348-alpha-810e232.0
{ | ||
"name": "@paypal/checkout-components", | ||
"version": "5.0.347", | ||
"version": "5.0.348-alpha-810e232.0", | ||
"description": "PayPal Checkout components, for integrating checkout products.", | ||
@@ -15,3 +15,3 @@ "main": "index.js", | ||
"demo": "serve ./demo -l 1337", | ||
"dev": "npm run check-node-version && babel-node $(npm bin)/webpack-dev-server -- --config webpack.config.dev.js --port 9001 --host localhost.paypal.com --open /index.htm --https --hot=false --static './demo/dev'", | ||
"dev": "npm run check-node-version && babel-node ./node_modules/.bin/webpack-dev-server -- --config webpack.config.dev.js --port 9001 --host localhost.paypal.com --open /index.htm --https --hot=false --static './demo/dev'", | ||
"eslint-find-rules": "eslint-find-rules --current .eslintrc.js --unused --plugin", | ||
@@ -25,3 +25,3 @@ "flow": "flow", | ||
"jest-ssr": "jest test/ssr --env=node --no-cache --collectCoverage --collectCoverageFrom='src/' --coverageDirectory='coverage/jest'", | ||
"karma": "cross-env NODE_ENV=test babel-node $(npm bin)/karma start", | ||
"karma": "cross-env NODE_ENV=test babel-node ./node_modules/.bin/karma start", | ||
"lint": "eslint --ext .js --ext .jsx src/ test/ *.js", | ||
@@ -39,3 +39,3 @@ "postversion": "./scripts/postversion.sh", | ||
"vitest": "vitest", | ||
"webpack": "babel-node $(npm bin)/webpack --", | ||
"webpack": "babel-node ./node_modules/.bin/webpack --", | ||
"webpack-size": "npm run webpack -- --config webpack.config.size", | ||
@@ -45,2 +45,6 @@ "prepare": "husky install", | ||
}, | ||
"engines": { | ||
"node": "^18", | ||
"npm": "8" | ||
}, | ||
"files": [ | ||
@@ -47,0 +51,0 @@ "src/", |
/* @flow */ | ||
import { FUNDING } from "@paypal/sdk-constants/src"; | ||
import { parseQuery } from "@krakenjs/belter/src"; | ||
@@ -19,3 +20,5 @@ import { APP_SWITCH_RETURN_HASH } from "../constants"; | ||
export function getAppSwitchResumeParams(): AppSwitchResumeParams | null { | ||
const urlHash = String(window.location.hash).replace("#", ""); | ||
const hashString = window.location.hash && window.location.hash.slice(1); | ||
const [hash, queryString] = hashString.split("?"); | ||
const isPostApprovalAction = [ | ||
@@ -25,37 +28,36 @@ APP_SWITCH_RETURN_HASH.ONAPPROVE, | ||
APP_SWITCH_RETURN_HASH.ONERROR, | ||
].includes(urlHash); | ||
].includes(hash); | ||
if (!isPostApprovalAction) { | ||
return null; | ||
} | ||
// eslint-disable-next-line compat/compat | ||
const search = new URLSearchParams(window.location.search); | ||
const orderID = search.get("orderID"); | ||
const payerID = search.get("payerID"); | ||
const buttonSessionID = search.get("buttonSessionID"); | ||
const billingToken = search.get("billingToken"); | ||
const paymentID = search.get("paymentID"); | ||
const subscriptionID = search.get("subscriptionID"); | ||
const vaultSetupToken = search.get("vaultSetupToken"); | ||
const fundingSource = search.get("fundingSource"); | ||
if (buttonSessionID) { | ||
const params: AppSwitchResumeParams = { | ||
orderID, | ||
buttonSessionID, | ||
payerID, | ||
billingToken, | ||
paymentID, | ||
subscriptionID, | ||
// URLSearchParams get returns as string, | ||
// but below code excepts a value from list of string. | ||
// $FlowIgnore[incompatible-type] | ||
fundingSource, | ||
vaultSetupToken, | ||
// the isPostApprovalAction already ensures | ||
// that the function will exit if url hash is not one of supported values. | ||
// $FlowIgnore[incompatible-type] | ||
checkoutState: urlHash, | ||
}; | ||
return params; | ||
} | ||
return null; | ||
const { | ||
token, | ||
PayerID, | ||
buttonSessionID, | ||
billingToken, | ||
paymentID, | ||
subscriptionID, | ||
vaultSetupToken, | ||
fundingSource, | ||
} = parseQuery(queryString); | ||
const params: AppSwitchResumeParams = { | ||
orderID: token, | ||
buttonSessionID, | ||
payerID: PayerID, | ||
billingToken, | ||
paymentID, | ||
subscriptionID, | ||
// URLSearchParams get returns as string, | ||
// but below code excepts a value from list of string. | ||
// $FlowIgnore[incompatible-type] | ||
fundingSource, | ||
vaultSetupToken, | ||
// the isPostApprovalAction already ensures | ||
// that the function will exit if url hash is not one of supported values. | ||
// $FlowIgnore[incompatible-type] | ||
checkoutState: hash, | ||
}; | ||
return params; | ||
} | ||
@@ -62,0 +64,0 @@ |
@@ -29,4 +29,3 @@ /* @flow */ | ||
vi.spyOn(window, "location", "get").mockReturnValue({ | ||
hash: "#onApprove", | ||
search: `buttonSessionID=${buttonSessionID}&orderID=${orderID}&fundingSource=${fundingSource}`, | ||
hash: `#onApprove?buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}`, | ||
}); | ||
@@ -38,3 +37,2 @@ | ||
expect(params).toEqual({ | ||
billingToken: null, | ||
buttonSessionID, | ||
@@ -44,6 +42,2 @@ checkoutState: "onApprove", | ||
orderID, | ||
payerID: null, | ||
paymentID: null, | ||
subscriptionID: null, | ||
vaultSetupToken: null, | ||
}); | ||
@@ -56,3 +50,3 @@ expect(isAppSwitchResumeFlow()).toEqual(true); | ||
hash: "#Unknown", | ||
search: `buttonSessionID=${buttonSessionID}&orderID=${orderID}&fundingSource=${fundingSource}`, | ||
search: `buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}`, | ||
}); | ||
@@ -69,4 +63,3 @@ | ||
vi.spyOn(window, "location", "get").mockReturnValue({ | ||
hash: "#Unknown", | ||
search: `buttonSessionID=${buttonSessionID}&orderID=${orderID}&fundingSource=${fundingSource}`, | ||
hash: `#Unknown?buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}`, | ||
}); | ||
@@ -81,6 +74,5 @@ | ||
test("should test fetching resume params when parameters are correctly passed", () => { | ||
test("should test fetching multiple resume params when parameters are correctly passed", () => { | ||
vi.spyOn(window, "location", "get").mockReturnValue({ | ||
hash: "#onApprove", | ||
search: `buttonSessionID=${buttonSessionID}&orderID=${orderID}&fundingSource=${fundingSource}&billingToken=BA-124&payerID=PP-122&paymentID=PAY-123&subscriptionID=I-1234&vaultSetupToken=VA-3`, | ||
hash: `#onApprove?buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}&billingToken=BA-124&PayerID=PP-payer-122&paymentID=PAY-123&subscriptionID=I-1234&vaultSetupToken=VA-3`, | ||
}); | ||
@@ -97,3 +89,3 @@ | ||
orderID, | ||
payerID: "PP-122", | ||
payerID: "PP-payer-122", | ||
paymentID: "PAY-123", | ||
@@ -100,0 +92,0 @@ subscriptionID: "I-1234", |
@@ -42,10 +42,3 @@ /* @flow */ | ||
export class RestClient extends HTTPClient { | ||
request({ baseURL, ...rest }: HTTPRequestOptions): ZalgoPromise<{ ... }> { | ||
return callRestAPI({ | ||
url: baseURL ?? this.baseURL ?? "", | ||
accessToken: this.accessToken, | ||
...rest, | ||
}); | ||
} | ||
authRequest({ | ||
request({ | ||
baseURL, | ||
@@ -55,24 +48,6 @@ accessToken, | ||
}: HTTPRequestOptions): ZalgoPromise<{ ... }> { | ||
return request({ | ||
method: "post", | ||
return callRestAPI({ | ||
url: baseURL ?? this.baseURL ?? "", | ||
headers: { | ||
// $FlowIssue | ||
Authorization: `Basic ${accessToken}`, | ||
}, | ||
accessToken: accessToken ?? this.accessToken, | ||
...rest, | ||
}).then(({ body }) => { | ||
if (body && body.error === "invalid_client") { | ||
throw new Error( | ||
`Auth Api invalid client id: \n\n${JSON.stringify(body, null, 4)}` | ||
); | ||
} | ||
if (!body || !body.access_token) { | ||
throw new Error( | ||
`Auth Api response error:\n\n${JSON.stringify(body, null, 4)}` | ||
); | ||
} | ||
return body.access_token; | ||
}); | ||
@@ -79,0 +54,0 @@ } |
@@ -6,7 +6,6 @@ /* @flow */ | ||
import { type ZoidComponent } from "@krakenjs/zoid/src"; | ||
import { base64encode } from "@krakenjs/belter/src"; | ||
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src"; | ||
import { FPTI_KEY, CURRENCY } from "@paypal/sdk-constants/src"; | ||
import { PAYMENT_3DS_VERIFICATION, AUTH } from "../constants/api"; | ||
import { PAYMENT_3DS_VERIFICATION } from "../constants/api"; | ||
import { ValidationError } from "../lib"; | ||
@@ -16,3 +15,2 @@ | ||
requestData, | ||
responseBody, | ||
GqlResponse, | ||
@@ -23,3 +21,2 @@ MerchantPayloadData, | ||
TDSProps, | ||
Request, | ||
} from "./types"; | ||
@@ -106,30 +103,4 @@ import { getFastlaneThreeDS } from "./utils"; | ||
try { | ||
const basicAuth = base64encode(`${this.sdkConfig.clientID}:`); | ||
const authData = { | ||
grant_type: `client_credentials`, | ||
}; | ||
if (this.sdkConfig.merchantID?.length) { | ||
// $FlowFixMe invalid error on key assignment | ||
authData.target_subject = this.sdkConfig.merchantID[0]; | ||
} | ||
// $FlowFixMe | ||
const accessToken = await this.restClient.authRequest<Request, string>({ | ||
baseURL: `${this.sdkConfig.paypalApiDomain}${AUTH}`, | ||
accessToken: `${basicAuth}`, | ||
data: authData, | ||
}); | ||
// $FlowIssue confusing ZalgoPromise return type with resolved string value | ||
this.restClient.setAccessToken(accessToken); | ||
} catch (error) { | ||
this.logger.warn(error); | ||
throw error; | ||
} | ||
try { | ||
// $FlowFixMe | ||
const { status, links } = await this.restClient.request< | ||
requestData, | ||
responseBody | ||
>({ | ||
const { status, links } = await this.restClient.request({ | ||
method: "POST", | ||
@@ -136,0 +107,0 @@ baseURL: `${this.sdkConfig.paypalApiDomain}/${PAYMENT_3DS_VERIFICATION}`, |
@@ -48,3 +48,2 @@ /* @flow */ | ||
}), | ||
authRequest: vi.fn(), | ||
}; | ||
@@ -51,0 +50,0 @@ |
@@ -8,3 +8,2 @@ /* @flow */ | ||
getClientID, | ||
getMerchantID, | ||
} from "@paypal/sdk-client/src"; | ||
@@ -38,3 +37,3 @@ import { destroy as zoidDestroy } from "@krakenjs/zoid/src"; | ||
logger: getLogger(), | ||
restClient: new RestClient(), | ||
restClient: new RestClient({ accessToken: getSDKToken() }), | ||
graphQLClient: new GraphQLClient({ | ||
@@ -50,3 +49,2 @@ baseURL: | ||
clientID: getClientID(), | ||
merchantID: getMerchantID(), | ||
}, | ||
@@ -53,0 +51,0 @@ }); |
@@ -80,2 +80,3 @@ /* @flow */ | ||
currency: $Values<typeof CURRENCY>, | ||
amount: string, | ||
intent: $Values<typeof INTENT>, | ||
@@ -301,2 +302,8 @@ commit: boolean, | ||
amount: { | ||
type: "object", | ||
value: ({ props }) => props.parent.props.amount, | ||
required: false, | ||
}, | ||
onApprove: { | ||
@@ -644,2 +651,7 @@ type: "function", | ||
amount: { | ||
type: "object", | ||
required: false, | ||
}, | ||
onApprove: { | ||
@@ -646,0 +658,0 @@ type: "function", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1289122
19249
1