@paypal/react-paypal-js
Advanced tools
Comparing version 4.1.0 to 4.1.1
@@ -25,3 +25,3 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
/*! | ||
* paypal-js v2.1.6 (2021-02-07T22:00:24.387Z) | ||
* paypal-js v2.1.9 (2021-02-15T22:49:36.078Z) | ||
* Copyright 2020-present, PayPal, Inc. All rights reserved. | ||
@@ -73,3 +73,3 @@ * | ||
function processOptions(options) { | ||
var sdkBaseURL = 'https://www.paypal.com/sdk/js'; | ||
var sdkBaseURL = "https://www.paypal.com/sdk/js"; | ||
@@ -86,3 +86,3 @@ if (options.sdkBaseURL) { | ||
forEachObjectKey(options, function (key) { | ||
var keyType = key.substring(0, 5) === 'data-' ? 'dataAttributes' : 'queryParams'; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
var keyType = key.substring(0, 5) === "data-" ? "dataAttributes" : "queryParams"; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
@@ -100,6 +100,6 @@ processedOptions[keyType][key] = options[key].toString(); | ||
function objectToQueryString(params) { | ||
var queryString = ''; | ||
var queryString = ""; | ||
forEachObjectKey(params, function (key) { | ||
if (queryString.length !== 0) queryString += '&'; | ||
queryString += key + '=' + params[key]; | ||
if (queryString.length !== 0) queryString += "&"; | ||
queryString += key + "=" + params[key]; | ||
}); | ||
@@ -111,3 +111,3 @@ return queryString; | ||
var dataAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var newScript = document.createElement('script'); | ||
var newScript = document.createElement("script"); | ||
newScript.src = url; | ||
@@ -117,4 +117,4 @@ forEachObjectKey(dataAttributes, function (key) { | ||
if (key === 'data-csp-nonce') { | ||
newScript.setAttribute('nonce', dataAttributes['data-csp-nonce']); | ||
if (key === "data-csp-nonce") { | ||
newScript.setAttribute("nonce", dataAttributes["data-csp-nonce"]); | ||
} | ||
@@ -147,9 +147,9 @@ }); | ||
if (!(options instanceof Object)) { | ||
throw new Error('Invalid arguments. Expected an object to be passed into loadScript().'); | ||
throw new Error("Invalid arguments. Expected an object to be passed into loadScript()."); | ||
} | ||
if (typeof PromisePonyfill === 'undefined') { | ||
if (typeof PromisePonyfill === "undefined") { | ||
// default to using window.Promise as the Promise implementation | ||
if (typeof Promise === 'undefined') { | ||
throw new Error('Failed to load the PayPal JS SDK script because Promise is undefined. To resolve the issue, use a Promise polyfill.'); | ||
if (typeof Promise === "undefined") { | ||
throw new Error("Failed to load the PayPal JS SDK script because Promise is undefined. To resolve the issue, use a Promise polyfill."); | ||
} | ||
@@ -164,3 +164,3 @@ | ||
// resolve with null when running in Node | ||
if (typeof window === 'undefined') return resolve(null); | ||
if (typeof window === "undefined") return resolve(null); | ||
@@ -180,3 +180,3 @@ var _processOptions = processOptions(options), | ||
if (window.paypal) return resolve(window.paypal); | ||
return reject(new Error('The window.paypal global variable is not available.')); | ||
return reject(new Error("The window.paypal global variable is not available.")); | ||
}, | ||
@@ -183,0 +183,0 @@ onError: function onError() { |
@@ -12,3 +12,3 @@ 'use strict'; | ||
/*! | ||
* paypal-js v2.1.6 (2021-02-07T22:00:24.387Z) | ||
* paypal-js v2.1.9 (2021-02-15T22:49:36.078Z) | ||
* Copyright 2020-present, PayPal, Inc. All rights reserved. | ||
@@ -59,3 +59,3 @@ * | ||
function processOptions(options) { | ||
var sdkBaseURL = 'https://www.paypal.com/sdk/js'; | ||
var sdkBaseURL = "https://www.paypal.com/sdk/js"; | ||
@@ -72,3 +72,3 @@ if (options.sdkBaseURL) { | ||
forEachObjectKey(options, function (key) { | ||
var keyType = key.substring(0, 5) === 'data-' ? 'dataAttributes' : 'queryParams'; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
var keyType = key.substring(0, 5) === "data-" ? "dataAttributes" : "queryParams"; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
@@ -86,6 +86,6 @@ processedOptions[keyType][key] = options[key].toString(); | ||
function objectToQueryString(params) { | ||
var queryString = ''; | ||
var queryString = ""; | ||
forEachObjectKey(params, function (key) { | ||
if (queryString.length !== 0) queryString += '&'; | ||
queryString += key + '=' + params[key]; | ||
if (queryString.length !== 0) queryString += "&"; | ||
queryString += key + "=" + params[key]; | ||
}); | ||
@@ -97,3 +97,3 @@ return queryString; | ||
var dataAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var newScript = document.createElement('script'); | ||
var newScript = document.createElement("script"); | ||
newScript.src = url; | ||
@@ -103,4 +103,4 @@ forEachObjectKey(dataAttributes, function (key) { | ||
if (key === 'data-csp-nonce') { | ||
newScript.setAttribute('nonce', dataAttributes['data-csp-nonce']); | ||
if (key === "data-csp-nonce") { | ||
newScript.setAttribute("nonce", dataAttributes["data-csp-nonce"]); | ||
} | ||
@@ -133,9 +133,9 @@ }); | ||
if (!(options instanceof Object)) { | ||
throw new Error('Invalid arguments. Expected an object to be passed into loadScript().'); | ||
throw new Error("Invalid arguments. Expected an object to be passed into loadScript()."); | ||
} | ||
if (typeof PromisePonyfill === 'undefined') { | ||
if (typeof PromisePonyfill === "undefined") { | ||
// default to using window.Promise as the Promise implementation | ||
if (typeof Promise === 'undefined') { | ||
throw new Error('Failed to load the PayPal JS SDK script because Promise is undefined. To resolve the issue, use a Promise polyfill.'); | ||
if (typeof Promise === "undefined") { | ||
throw new Error("Failed to load the PayPal JS SDK script because Promise is undefined. To resolve the issue, use a Promise polyfill."); | ||
} | ||
@@ -150,3 +150,3 @@ | ||
// resolve with null when running in Node | ||
if (typeof window === 'undefined') return resolve(null); | ||
if (typeof window === "undefined") return resolve(null); | ||
@@ -166,3 +166,3 @@ var _processOptions = processOptions(options), | ||
if (window.paypal) return resolve(window.paypal); | ||
return reject(new Error('The window.paypal global variable is not available.')); | ||
return reject(new Error("The window.paypal global variable is not available.")); | ||
}, | ||
@@ -169,0 +169,0 @@ onError: function onError() { |
{ | ||
"name": "@paypal/react-paypal-js", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "React components for the PayPal JS SDK", | ||
@@ -42,24 +42,24 @@ "keywords": [ | ||
"dependencies": { | ||
"@paypal/paypal-js": "^2.1.6", | ||
"@paypal/paypal-js": "^2.1.9", | ||
"@paypal/sdk-constants": "^1.0.86" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@babel/preset-react": "^7.12.10", | ||
"@babel/preset-typescript": "^7.12.7", | ||
"@rollup/plugin-babel": "^5.2.3", | ||
"@rollup/plugin-node-resolve": "^11.1.1", | ||
"@babel/core": "^7.12.16", | ||
"@babel/preset-env": "^7.12.16", | ||
"@babel/preset-react": "^7.12.13", | ||
"@babel/preset-typescript": "^7.12.16", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"@rollup/plugin-replace": "^2.3.4", | ||
"@rollup/plugin-typescript": "^8.1.1", | ||
"@storybook/addon-actions": "^6.1.16", | ||
"@storybook/addon-essentials": "^6.1.16", | ||
"@storybook/addon-links": "^6.1.16", | ||
"@storybook/react": "^6.1.16", | ||
"@rollup/plugin-typescript": "^8.2.0", | ||
"@storybook/addon-actions": "^6.1.18", | ||
"@storybook/addon-essentials": "^6.1.18", | ||
"@storybook/addon-links": "^6.1.18", | ||
"@storybook/react": "^6.1.18", | ||
"@storybook/storybook-deployer": "^2.8.7", | ||
"@testing-library/react": "^11.2.5", | ||
"@types/react": "^17.0.0", | ||
"@types/react": "^17.0.2", | ||
"babel-jest": "^26.6.3", | ||
"babel-loader": "^8.2.2", | ||
"eslint": "^7.19.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
@@ -70,3 +70,3 @@ "eslint-plugin-react": "^7.22.0", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.3", | ||
"lint-staged": "^10.5.4", | ||
"prettier": "^2.2.1", | ||
@@ -76,5 +76,5 @@ "react": "^16.13.1", | ||
"react-is": "^17.0.1", | ||
"rollup": "^2.38.4", | ||
"rollup": "^2.39.0", | ||
"shelljs": "^0.8.4", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.1.5" | ||
}, | ||
@@ -81,0 +81,0 @@ "peerDependencies": { |
@@ -51,3 +51,3 @@ # react-paypal-js | ||
```js | ||
```jsx | ||
// App.js | ||
@@ -58,3 +58,3 @@ import { PayPalScriptProvider, PayPalButtons } from "@paypal/react-paypal-js"; | ||
return ( | ||
<PayPalScriptProvider options={{ "client-id": "sb" }}> | ||
<PayPalScriptProvider options={{ "client-id": "test" }}> | ||
<PayPalButtons style={{ layout: "horizontal" }} /> | ||
@@ -72,2 +72,18 @@ </PayPalScriptProvider> | ||
Use the PayPalScriptProvider `options` prop to configure the JS SDK. It accepts an object for passing query parameters and data attributes to the JS SDK script. | ||
```jsx | ||
const initialOptions = { | ||
"client-id": "test", | ||
currency: "USD", | ||
intent: "capture", | ||
"data-client-token": "abc123xyz==", | ||
}; | ||
<PayPalScriptProvider options={initialOptions}> | ||
<PayPalButtons /> | ||
</PayPalScriptProvider>; | ||
``` | ||
The [JS SDK Configuration guide](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-configuration/) contains the full list of query parameters and data attributes that can be used with the JS SDK. | ||
The `<PayPalScriptProvider />` component is designed to be used with the `usePayPalScriptReducer` hook for managing global state. This `usePayPalScriptReducer` hook has the same API as [React's useReducer hook](https://reactjs.org/docs/hooks-reference.html#usereducer). | ||
@@ -85,3 +101,3 @@ | ||
```js | ||
```jsx | ||
const [{ isPending }] = usePayPalScriptReducer(); | ||
@@ -103,3 +119,3 @@ | ||
```js | ||
```jsx | ||
const [{ scriptOptions }, dispatch] = usePayPalScriptReducer(); | ||
@@ -106,0 +122,0 @@ const [currency, setCurrency] = useState(scriptOptions.currency); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65798
146
Updated@paypal/paypal-js@^2.1.9