Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@paypal/react-paypal-js

Package Overview
Dependencies
Maintainers
36
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@paypal/react-paypal-js - npm Package Compare versions

Comparing version 7.4.0 to 7.4.1

6

CHANGELOG.md

@@ -5,2 +5,8 @@ # Changelog

### [7.4.1](https://github.com/paypal/react-paypal-js/compare/v7.4.0...v7.4.1) (2021-10-09)
### Bug Fixes
- **types:** rename back to DISPATCH_ACTION ([#192](https://github.com/paypal/react-paypal-js/issues/192)) ([2b8f14a](https://github.com/paypal/react-paypal-js/commit/2b8f14ad41a6be3f461fe73b9661c92bd012df2a))
## [7.4.0](https://github.com/paypal/react-paypal-js/compare/v7.3.3...v7.4.0) (2021-10-08)

@@ -7,0 +13,0 @@

28

dist/cjs/react-paypal-js.js
/*!
* react-paypal-js v7.4.0 (2021-10-08T14:28:13.235Z)
* react-paypal-js v7.4.1 (2021-10-09T12:33:33.981Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.

@@ -44,8 +44,8 @@ *

*/
exports.SCRIPT_PROVIDER_DISPATCH_ACTION = void 0;
(function (SCRIPT_PROVIDER_DISPATCH_ACTION) {
SCRIPT_PROVIDER_DISPATCH_ACTION["LOADING_STATUS"] = "setLoadingStatus";
SCRIPT_PROVIDER_DISPATCH_ACTION["RESET_OPTIONS"] = "resetOptions";
SCRIPT_PROVIDER_DISPATCH_ACTION["SET_BRAINTREE_INSTANCE"] = "braintreeInstance";
})(exports.SCRIPT_PROVIDER_DISPATCH_ACTION || (exports.SCRIPT_PROVIDER_DISPATCH_ACTION = {}));
exports.DISPATCH_ACTION = void 0;
(function (DISPATCH_ACTION) {
DISPATCH_ACTION["LOADING_STATUS"] = "setLoadingStatus";
DISPATCH_ACTION["RESET_OPTIONS"] = "resetOptions";
DISPATCH_ACTION["SET_BRAINTREE_INSTANCE"] = "braintreeInstance";
})(exports.DISPATCH_ACTION || (exports.DISPATCH_ACTION = {}));
/**

@@ -196,5 +196,5 @@ * Enum for all the available hosted fields

switch (action.type) {
case exports.SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS:
case exports.DISPATCH_ACTION.LOADING_STATUS:
return __assign(__assign({}, state), { loadingStatus: action.value });
case exports.SCRIPT_PROVIDER_DISPATCH_ACTION.RESET_OPTIONS:
case exports.DISPATCH_ACTION.RESET_OPTIONS:
// destroy existing script to make sure only one script loads at a time

@@ -205,3 +205,3 @@ destroySDKScript(state.options[SCRIPT_ID]);

return __assign(__assign({}, state), { loadingStatus: exports.SCRIPT_LOADING_STATE.PENDING, options: __assign(__assign({}, action.value), (_a = {}, _a[SCRIPT_ID] = "" + getScriptID(action.value), _a[DATA_SDK_INTEGRATION_SOURCE] = DATA_SDK_INTEGRATION_SOURCE_VALUE, _a)) });
case exports.SCRIPT_PROVIDER_DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:
case exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:
return __assign(__assign({}, state), { braintreePayPalCheckoutInstance: action.value });

@@ -681,3 +681,3 @@ default: {

dispatch({
type: exports.SCRIPT_PROVIDER_DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,
type: exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,
value: paypalCheckoutInstance,

@@ -844,3 +844,3 @@ });

return dispatch({
type: exports.SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,
type: exports.DISPATCH_ACTION.LOADING_STATUS,
value: exports.SCRIPT_LOADING_STATE.PENDING,

@@ -856,3 +856,3 @@ });

dispatch({
type: exports.SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,
type: exports.DISPATCH_ACTION.LOADING_STATUS,
value: exports.SCRIPT_LOADING_STATE.RESOLVED,

@@ -865,3 +865,3 @@ });

dispatch({
type: exports.SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,
type: exports.DISPATCH_ACTION.LOADING_STATUS,
value: exports.SCRIPT_LOADING_STATE.REJECTED,

@@ -868,0 +868,0 @@ });

/*!
* react-paypal-js v7.4.0 (2021-10-08T14:28:13.235Z)
* react-paypal-js v7.4.1 (2021-10-09T12:33:33.981Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.

@@ -17,2 +17,2 @@ *

*/
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r,n,o,a=t(e);exports.SCRIPT_LOADING_STATE=void 0,(r=exports.SCRIPT_LOADING_STATE||(exports.SCRIPT_LOADING_STATE={})).INITIAL="initial",r.PENDING="pending",r.REJECTED="rejected",r.RESOLVED="resolved",exports.SCRIPT_PROVIDER_DISPATCH_ACTION=void 0,(n=exports.SCRIPT_PROVIDER_DISPATCH_ACTION||(exports.SCRIPT_PROVIDER_DISPATCH_ACTION={})).LOADING_STATUS="setLoadingStatus",n.RESET_OPTIONS="resetOptions",n.SET_BRAINTREE_INSTANCE="braintreeInstance",exports.PAYPAL_HOSTED_FIELDS_TYPES=void 0,(o=exports.PAYPAL_HOSTED_FIELDS_TYPES||(exports.PAYPAL_HOSTED_FIELDS_TYPES={})).NUMBER="number",o.CVV="cvv",o.EXPIRATION_DATE="expirationDate",o.EXPIRATION_MONTH="expirationMonth",o.EXPIRATION_YEAR="expirationYear",o.POSTAL_CODE="postalCode";var i="data-react-paypal-script-id",s=function(){return(s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function u(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function c(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}function l(e){return void 0===e&&(e="paypal"),window[e]}function d(e){return"react-paypal-js-"+function(e){for(var t="",r=0;r<e.length;r++){var n=e[r].charCodeAt(0)*r;e[r+1]&&(n+=e[r+1].charCodeAt(0)*(r-1)),t+=String.fromCharCode(97+Math.abs(n)%26)}return t}(JSON.stringify(e))}function p(e){var t=self.document.querySelector("script["+i+'="'+e+'"]');(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function f(e,t){var r;switch(t.type){case exports.SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS:return s(s({},e),{loadingStatus:t.value});case exports.SCRIPT_PROVIDER_DISPATCH_ACTION.RESET_OPTIONS:return p(e.options[i]),delete t.value[i],s(s({},e),{loadingStatus:exports.SCRIPT_LOADING_STATE.PENDING,options:s(s({},t.value),(r={},r[i]=""+d(t.value),r["data-sdk-integration-source"]="react-paypal-js",r))});case exports.SCRIPT_PROVIDER_DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:return s(s({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var P=e.createContext(null);function E(e){if("function"==typeof(null==e?void 0:e.dispatch)&&0!==e.dispatch.length)return e;throw new Error("usePayPalScriptReducer must be used within a PayPalScriptProvider")}function S(){var t=E(e.useContext(P));return[s(s({},t),{isInitial:t.loadingStatus===exports.SCRIPT_LOADING_STATE.INITIAL,isPending:t.loadingStatus===exports.SCRIPT_LOADING_STATE.PENDING,isResolved:t.loadingStatus===exports.SCRIPT_LOADING_STATE.RESOLVED,isRejected:t.loadingStatus===exports.SCRIPT_LOADING_STATE.REJECTED}),t.dispatch]}function T(){var t=function(e){var t;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t["data-client-token"]))throw new Error("A client token wasn't found in the provider parent component");return e}(E(e.useContext(P)));return[t,t.dispatch]}var v=e.createContext(null);var I=function(t){var r=t.className,n=void 0===r?"":r,o=t.disabled,i=void 0!==o&&o,d=t.children,p=t.forceReRender,f=void 0===p?[]:p,P=u(t,["className","disabled","children","forceReRender"]),E=i?{opacity:.38}:{},T=(n+" "+(i?"paypal-buttons-disabled":"")).trim(),v=e.useRef(null),I=e.useRef(null),h=S()[0],A=h.isResolved,y=h.options,m=e.useState(null),R=m[0],_=m[1],O=e.useState(!0),N=O[0],C=O[1],b=e.useState(null)[1];function D(){null!==I.current&&I.current.close().catch((function(){}))}return e.useEffect((function(){if(!1===A)return D;var e=l(y["data-namespace"]);if(void 0===e||void 0===e.Buttons)return b((function(){throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e["data-namespace"],o="Unable to render <PayPalButtons /> because window."+(void 0===n?"paypal":n)+".Buttons is undefined.";if(r.length&&!r.includes("buttons")){o+="\nTo fix the issue, add 'buttons' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(r+",buttons")+"'}}>`."}return o}(y))})),D;try{I.current=e.Buttons(s(s({},P),{onInit:function(e,t){_(t),"function"==typeof P.onInit&&P.onInit(e,t)}}))}catch(e){return b((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: "+e)}))}return!1===I.current.isEligible()?(C(!1),D):v.current?(I.current.render(v.current).catch((function(e){null!==v.current&&0!==v.current.children.length&&b((function(){throw new Error("Failed to render <PayPalButtons /> component. "+e)}))})),D):D}),c(c([A],f,!0),[P.fundingSource],!1)),e.useEffect((function(){null!==R&&(!0===i?R.disable().catch((function(){})):R.enable().catch((function(){})))}),[i,R]),a.default.createElement(a.default.Fragment,null,N?a.default.createElement("div",{ref:v,style:E,className:T}):d)};function h(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL);var r=function(e,t){var r="",n="";Array.isArray(e)?e.length>1?(r="*",n=e.toString()):r=e.toString():"string"==typeof e&&e.length>0?r=e:"string"==typeof t&&t.length>0&&(r="*",n=t);return{"merchant-id":r,"data-merchant-id":n}}(e["merchant-id"],e["data-merchant-id"]),n=Object.assign({},e,r),o=Object.keys(n).filter((function(e){return void 0!==n[e]&&null!==n[e]&&""!==n[e]})).reduce((function(e,t){var r=n[t].toString();return"data-"===t.substring(0,5)?e.dataAttributes[t]=r:e.queryParams[t]=r,e}),{queryParams:{},dataAttributes:{}}),a=o.queryParams,i=o.dataAttributes;return{url:t+"?"+A(a),dataAttributes:i}}function A(e){var t="";return Object.keys(e).forEach((function(r){0!==t.length&&(t+="&"),t+=r+"="+e[r]})),t}function y(e,t){void 0===t&&(t={});var r=document.createElement("script");return r.src=e,Object.keys(t).forEach((function(e){r.setAttribute(e,t[e]),"data-csp-nonce"===e&&r.setAttribute("nonce",t["data-csp-nonce"])})),r}function m(e,t){if(void 0===t&&(t=_()),N(e,t),"undefined"==typeof window)return t.resolve(null);var r=h(e),n=r.url,o=r.dataAttributes,a=o["data-namespace"]||"paypal",i=O(a);return function(e,t){var r=document.querySelector('script[src="'+e+'"]');if(null===r)return null;var n=y(e,t),o=Object.assign({},r.dataset);if(delete o.uidAuto,Object.keys(o).length!==Object.keys(n.dataset).length)return null;var a=!0;return Object.keys(o).forEach((function(e){o[e]!==n.dataset[e]&&(a=!1)})),a?r:null}(n,o)&&i?t.resolve(i):R({url:n,attributes:o},t).then((function(){var e=O(a);if(e)return e;throw new Error("The window."+a+" global variable is not available.")}))}function R(e,t){void 0===t&&(t=_()),N(e,t);var r=e.url,n=e.attributes;if("string"!=typeof r||0===r.length)throw new Error("Invalid url.");if(void 0!==n&&"object"!=typeof n)throw new Error("Expected attributes to be an object.");return new t((function(e,t){if("undefined"==typeof window)return e();!function(e){var t=e.url,r=e.attributes,n=e.onSuccess,o=e.onError,a=y(t,r);a.onerror=o,a.onload=n,document.head.insertBefore(a,document.head.firstElementChild)}({url:r,attributes:n,onSuccess:function(){return e()},onError:function(){return t(new Error('The script "'+r+'" failed to load.'))}})}))}function _(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function O(e){return window[e]}function N(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}var C=function(e,t){return function(e,t){if("function"==typeof e.createOrder){var r=e.createOrder;e.createOrder=function(e,n){return r(e,s(s({},n),{braintree:t}))}}}(e,t),function(e,t){if("function"==typeof e.onApprove){var r=e.onApprove;e.onApprove=function(e,n){return r(e,s(s({},n),{braintree:t}))}}}(e,t),s({},e)};var b=function(e){return e.reduce((function(e,t){var r=t.props,n=r.hostedFieldType,o=r.options;return Object.values(exports.PAYPAL_HOSTED_FIELDS_TYPES).includes(n)&&(e[n]={selector:o.selector,placeholder:o.placeholder,type:o.type,formatInput:o.formatInput,maskInput:o.maskInput,select:o.select,maxlength:o.maxlength,minlength:o.minlength,prefill:o.prefill,rejectUnsupportedCards:o.rejectUnsupportedCards}),e}),{})},D=function(e){if(!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.NUMBER)||!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.CVV)||function(e){return!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.EXPIRATION_DATE)&&!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.EXPIRATION_MONTH)&&!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.EXPIRATION_YEAR)}(e))throw new Error("To use HostedFields you must use it with at least 3 children with types: [number, cvv, expirationDate] includes")},w=function(e){var t=function(e){return e.reduce((function(e,t){var r=t;return r.props.hostedFieldType&&e.push(r.props.hostedFieldType),e}),[])}(e);D(t),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(t)},g={PAYPAL:"paypal",VENMO:"venmo",APPLEPAY:"applepay",ITAU:"itau",CREDIT:"credit",PAYLATER:"paylater",CARD:"card",IDEAL:"ideal",SEPA:"sepa",BANCONTACT:"bancontact",GIROPAY:"giropay",SOFORT:"sofort",EPS:"eps",MYBANK:"mybank",P24:"p24",VERKKOPANKKI:"verkkopankki",PAYU:"payu",BLIK:"blik",TRUSTLY:"trustly",ZIMPLER:"zimpler",MAXIMA:"maxima",OXXO:"oxxo",BOLETO:"boleto",WECHATPAY:"wechatpay",MERCADOPAGO:"mercadopago"};exports.BraintreePayPalButtons=function(t){var r=t.className,n=void 0===r?"":r,o=t.disabled,i=void 0!==o&&o,c=t.children,l=t.forceReRender,d=void 0===l?[]:l,p=u(t,["className","disabled","children","forceReRender"]),f=e.useState(null)[1],P=T(),E=P[0],S=P[1];return e.useEffect((function(){Promise.all([R({url:"https://js.braintreegateway.com/web/3.81.0/js/client.min.js"}),R({url:"https://js.braintreegateway.com/web/3.81.0/js/paypal-checkout.min.js"})]).then((function(){var e,t=E.options["data-client-token"],r=(void 0===e&&(e="braintree"),window[e]);return r.client.create({authorization:t}).then((function(e){return r.paypalCheckout.create({client:e})})).then((function(e){S({type:exports.SCRIPT_PROVIDER_DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,value:e})}))})).catch((function(e){f((function(){throw new Error("An error occurred when loading the Braintree scripts: "+e)}))}))}),[E.options,S]),a.default.createElement(a.default.Fragment,null,E.braintreePayPalCheckoutInstance&&a.default.createElement(I,s({className:n,disabled:i,forceReRender:d},C(p,E.braintreePayPalCheckoutInstance)),c))},exports.FUNDING=g,exports.PayPalButtons=I,exports.PayPalHostedField=function(e){e.hostedFieldType,e.options;var t=u(e,["hostedFieldType","options"]);return a.default.createElement("div",s({},t))},exports.PayPalHostedFieldsProvider=function(t){var r=t.styles,n=t.createOrder,o=t.notEligibleError,i=t.children,s=e.Children.toArray(i),u=T()[0],c=u.options,d=u.loadingStatus,p=e.useState(!0),f=p[0],P=p[1],E=e.useState(null),S=E[0],I=E[1],h=e.useRef(null),A=e.useRef(),y=e.useState(null)[1];return e.useEffect((function(){w(s)}),[]),e.useEffect((function(){var e,t;if(d===exports.SCRIPT_LOADING_STATE.RESOLVED){if(A.current||(A.current=l(c["data-namespace"]).HostedFields,A.current||function(e){var t=e.components,r=void 0===t?"":t,n=e["data-namespace"],o=r?r+",hosted-fields":"hosted-fields",a="Unable to render <PayPalHostedFieldsProvider /> because window."+(void 0===n?"paypal":n)+".HostedFields is undefined.";throw r.includes("hosted-fields")||(a+="\nTo fix the issue, add 'hosted-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '"+o+"'}}>"),new Error(a)}(((e={components:c.components})["data-namespace"]=c["data-namespace"],e))),!(null===(t=null==A?void 0:A.current)||void 0===t?void 0:t.isEligible()))return P(!1);S&&S.teardown(),A.current.render({createOrder:n,styles:r,fields:b(s)}).then((function(e){I(e)})).catch((function(e){y((function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. "+e)}))}))}}),[d,r]),a.default.createElement("div",{ref:h},f?a.default.createElement(v.Provider,{value:S},i):o)},exports.PayPalMarks=function(t){var r=t.className,n=void 0===r?"":r,o=t.children,i=u(t,["className","children"]),c=S()[0],d=c.isResolved,p=c.options,f=e.useRef(null),P=e.useState(!0),E=P[0],T=P[1],v=e.useState(null)[1];return e.useEffect((function(){if(!1!==d){var e=l(p["data-namespace"]);void 0!==e&&void 0!==e.Marks?function(e){var t=f.current;if(!t||!e.isEligible())return T(!1);t.firstChild&&t.removeChild(t.firstChild),e.render(t).catch((function(e){null!==t&&0!==t.children.length&&v((function(){throw new Error("Failed to render <PayPalMarks /> component. "+e)}))}))}(e.Marks(s({},i))):v((function(){throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e["data-namespace"],o="Unable to render <PayPalMarks /> because window."+(void 0===n?"paypal":n)+".Marks is undefined.";if(!r.includes("marks")){o+="\nTo fix the issue, add 'marks' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(r?r+",marks":"marks")+"'}}>`."}return o}(p))}))}}),[d,i.fundingSource]),a.default.createElement(a.default.Fragment,null,E?a.default.createElement("div",{ref:f,className:n}):o)},exports.PayPalMessages=function(t){var r=t.className,n=void 0===r?"":r,o=t.forceReRender,i=void 0===o?[]:o,d=u(t,["className","forceReRender"]),p=S()[0],f=p.isResolved,P=p.options,E=e.useRef(null),T=e.useRef(null),v=e.useState(null)[1];return e.useEffect((function(){if(!1!==f){var e=l(P["data-namespace"]);void 0!==e&&void 0!==e.Messages?(T.current=e.Messages(s({},d)),null!==E.current&&T.current.render(E.current).catch((function(e){null!==E.current&&0!==E.current.children.length&&v((function(){throw new Error("Failed to render <PayPalMessages /> component. "+e)}))}))):v((function(){throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e["data-namespace"],o="Unable to render <PayPalMessages /> because window."+(void 0===n?"paypal":n)+".Messages is undefined.";if(!r.includes("messages")){o+="\nTo fix the issue, add 'messages' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(r?r+",messages":"messages")+"'}}>`."}return o}(P))}))}}),c([f],i,!0)),a.default.createElement("div",{ref:E,className:n})},exports.PayPalScriptProvider=function(t){var r,n=t.options,o=void 0===n?{"client-id":"test"}:n,u=t.children,c=t.deferLoading,l=void 0!==c&&c,p=e.useReducer(f,{options:s(s({},o),(r={},r[i]=""+d(o),r["data-sdk-integration-source"]="react-paypal-js",r)),loadingStatus:l?exports.SCRIPT_LOADING_STATE.INITIAL:exports.SCRIPT_LOADING_STATE.PENDING}),E=p[0],S=p[1];return e.useEffect((function(){if(!1===l&&E.loadingStatus===exports.SCRIPT_LOADING_STATE.INITIAL)return S({type:exports.SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.PENDING});if(E.loadingStatus===exports.SCRIPT_LOADING_STATE.PENDING){var e=!0;return m(E.options).then((function(){e&&S({type:exports.SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.RESOLVED})})).catch((function(){e&&S({type:exports.SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.REJECTED})})),function(){e=!1}}}),[E.options,l,E.loadingStatus]),a.default.createElement(P.Provider,{value:s(s({},E),{dispatch:S})},u)},exports.ScriptContext=P,exports.destroySDKScript=p,exports.getScriptID=d,exports.scriptReducer=f,exports.usePayPalHostedFields=function(){return e.useContext(v)},exports.usePayPalScriptReducer=S,exports.useScriptProviderContext=T;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r,n,o,a=t(e);exports.SCRIPT_LOADING_STATE=void 0,(r=exports.SCRIPT_LOADING_STATE||(exports.SCRIPT_LOADING_STATE={})).INITIAL="initial",r.PENDING="pending",r.REJECTED="rejected",r.RESOLVED="resolved",exports.DISPATCH_ACTION=void 0,(n=exports.DISPATCH_ACTION||(exports.DISPATCH_ACTION={})).LOADING_STATUS="setLoadingStatus",n.RESET_OPTIONS="resetOptions",n.SET_BRAINTREE_INSTANCE="braintreeInstance",exports.PAYPAL_HOSTED_FIELDS_TYPES=void 0,(o=exports.PAYPAL_HOSTED_FIELDS_TYPES||(exports.PAYPAL_HOSTED_FIELDS_TYPES={})).NUMBER="number",o.CVV="cvv",o.EXPIRATION_DATE="expirationDate",o.EXPIRATION_MONTH="expirationMonth",o.EXPIRATION_YEAR="expirationYear",o.POSTAL_CODE="postalCode";var i="data-react-paypal-script-id",s=function(){return(s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function u(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function c(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}function l(e){return void 0===e&&(e="paypal"),window[e]}function d(e){return"react-paypal-js-"+function(e){for(var t="",r=0;r<e.length;r++){var n=e[r].charCodeAt(0)*r;e[r+1]&&(n+=e[r+1].charCodeAt(0)*(r-1)),t+=String.fromCharCode(97+Math.abs(n)%26)}return t}(JSON.stringify(e))}function p(e){var t=self.document.querySelector("script["+i+'="'+e+'"]');(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function f(e,t){var r;switch(t.type){case exports.DISPATCH_ACTION.LOADING_STATUS:return s(s({},e),{loadingStatus:t.value});case exports.DISPATCH_ACTION.RESET_OPTIONS:return p(e.options[i]),delete t.value[i],s(s({},e),{loadingStatus:exports.SCRIPT_LOADING_STATE.PENDING,options:s(s({},t.value),(r={},r[i]=""+d(t.value),r["data-sdk-integration-source"]="react-paypal-js",r))});case exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:return s(s({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var P=e.createContext(null);function E(e){if("function"==typeof(null==e?void 0:e.dispatch)&&0!==e.dispatch.length)return e;throw new Error("usePayPalScriptReducer must be used within a PayPalScriptProvider")}function v(){var t=E(e.useContext(P));return[s(s({},t),{isInitial:t.loadingStatus===exports.SCRIPT_LOADING_STATE.INITIAL,isPending:t.loadingStatus===exports.SCRIPT_LOADING_STATE.PENDING,isResolved:t.loadingStatus===exports.SCRIPT_LOADING_STATE.RESOLVED,isRejected:t.loadingStatus===exports.SCRIPT_LOADING_STATE.REJECTED}),t.dispatch]}function S(){var t=function(e){var t;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t["data-client-token"]))throw new Error("A client token wasn't found in the provider parent component");return e}(E(e.useContext(P)));return[t,t.dispatch]}var T=e.createContext(null);var h=function(t){var r=t.className,n=void 0===r?"":r,o=t.disabled,i=void 0!==o&&o,d=t.children,p=t.forceReRender,f=void 0===p?[]:p,P=u(t,["className","disabled","children","forceReRender"]),E=i?{opacity:.38}:{},S=(n+" "+(i?"paypal-buttons-disabled":"")).trim(),T=e.useRef(null),h=e.useRef(null),A=v()[0],I=A.isResolved,y=A.options,m=e.useState(null),O=m[0],_=m[1],N=e.useState(!0),b=N[0],R=N[1],w=e.useState(null)[1];function g(){null!==h.current&&h.current.close().catch((function(){}))}return e.useEffect((function(){if(!1===I)return g;var e=l(y["data-namespace"]);if(void 0===e||void 0===e.Buttons)return w((function(){throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e["data-namespace"],o="Unable to render <PayPalButtons /> because window."+(void 0===n?"paypal":n)+".Buttons is undefined.";if(r.length&&!r.includes("buttons")){o+="\nTo fix the issue, add 'buttons' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(r+",buttons")+"'}}>`."}return o}(y))})),g;try{h.current=e.Buttons(s(s({},P),{onInit:function(e,t){_(t),"function"==typeof P.onInit&&P.onInit(e,t)}}))}catch(e){return w((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: "+e)}))}return!1===h.current.isEligible()?(R(!1),g):T.current?(h.current.render(T.current).catch((function(e){null!==T.current&&0!==T.current.children.length&&w((function(){throw new Error("Failed to render <PayPalButtons /> component. "+e)}))})),g):g}),c(c([I],f,!0),[P.fundingSource],!1)),e.useEffect((function(){null!==O&&(!0===i?O.disable().catch((function(){})):O.enable().catch((function(){})))}),[i,O]),a.default.createElement(a.default.Fragment,null,b?a.default.createElement("div",{ref:T,style:E,className:S}):d)};function A(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL);var r=function(e,t){var r="",n="";Array.isArray(e)?e.length>1?(r="*",n=e.toString()):r=e.toString():"string"==typeof e&&e.length>0?r=e:"string"==typeof t&&t.length>0&&(r="*",n=t);return{"merchant-id":r,"data-merchant-id":n}}(e["merchant-id"],e["data-merchant-id"]),n=Object.assign({},e,r),o=Object.keys(n).filter((function(e){return void 0!==n[e]&&null!==n[e]&&""!==n[e]})).reduce((function(e,t){var r=n[t].toString();return"data-"===t.substring(0,5)?e.dataAttributes[t]=r:e.queryParams[t]=r,e}),{queryParams:{},dataAttributes:{}}),a=o.queryParams,i=o.dataAttributes;return{url:t+"?"+I(a),dataAttributes:i}}function I(e){var t="";return Object.keys(e).forEach((function(r){0!==t.length&&(t+="&"),t+=r+"="+e[r]})),t}function y(e,t){void 0===t&&(t={});var r=document.createElement("script");return r.src=e,Object.keys(t).forEach((function(e){r.setAttribute(e,t[e]),"data-csp-nonce"===e&&r.setAttribute("nonce",t["data-csp-nonce"])})),r}function m(e,t){if(void 0===t&&(t=_()),b(e,t),"undefined"==typeof window)return t.resolve(null);var r=A(e),n=r.url,o=r.dataAttributes,a=o["data-namespace"]||"paypal",i=N(a);return function(e,t){var r=document.querySelector('script[src="'+e+'"]');if(null===r)return null;var n=y(e,t),o=Object.assign({},r.dataset);if(delete o.uidAuto,Object.keys(o).length!==Object.keys(n.dataset).length)return null;var a=!0;return Object.keys(o).forEach((function(e){o[e]!==n.dataset[e]&&(a=!1)})),a?r:null}(n,o)&&i?t.resolve(i):O({url:n,attributes:o},t).then((function(){var e=N(a);if(e)return e;throw new Error("The window."+a+" global variable is not available.")}))}function O(e,t){void 0===t&&(t=_()),b(e,t);var r=e.url,n=e.attributes;if("string"!=typeof r||0===r.length)throw new Error("Invalid url.");if(void 0!==n&&"object"!=typeof n)throw new Error("Expected attributes to be an object.");return new t((function(e,t){if("undefined"==typeof window)return e();!function(e){var t=e.url,r=e.attributes,n=e.onSuccess,o=e.onError,a=y(t,r);a.onerror=o,a.onload=n,document.head.insertBefore(a,document.head.firstElementChild)}({url:r,attributes:n,onSuccess:function(){return e()},onError:function(){return t(new Error('The script "'+r+'" failed to load.'))}})}))}function _(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function N(e){return window[e]}function b(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}var R=function(e,t){return function(e,t){if("function"==typeof e.createOrder){var r=e.createOrder;e.createOrder=function(e,n){return r(e,s(s({},n),{braintree:t}))}}}(e,t),function(e,t){if("function"==typeof e.onApprove){var r=e.onApprove;e.onApprove=function(e,n){return r(e,s(s({},n),{braintree:t}))}}}(e,t),s({},e)};var w=function(e){return e.reduce((function(e,t){var r=t.props,n=r.hostedFieldType,o=r.options;return Object.values(exports.PAYPAL_HOSTED_FIELDS_TYPES).includes(n)&&(e[n]={selector:o.selector,placeholder:o.placeholder,type:o.type,formatInput:o.formatInput,maskInput:o.maskInput,select:o.select,maxlength:o.maxlength,minlength:o.minlength,prefill:o.prefill,rejectUnsupportedCards:o.rejectUnsupportedCards}),e}),{})},g=function(e){if(!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.NUMBER)||!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.CVV)||function(e){return!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.EXPIRATION_DATE)&&!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.EXPIRATION_MONTH)&&!e.includes(exports.PAYPAL_HOSTED_FIELDS_TYPES.EXPIRATION_YEAR)}(e))throw new Error("To use HostedFields you must use it with at least 3 children with types: [number, cvv, expirationDate] includes")},x=function(e){var t=function(e){return e.reduce((function(e,t){var r=t;return r.props.hostedFieldType&&e.push(r.props.hostedFieldType),e}),[])}(e);g(t),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(t)},C={PAYPAL:"paypal",VENMO:"venmo",APPLEPAY:"applepay",ITAU:"itau",CREDIT:"credit",PAYLATER:"paylater",CARD:"card",IDEAL:"ideal",SEPA:"sepa",BANCONTACT:"bancontact",GIROPAY:"giropay",SOFORT:"sofort",EPS:"eps",MYBANK:"mybank",P24:"p24",VERKKOPANKKI:"verkkopankki",PAYU:"payu",BLIK:"blik",TRUSTLY:"trustly",ZIMPLER:"zimpler",MAXIMA:"maxima",OXXO:"oxxo",BOLETO:"boleto",WECHATPAY:"wechatpay",MERCADOPAGO:"mercadopago"};exports.BraintreePayPalButtons=function(t){var r=t.className,n=void 0===r?"":r,o=t.disabled,i=void 0!==o&&o,c=t.children,l=t.forceReRender,d=void 0===l?[]:l,p=u(t,["className","disabled","children","forceReRender"]),f=e.useState(null)[1],P=S(),E=P[0],v=P[1];return e.useEffect((function(){Promise.all([O({url:"https://js.braintreegateway.com/web/3.81.0/js/client.min.js"}),O({url:"https://js.braintreegateway.com/web/3.81.0/js/paypal-checkout.min.js"})]).then((function(){var e,t=E.options["data-client-token"],r=(void 0===e&&(e="braintree"),window[e]);return r.client.create({authorization:t}).then((function(e){return r.paypalCheckout.create({client:e})})).then((function(e){v({type:exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,value:e})}))})).catch((function(e){f((function(){throw new Error("An error occurred when loading the Braintree scripts: "+e)}))}))}),[E.options,v]),a.default.createElement(a.default.Fragment,null,E.braintreePayPalCheckoutInstance&&a.default.createElement(h,s({className:n,disabled:i,forceReRender:d},R(p,E.braintreePayPalCheckoutInstance)),c))},exports.FUNDING=C,exports.PayPalButtons=h,exports.PayPalHostedField=function(e){e.hostedFieldType,e.options;var t=u(e,["hostedFieldType","options"]);return a.default.createElement("div",s({},t))},exports.PayPalHostedFieldsProvider=function(t){var r=t.styles,n=t.createOrder,o=t.notEligibleError,i=t.children,s=e.Children.toArray(i),u=S()[0],c=u.options,d=u.loadingStatus,p=e.useState(!0),f=p[0],P=p[1],E=e.useState(null),v=E[0],h=E[1],A=e.useRef(null),I=e.useRef(),y=e.useState(null)[1];return e.useEffect((function(){x(s)}),[]),e.useEffect((function(){var e,t;if(d===exports.SCRIPT_LOADING_STATE.RESOLVED){if(I.current||(I.current=l(c["data-namespace"]).HostedFields,I.current||function(e){var t=e.components,r=void 0===t?"":t,n=e["data-namespace"],o=r?r+",hosted-fields":"hosted-fields",a="Unable to render <PayPalHostedFieldsProvider /> because window."+(void 0===n?"paypal":n)+".HostedFields is undefined.";throw r.includes("hosted-fields")||(a+="\nTo fix the issue, add 'hosted-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '"+o+"'}}>"),new Error(a)}(((e={components:c.components})["data-namespace"]=c["data-namespace"],e))),!(null===(t=null==I?void 0:I.current)||void 0===t?void 0:t.isEligible()))return P(!1);v&&v.teardown(),I.current.render({createOrder:n,styles:r,fields:w(s)}).then((function(e){h(e)})).catch((function(e){y((function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. "+e)}))}))}}),[d,r]),a.default.createElement("div",{ref:A},f?a.default.createElement(T.Provider,{value:v},i):o)},exports.PayPalMarks=function(t){var r=t.className,n=void 0===r?"":r,o=t.children,i=u(t,["className","children"]),c=v()[0],d=c.isResolved,p=c.options,f=e.useRef(null),P=e.useState(!0),E=P[0],S=P[1],T=e.useState(null)[1];return e.useEffect((function(){if(!1!==d){var e=l(p["data-namespace"]);void 0!==e&&void 0!==e.Marks?function(e){var t=f.current;if(!t||!e.isEligible())return S(!1);t.firstChild&&t.removeChild(t.firstChild),e.render(t).catch((function(e){null!==t&&0!==t.children.length&&T((function(){throw new Error("Failed to render <PayPalMarks /> component. "+e)}))}))}(e.Marks(s({},i))):T((function(){throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e["data-namespace"],o="Unable to render <PayPalMarks /> because window."+(void 0===n?"paypal":n)+".Marks is undefined.";if(!r.includes("marks")){o+="\nTo fix the issue, add 'marks' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(r?r+",marks":"marks")+"'}}>`."}return o}(p))}))}}),[d,i.fundingSource]),a.default.createElement(a.default.Fragment,null,E?a.default.createElement("div",{ref:f,className:n}):o)},exports.PayPalMessages=function(t){var r=t.className,n=void 0===r?"":r,o=t.forceReRender,i=void 0===o?[]:o,d=u(t,["className","forceReRender"]),p=v()[0],f=p.isResolved,P=p.options,E=e.useRef(null),S=e.useRef(null),T=e.useState(null)[1];return e.useEffect((function(){if(!1!==f){var e=l(P["data-namespace"]);void 0!==e&&void 0!==e.Messages?(S.current=e.Messages(s({},d)),null!==E.current&&S.current.render(E.current).catch((function(e){null!==E.current&&0!==E.current.children.length&&T((function(){throw new Error("Failed to render <PayPalMessages /> component. "+e)}))}))):T((function(){throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e["data-namespace"],o="Unable to render <PayPalMessages /> because window."+(void 0===n?"paypal":n)+".Messages is undefined.";if(!r.includes("messages")){o+="\nTo fix the issue, add 'messages' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(r?r+",messages":"messages")+"'}}>`."}return o}(P))}))}}),c([f],i,!0)),a.default.createElement("div",{ref:E,className:n})},exports.PayPalScriptProvider=function(t){var r,n=t.options,o=void 0===n?{"client-id":"test"}:n,u=t.children,c=t.deferLoading,l=void 0!==c&&c,p=e.useReducer(f,{options:s(s({},o),(r={},r[i]=""+d(o),r["data-sdk-integration-source"]="react-paypal-js",r)),loadingStatus:l?exports.SCRIPT_LOADING_STATE.INITIAL:exports.SCRIPT_LOADING_STATE.PENDING}),E=p[0],v=p[1];return e.useEffect((function(){if(!1===l&&E.loadingStatus===exports.SCRIPT_LOADING_STATE.INITIAL)return v({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.PENDING});if(E.loadingStatus===exports.SCRIPT_LOADING_STATE.PENDING){var e=!0;return m(E.options).then((function(){e&&v({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.RESOLVED})})).catch((function(){e&&v({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.REJECTED})})),function(){e=!1}}}),[E.options,l,E.loadingStatus]),a.default.createElement(P.Provider,{value:s(s({},E),{dispatch:v})},u)},exports.ScriptContext=P,exports.destroySDKScript=p,exports.getScriptID=d,exports.scriptReducer=f,exports.usePayPalHostedFields=function(){return e.useContext(T)},exports.usePayPalScriptReducer=v,exports.useScriptProviderContext=S;
/*!
* react-paypal-js v7.4.0 (2021-10-08T14:28:13.235Z)
* react-paypal-js v7.4.1 (2021-10-09T12:33:33.981Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.

@@ -39,9 +39,9 @@ *

var SCRIPT_PROVIDER_DISPATCH_ACTION;
var DISPATCH_ACTION;
(function (SCRIPT_PROVIDER_DISPATCH_ACTION) {
SCRIPT_PROVIDER_DISPATCH_ACTION["LOADING_STATUS"] = "setLoadingStatus";
SCRIPT_PROVIDER_DISPATCH_ACTION["RESET_OPTIONS"] = "resetOptions";
SCRIPT_PROVIDER_DISPATCH_ACTION["SET_BRAINTREE_INSTANCE"] = "braintreeInstance";
})(SCRIPT_PROVIDER_DISPATCH_ACTION || (SCRIPT_PROVIDER_DISPATCH_ACTION = {}));
(function (DISPATCH_ACTION) {
DISPATCH_ACTION["LOADING_STATUS"] = "setLoadingStatus";
DISPATCH_ACTION["RESET_OPTIONS"] = "resetOptions";
DISPATCH_ACTION["SET_BRAINTREE_INSTANCE"] = "braintreeInstance";
})(DISPATCH_ACTION || (DISPATCH_ACTION = {}));
/**

@@ -227,3 +227,3 @@ * Enum for all the available hosted fields

switch (action.type) {
case SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS:
case DISPATCH_ACTION.LOADING_STATUS:
return __assign(__assign({}, state), {

@@ -233,3 +233,3 @@ loadingStatus: action.value

case SCRIPT_PROVIDER_DISPATCH_ACTION.RESET_OPTIONS:
case DISPATCH_ACTION.RESET_OPTIONS:
// destroy existing script to make sure only one script loads at a time

@@ -244,3 +244,3 @@ destroySDKScript(state.options[SCRIPT_ID]); // exclude the old data-react-paypal-script-id value from the hash generated by getScriptID()

case SCRIPT_PROVIDER_DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:
case DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:
return __assign(__assign({}, state), {

@@ -824,3 +824,3 @@ braintreePayPalCheckoutInstance: action.value

dispatch({
type: SCRIPT_PROVIDER_DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,
type: DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,
value: paypalCheckoutInstance

@@ -1036,3 +1036,3 @@ });

return dispatch({
type: SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,
type: DISPATCH_ACTION.LOADING_STATUS,
value: SCRIPT_LOADING_STATE.PENDING

@@ -1047,3 +1047,3 @@ });

dispatch({
type: SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,
type: DISPATCH_ACTION.LOADING_STATUS,
value: SCRIPT_LOADING_STATE.RESOLVED

@@ -1055,3 +1055,3 @@ });

dispatch({
type: SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS,
type: DISPATCH_ACTION.LOADING_STATUS,
value: SCRIPT_LOADING_STATE.REJECTED

@@ -1402,2 +1402,2 @@ });

var FUNDING = FUNDING$1;
export { BraintreePayPalButtons, FUNDING, PAYPAL_HOSTED_FIELDS_TYPES, PayPalButtons, PayPalHostedField, PayPalHostedFieldsProvider, PayPalMarks, PayPalMessages, PayPalScriptProvider, SCRIPT_LOADING_STATE, SCRIPT_PROVIDER_DISPATCH_ACTION, ScriptContext, destroySDKScript, getScriptID, scriptReducer, usePayPalHostedFields, usePayPalScriptReducer, useScriptProviderContext };
export { BraintreePayPalButtons, DISPATCH_ACTION, FUNDING, PAYPAL_HOSTED_FIELDS_TYPES, PayPalButtons, PayPalHostedField, PayPalHostedFieldsProvider, PayPalMarks, PayPalMessages, PayPalScriptProvider, SCRIPT_LOADING_STATE, ScriptContext, destroySDKScript, getScriptID, scriptReducer, usePayPalHostedFields, usePayPalScriptReducer, useScriptProviderContext };
/*!
* react-paypal-js v7.4.0 (2021-10-08T14:28:13.235Z)
* react-paypal-js v7.4.1 (2021-10-09T12:33:33.981Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.

@@ -17,2 +17,2 @@ *

*/
import e,{createContext as t,useContext as n,useRef as r,useState as o,useEffect as a,useReducer as i,Children as c}from"react";var s,u,l;!function(e){e.INITIAL="initial",e.PENDING="pending",e.REJECTED="rejected",e.RESOLVED="resolved"}(s||(s={})),function(e){e.LOADING_STATUS="setLoadingStatus",e.RESET_OPTIONS="resetOptions",e.SET_BRAINTREE_INSTANCE="braintreeInstance"}(u||(u={})),function(e){e.NUMBER="number",e.CVV="cvv",e.EXPIRATION_DATE="expirationDate",e.EXPIRATION_MONTH="expirationMonth",e.EXPIRATION_YEAR="expirationYear",e.POSTAL_CODE="postalCode"}(l||(l={}));var d="data-react-paypal-script-id",p=function(){return(p=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function f(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function v(e,t,n){if(n||2===arguments.length)for(var r,o=0,a=t.length;o<a;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function h(e){return void 0===e&&(e="paypal"),window[e]}function m(e){return"react-paypal-js-"+function(e){for(var t="",n=0;n<e.length;n++){var r=e[n].charCodeAt(0)*n;e[n+1]&&(r+=e[n+1].charCodeAt(0)*(n-1)),t+=String.fromCharCode(97+Math.abs(r)%26)}return t}(JSON.stringify(e))}function E(e){var t=self.document.querySelector("script["+d+'="'+e+'"]');(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function y(e,t){var n;switch(t.type){case u.LOADING_STATUS:return p(p({},e),{loadingStatus:t.value});case u.RESET_OPTIONS:return E(e.options[d]),delete t.value[d],p(p({},e),{loadingStatus:s.PENDING,options:p(p({},t.value),(n={},n[d]=""+m(t.value),n["data-sdk-integration-source"]="react-paypal-js",n))});case u.SET_BRAINTREE_INSTANCE:return p(p({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var P=t(null);function b(e){if("function"==typeof(null==e?void 0:e.dispatch)&&0!==e.dispatch.length)return e;throw new Error("usePayPalScriptReducer must be used within a PayPalScriptProvider")}function w(){var e=b(n(P));return[p(p({},e),{isInitial:e.loadingStatus===s.INITIAL,isPending:e.loadingStatus===s.PENDING,isResolved:e.loadingStatus===s.RESOLVED,isRejected:e.loadingStatus===s.REJECTED}),e.dispatch]}function g(){var e=function(e){var t;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t["data-client-token"]))throw new Error("A client token wasn't found in the provider parent component");return e}(b(n(P)));return[e,e.dispatch]}var A=t(null);function I(){return n(A)}var S=function(t){var n=t.className,i=void 0===n?"":n,c=t.disabled,s=void 0!==c&&c,u=t.children,l=t.forceReRender,d=void 0===l?[]:l,m=f(t,["className","disabled","children","forceReRender"]),E=s?{opacity:.38}:{},y=(i+" "+(s?"paypal-buttons-disabled":"")).trim(),P=r(null),b=r(null),g=w()[0],A=g.isResolved,I=g.options,S=o(null),T=S[0],O=S[1],N=o(!0),R=N[0],k=N[1],j=o(null)[1];function C(){null!==b.current&&b.current.close().catch((function(){}))}return a((function(){if(!1===A)return C;var e=h(I["data-namespace"]);if(void 0===e||void 0===e.Buttons)return j((function(){throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e["data-namespace"],o="Unable to render <PayPalButtons /> because window."+(void 0===r?"paypal":r)+".Buttons is undefined.";if(n.length&&!n.includes("buttons")){o+="\nTo fix the issue, add 'buttons' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(n+",buttons")+"'}}>`."}return o}(I))})),C;try{b.current=e.Buttons(p(p({},m),{onInit:function(e,t){O(t),"function"==typeof m.onInit&&m.onInit(e,t)}}))}catch(e){return j((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: "+e)}))}return!1===b.current.isEligible()?(k(!1),C):P.current?(b.current.render(P.current).catch((function(e){null!==P.current&&0!==P.current.children.length&&j((function(){throw new Error("Failed to render <PayPalButtons /> component. "+e)}))})),C):C}),v(v([A],d,!0),[m.fundingSource],!1)),a((function(){null!==T&&(!0===s?T.disable().catch((function(){})):T.enable().catch((function(){})))}),[s,T]),e.createElement(e.Fragment,null,R?e.createElement("div",{ref:P,style:E,className:y}):u)};function T(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL);var n=function(e,t){var n="",r="";Array.isArray(e)?e.length>1?(n="*",r=e.toString()):n=e.toString():"string"==typeof e&&e.length>0?n=e:"string"==typeof t&&t.length>0&&(n="*",r=t);return{"merchant-id":n,"data-merchant-id":r}}(e["merchant-id"],e["data-merchant-id"]),r=Object.assign({},e,n),o=Object.keys(r).filter((function(e){return void 0!==r[e]&&null!==r[e]&&""!==r[e]})).reduce((function(e,t){var n=r[t].toString();return"data-"===t.substring(0,5)?e.dataAttributes[t]=n:e.queryParams[t]=n,e}),{queryParams:{},dataAttributes:{}}),a=o.queryParams,i=o.dataAttributes;return{url:t+"?"+O(a),dataAttributes:i}}function O(e){var t="";return Object.keys(e).forEach((function(n){0!==t.length&&(t+="&"),t+=n+"="+e[n]})),t}function N(e,t){void 0===t&&(t={});var n=document.createElement("script");return n.src=e,Object.keys(t).forEach((function(e){n.setAttribute(e,t[e]),"data-csp-nonce"===e&&n.setAttribute("nonce",t["data-csp-nonce"])})),n}function R(e,t){if(void 0===t&&(t=j()),D(e,t),"undefined"==typeof window)return t.resolve(null);var n=T(e),r=n.url,o=n.dataAttributes,a=o["data-namespace"]||"paypal",i=C(a);return function(e,t){var n=document.querySelector('script[src="'+e+'"]');if(null===n)return null;var r=N(e,t),o=Object.assign({},n.dataset);if(delete o.uidAuto,Object.keys(o).length!==Object.keys(r.dataset).length)return null;var a=!0;return Object.keys(o).forEach((function(e){o[e]!==r.dataset[e]&&(a=!1)})),a?n:null}(r,o)&&i?t.resolve(i):k({url:r,attributes:o},t).then((function(){var e=C(a);if(e)return e;throw new Error("The window."+a+" global variable is not available.")}))}function k(e,t){void 0===t&&(t=j()),D(e,t);var n=e.url,r=e.attributes;if("string"!=typeof n||0===n.length)throw new Error("Invalid url.");if(void 0!==r&&"object"!=typeof r)throw new Error("Expected attributes to be an object.");return new t((function(e,t){if("undefined"==typeof window)return e();!function(e){var t=e.url,n=e.attributes,r=e.onSuccess,o=e.onError,a=N(t,n);a.onerror=o,a.onload=r,document.head.insertBefore(a,document.head.firstElementChild)}({url:n,attributes:r,onSuccess:function(){return e()},onError:function(){return t(new Error('The script "'+n+'" failed to load.'))}})}))}function j(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function C(e){return window[e]}function D(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}var L=function(e,t){return function(e,t){if("function"==typeof e.createOrder){var n=e.createOrder;e.createOrder=function(e,r){return n(e,p(p({},r),{braintree:t}))}}}(e,t),function(e,t){if("function"==typeof e.onApprove){var n=e.onApprove;e.onApprove=function(e,r){return n(e,p(p({},r),{braintree:t}))}}}(e,t),p({},e)},M=function(t){var n=t.className,r=void 0===n?"":n,i=t.disabled,c=void 0!==i&&i,s=t.children,l=t.forceReRender,d=void 0===l?[]:l,v=f(t,["className","disabled","children","forceReRender"]),h=o(null)[1],m=g(),E=m[0],y=m[1];return a((function(){Promise.all([k({url:"https://js.braintreegateway.com/web/3.81.0/js/client.min.js"}),k({url:"https://js.braintreegateway.com/web/3.81.0/js/paypal-checkout.min.js"})]).then((function(){var e,t=E.options["data-client-token"],n=(void 0===e&&(e="braintree"),window[e]);return n.client.create({authorization:t}).then((function(e){return n.paypalCheckout.create({client:e})})).then((function(e){y({type:u.SET_BRAINTREE_INSTANCE,value:e})}))})).catch((function(e){h((function(){throw new Error("An error occurred when loading the Braintree scripts: "+e)}))}))}),[E.options,y]),e.createElement(e.Fragment,null,E.braintreePayPalCheckoutInstance&&e.createElement(S,p({className:r,disabled:c,forceReRender:d},L(v,E.braintreePayPalCheckoutInstance)),s))},F=function(t){var n=t.className,i=void 0===n?"":n,c=t.children,s=f(t,["className","children"]),u=w()[0],l=u.isResolved,d=u.options,v=r(null),m=o(!0),E=m[0],y=m[1],P=o(null)[1];return a((function(){if(!1!==l){var e=h(d["data-namespace"]);void 0!==e&&void 0!==e.Marks?function(e){var t=v.current;if(!t||!e.isEligible())return y(!1);t.firstChild&&t.removeChild(t.firstChild),e.render(t).catch((function(e){null!==t&&0!==t.children.length&&P((function(){throw new Error("Failed to render <PayPalMarks /> component. "+e)}))}))}(e.Marks(p({},s))):P((function(){throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e["data-namespace"],o="Unable to render <PayPalMarks /> because window."+(void 0===r?"paypal":r)+".Marks is undefined.";if(!n.includes("marks")){o+="\nTo fix the issue, add 'marks' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(n?n+",marks":"marks")+"'}}>`."}return o}(d))}))}}),[l,s.fundingSource]),e.createElement(e.Fragment,null,E?e.createElement("div",{ref:v,className:i}):c)};var B=function(t){var n=t.className,i=void 0===n?"":n,c=t.forceReRender,s=void 0===c?[]:c,u=f(t,["className","forceReRender"]),l=w()[0],d=l.isResolved,m=l.options,E=r(null),y=r(null),P=o(null)[1];return a((function(){if(!1!==d){var e=h(m["data-namespace"]);void 0!==e&&void 0!==e.Messages?(y.current=e.Messages(p({},u)),null!==E.current&&y.current.render(E.current).catch((function(e){null!==E.current&&0!==E.current.children.length&&P((function(){throw new Error("Failed to render <PayPalMessages /> component. "+e)}))}))):P((function(){throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e["data-namespace"],o="Unable to render <PayPalMessages /> because window."+(void 0===r?"paypal":r)+".Messages is undefined.";if(!n.includes("messages")){o+="\nTo fix the issue, add 'messages' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(n?n+",messages":"messages")+"'}}>`."}return o}(m))}))}}),v([d],s,!0)),e.createElement("div",{ref:E,className:i})};var _=function(t){var n,r=t.options,o=void 0===r?{"client-id":"test"}:r,c=t.children,l=t.deferLoading,f=void 0!==l&&l,v=i(y,{options:p(p({},o),(n={},n[d]=""+m(o),n["data-sdk-integration-source"]="react-paypal-js",n)),loadingStatus:f?s.INITIAL:s.PENDING}),h=v[0],E=v[1];return a((function(){if(!1===f&&h.loadingStatus===s.INITIAL)return E({type:u.LOADING_STATUS,value:s.PENDING});if(h.loadingStatus===s.PENDING){var e=!0;return R(h.options).then((function(){e&&E({type:u.LOADING_STATUS,value:s.RESOLVED})})).catch((function(){e&&E({type:u.LOADING_STATUS,value:s.REJECTED})})),function(){e=!1}}}),[h.options,f,h.loadingStatus]),e.createElement(P.Provider,{value:p(p({},h),{dispatch:E})},c)},x=function(e){return e.reduce((function(e,t){var n=t.props,r=n.hostedFieldType,o=n.options;return Object.values(l).includes(r)&&(e[r]={selector:o.selector,placeholder:o.placeholder,type:o.type,formatInput:o.formatInput,maskInput:o.maskInput,select:o.select,maxlength:o.maxlength,minlength:o.minlength,prefill:o.prefill,rejectUnsupportedCards:o.rejectUnsupportedCards}),e}),{})},U=function(e){if(!e.includes(l.NUMBER)||!e.includes(l.CVV)||function(e){return!e.includes(l.EXPIRATION_DATE)&&!e.includes(l.EXPIRATION_MONTH)&&!e.includes(l.EXPIRATION_YEAR)}(e))throw new Error("To use HostedFields you must use it with at least 3 children with types: [number, cvv, expirationDate] includes")},G=function(e){var t=function(e){return e.reduce((function(e,t){var n=t;return n.props.hostedFieldType&&e.push(n.props.hostedFieldType),e}),[])}(e);U(t),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(t)},Y=function(t){var n=t.styles,i=t.createOrder,u=t.notEligibleError,l=t.children,d=c.toArray(l),p=g()[0],f=p.options,v=p.loadingStatus,m=o(!0),E=m[0],y=m[1],P=o(null),b=P[0],w=P[1],I=r(null),S=r(),T=o(null)[1];return a((function(){G(d)}),[]),a((function(){var e,t;if(v===s.RESOLVED){if(S.current||(S.current=h(f["data-namespace"]).HostedFields,S.current||function(e){var t=e.components,n=void 0===t?"":t,r=e["data-namespace"],o=n?n+",hosted-fields":"hosted-fields",a="Unable to render <PayPalHostedFieldsProvider /> because window."+(void 0===r?"paypal":r)+".HostedFields is undefined.";throw n.includes("hosted-fields")||(a+="\nTo fix the issue, add 'hosted-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '"+o+"'}}>"),new Error(a)}(((e={components:f.components})["data-namespace"]=f["data-namespace"],e))),!(null===(t=null==S?void 0:S.current)||void 0===t?void 0:t.isEligible()))return y(!1);b&&b.teardown(),S.current.render({createOrder:i,styles:n,fields:x(d)}).then((function(e){w(e)})).catch((function(e){T((function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. "+e)}))}))}}),[v,n]),e.createElement("div",{ref:I},E?e.createElement(A.Provider,{value:b},l):u)},V=function(t){t.hostedFieldType,t.options;var n=f(t,["hostedFieldType","options"]);return e.createElement("div",p({},n))},H={PAYPAL:"paypal",VENMO:"venmo",APPLEPAY:"applepay",ITAU:"itau",CREDIT:"credit",PAYLATER:"paylater",CARD:"card",IDEAL:"ideal",SEPA:"sepa",BANCONTACT:"bancontact",GIROPAY:"giropay",SOFORT:"sofort",EPS:"eps",MYBANK:"mybank",P24:"p24",VERKKOPANKKI:"verkkopankki",PAYU:"payu",BLIK:"blik",TRUSTLY:"trustly",ZIMPLER:"zimpler",MAXIMA:"maxima",OXXO:"oxxo",BOLETO:"boleto",WECHATPAY:"wechatpay",MERCADOPAGO:"mercadopago"};export{M as BraintreePayPalButtons,H as FUNDING,l as PAYPAL_HOSTED_FIELDS_TYPES,S as PayPalButtons,V as PayPalHostedField,Y as PayPalHostedFieldsProvider,F as PayPalMarks,B as PayPalMessages,_ as PayPalScriptProvider,s as SCRIPT_LOADING_STATE,u as SCRIPT_PROVIDER_DISPATCH_ACTION,P as ScriptContext,E as destroySDKScript,m as getScriptID,y as scriptReducer,I as usePayPalHostedFields,w as usePayPalScriptReducer,g as useScriptProviderContext};
import e,{createContext as t,useContext as n,useRef as r,useState as o,useEffect as a,useReducer as i,Children as c}from"react";var s,u,l;!function(e){e.INITIAL="initial",e.PENDING="pending",e.REJECTED="rejected",e.RESOLVED="resolved"}(s||(s={})),function(e){e.LOADING_STATUS="setLoadingStatus",e.RESET_OPTIONS="resetOptions",e.SET_BRAINTREE_INSTANCE="braintreeInstance"}(u||(u={})),function(e){e.NUMBER="number",e.CVV="cvv",e.EXPIRATION_DATE="expirationDate",e.EXPIRATION_MONTH="expirationMonth",e.EXPIRATION_YEAR="expirationYear",e.POSTAL_CODE="postalCode"}(l||(l={}));var d="data-react-paypal-script-id",p=function(){return(p=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function f(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function v(e,t,n){if(n||2===arguments.length)for(var r,o=0,a=t.length;o<a;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function h(e){return void 0===e&&(e="paypal"),window[e]}function m(e){return"react-paypal-js-"+function(e){for(var t="",n=0;n<e.length;n++){var r=e[n].charCodeAt(0)*n;e[n+1]&&(r+=e[n+1].charCodeAt(0)*(n-1)),t+=String.fromCharCode(97+Math.abs(r)%26)}return t}(JSON.stringify(e))}function E(e){var t=self.document.querySelector("script["+d+'="'+e+'"]');(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function y(e,t){var n;switch(t.type){case u.LOADING_STATUS:return p(p({},e),{loadingStatus:t.value});case u.RESET_OPTIONS:return E(e.options[d]),delete t.value[d],p(p({},e),{loadingStatus:s.PENDING,options:p(p({},t.value),(n={},n[d]=""+m(t.value),n["data-sdk-integration-source"]="react-paypal-js",n))});case u.SET_BRAINTREE_INSTANCE:return p(p({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var P=t(null);function b(e){if("function"==typeof(null==e?void 0:e.dispatch)&&0!==e.dispatch.length)return e;throw new Error("usePayPalScriptReducer must be used within a PayPalScriptProvider")}function w(){var e=b(n(P));return[p(p({},e),{isInitial:e.loadingStatus===s.INITIAL,isPending:e.loadingStatus===s.PENDING,isResolved:e.loadingStatus===s.RESOLVED,isRejected:e.loadingStatus===s.REJECTED}),e.dispatch]}function g(){var e=function(e){var t;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t["data-client-token"]))throw new Error("A client token wasn't found in the provider parent component");return e}(b(n(P)));return[e,e.dispatch]}var A=t(null);function I(){return n(A)}var S=function(t){var n=t.className,i=void 0===n?"":n,c=t.disabled,s=void 0!==c&&c,u=t.children,l=t.forceReRender,d=void 0===l?[]:l,m=f(t,["className","disabled","children","forceReRender"]),E=s?{opacity:.38}:{},y=(i+" "+(s?"paypal-buttons-disabled":"")).trim(),P=r(null),b=r(null),g=w()[0],A=g.isResolved,I=g.options,S=o(null),T=S[0],O=S[1],N=o(!0),R=N[0],k=N[1],j=o(null)[1];function C(){null!==b.current&&b.current.close().catch((function(){}))}return a((function(){if(!1===A)return C;var e=h(I["data-namespace"]);if(void 0===e||void 0===e.Buttons)return j((function(){throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e["data-namespace"],o="Unable to render <PayPalButtons /> because window."+(void 0===r?"paypal":r)+".Buttons is undefined.";if(n.length&&!n.includes("buttons")){o+="\nTo fix the issue, add 'buttons' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(n+",buttons")+"'}}>`."}return o}(I))})),C;try{b.current=e.Buttons(p(p({},m),{onInit:function(e,t){O(t),"function"==typeof m.onInit&&m.onInit(e,t)}}))}catch(e){return j((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: "+e)}))}return!1===b.current.isEligible()?(k(!1),C):P.current?(b.current.render(P.current).catch((function(e){null!==P.current&&0!==P.current.children.length&&j((function(){throw new Error("Failed to render <PayPalButtons /> component. "+e)}))})),C):C}),v(v([A],d,!0),[m.fundingSource],!1)),a((function(){null!==T&&(!0===s?T.disable().catch((function(){})):T.enable().catch((function(){})))}),[s,T]),e.createElement(e.Fragment,null,R?e.createElement("div",{ref:P,style:E,className:y}):u)};function T(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL);var n=function(e,t){var n="",r="";Array.isArray(e)?e.length>1?(n="*",r=e.toString()):n=e.toString():"string"==typeof e&&e.length>0?n=e:"string"==typeof t&&t.length>0&&(n="*",r=t);return{"merchant-id":n,"data-merchant-id":r}}(e["merchant-id"],e["data-merchant-id"]),r=Object.assign({},e,n),o=Object.keys(r).filter((function(e){return void 0!==r[e]&&null!==r[e]&&""!==r[e]})).reduce((function(e,t){var n=r[t].toString();return"data-"===t.substring(0,5)?e.dataAttributes[t]=n:e.queryParams[t]=n,e}),{queryParams:{},dataAttributes:{}}),a=o.queryParams,i=o.dataAttributes;return{url:t+"?"+O(a),dataAttributes:i}}function O(e){var t="";return Object.keys(e).forEach((function(n){0!==t.length&&(t+="&"),t+=n+"="+e[n]})),t}function N(e,t){void 0===t&&(t={});var n=document.createElement("script");return n.src=e,Object.keys(t).forEach((function(e){n.setAttribute(e,t[e]),"data-csp-nonce"===e&&n.setAttribute("nonce",t["data-csp-nonce"])})),n}function R(e,t){if(void 0===t&&(t=j()),D(e,t),"undefined"==typeof window)return t.resolve(null);var n=T(e),r=n.url,o=n.dataAttributes,a=o["data-namespace"]||"paypal",i=C(a);return function(e,t){var n=document.querySelector('script[src="'+e+'"]');if(null===n)return null;var r=N(e,t),o=Object.assign({},n.dataset);if(delete o.uidAuto,Object.keys(o).length!==Object.keys(r.dataset).length)return null;var a=!0;return Object.keys(o).forEach((function(e){o[e]!==r.dataset[e]&&(a=!1)})),a?n:null}(r,o)&&i?t.resolve(i):k({url:r,attributes:o},t).then((function(){var e=C(a);if(e)return e;throw new Error("The window."+a+" global variable is not available.")}))}function k(e,t){void 0===t&&(t=j()),D(e,t);var n=e.url,r=e.attributes;if("string"!=typeof n||0===n.length)throw new Error("Invalid url.");if(void 0!==r&&"object"!=typeof r)throw new Error("Expected attributes to be an object.");return new t((function(e,t){if("undefined"==typeof window)return e();!function(e){var t=e.url,n=e.attributes,r=e.onSuccess,o=e.onError,a=N(t,n);a.onerror=o,a.onload=r,document.head.insertBefore(a,document.head.firstElementChild)}({url:n,attributes:r,onSuccess:function(){return e()},onError:function(){return t(new Error('The script "'+n+'" failed to load.'))}})}))}function j(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function C(e){return window[e]}function D(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}var L=function(e,t){return function(e,t){if("function"==typeof e.createOrder){var n=e.createOrder;e.createOrder=function(e,r){return n(e,p(p({},r),{braintree:t}))}}}(e,t),function(e,t){if("function"==typeof e.onApprove){var n=e.onApprove;e.onApprove=function(e,r){return n(e,p(p({},r),{braintree:t}))}}}(e,t),p({},e)},M=function(t){var n=t.className,r=void 0===n?"":n,i=t.disabled,c=void 0!==i&&i,s=t.children,l=t.forceReRender,d=void 0===l?[]:l,v=f(t,["className","disabled","children","forceReRender"]),h=o(null)[1],m=g(),E=m[0],y=m[1];return a((function(){Promise.all([k({url:"https://js.braintreegateway.com/web/3.81.0/js/client.min.js"}),k({url:"https://js.braintreegateway.com/web/3.81.0/js/paypal-checkout.min.js"})]).then((function(){var e,t=E.options["data-client-token"],n=(void 0===e&&(e="braintree"),window[e]);return n.client.create({authorization:t}).then((function(e){return n.paypalCheckout.create({client:e})})).then((function(e){y({type:u.SET_BRAINTREE_INSTANCE,value:e})}))})).catch((function(e){h((function(){throw new Error("An error occurred when loading the Braintree scripts: "+e)}))}))}),[E.options,y]),e.createElement(e.Fragment,null,E.braintreePayPalCheckoutInstance&&e.createElement(S,p({className:r,disabled:c,forceReRender:d},L(v,E.braintreePayPalCheckoutInstance)),s))},F=function(t){var n=t.className,i=void 0===n?"":n,c=t.children,s=f(t,["className","children"]),u=w()[0],l=u.isResolved,d=u.options,v=r(null),m=o(!0),E=m[0],y=m[1],P=o(null)[1];return a((function(){if(!1!==l){var e=h(d["data-namespace"]);void 0!==e&&void 0!==e.Marks?function(e){var t=v.current;if(!t||!e.isEligible())return y(!1);t.firstChild&&t.removeChild(t.firstChild),e.render(t).catch((function(e){null!==t&&0!==t.children.length&&P((function(){throw new Error("Failed to render <PayPalMarks /> component. "+e)}))}))}(e.Marks(p({},s))):P((function(){throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e["data-namespace"],o="Unable to render <PayPalMarks /> because window."+(void 0===r?"paypal":r)+".Marks is undefined.";if(!n.includes("marks")){o+="\nTo fix the issue, add 'marks' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(n?n+",marks":"marks")+"'}}>`."}return o}(d))}))}}),[l,s.fundingSource]),e.createElement(e.Fragment,null,E?e.createElement("div",{ref:v,className:i}):c)};var B=function(t){var n=t.className,i=void 0===n?"":n,c=t.forceReRender,s=void 0===c?[]:c,u=f(t,["className","forceReRender"]),l=w()[0],d=l.isResolved,m=l.options,E=r(null),y=r(null),P=o(null)[1];return a((function(){if(!1!==d){var e=h(m["data-namespace"]);void 0!==e&&void 0!==e.Messages?(y.current=e.Messages(p({},u)),null!==E.current&&y.current.render(E.current).catch((function(e){null!==E.current&&0!==E.current.children.length&&P((function(){throw new Error("Failed to render <PayPalMessages /> component. "+e)}))}))):P((function(){throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e["data-namespace"],o="Unable to render <PayPalMessages /> because window."+(void 0===r?"paypal":r)+".Messages is undefined.";if(!n.includes("messages")){o+="\nTo fix the issue, add 'messages' to the list of components passed to the parent PayPalScriptProvider:\n`<PayPalScriptProvider options={{ components: '"+(n?n+",messages":"messages")+"'}}>`."}return o}(m))}))}}),v([d],s,!0)),e.createElement("div",{ref:E,className:i})};var _=function(t){var n,r=t.options,o=void 0===r?{"client-id":"test"}:r,c=t.children,l=t.deferLoading,f=void 0!==l&&l,v=i(y,{options:p(p({},o),(n={},n[d]=""+m(o),n["data-sdk-integration-source"]="react-paypal-js",n)),loadingStatus:f?s.INITIAL:s.PENDING}),h=v[0],E=v[1];return a((function(){if(!1===f&&h.loadingStatus===s.INITIAL)return E({type:u.LOADING_STATUS,value:s.PENDING});if(h.loadingStatus===s.PENDING){var e=!0;return R(h.options).then((function(){e&&E({type:u.LOADING_STATUS,value:s.RESOLVED})})).catch((function(){e&&E({type:u.LOADING_STATUS,value:s.REJECTED})})),function(){e=!1}}}),[h.options,f,h.loadingStatus]),e.createElement(P.Provider,{value:p(p({},h),{dispatch:E})},c)},x=function(e){return e.reduce((function(e,t){var n=t.props,r=n.hostedFieldType,o=n.options;return Object.values(l).includes(r)&&(e[r]={selector:o.selector,placeholder:o.placeholder,type:o.type,formatInput:o.formatInput,maskInput:o.maskInput,select:o.select,maxlength:o.maxlength,minlength:o.minlength,prefill:o.prefill,rejectUnsupportedCards:o.rejectUnsupportedCards}),e}),{})},U=function(e){if(!e.includes(l.NUMBER)||!e.includes(l.CVV)||function(e){return!e.includes(l.EXPIRATION_DATE)&&!e.includes(l.EXPIRATION_MONTH)&&!e.includes(l.EXPIRATION_YEAR)}(e))throw new Error("To use HostedFields you must use it with at least 3 children with types: [number, cvv, expirationDate] includes")},G=function(e){var t=function(e){return e.reduce((function(e,t){var n=t;return n.props.hostedFieldType&&e.push(n.props.hostedFieldType),e}),[])}(e);U(t),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(t)},Y=function(t){var n=t.styles,i=t.createOrder,u=t.notEligibleError,l=t.children,d=c.toArray(l),p=g()[0],f=p.options,v=p.loadingStatus,m=o(!0),E=m[0],y=m[1],P=o(null),b=P[0],w=P[1],I=r(null),S=r(),T=o(null)[1];return a((function(){G(d)}),[]),a((function(){var e,t;if(v===s.RESOLVED){if(S.current||(S.current=h(f["data-namespace"]).HostedFields,S.current||function(e){var t=e.components,n=void 0===t?"":t,r=e["data-namespace"],o=n?n+",hosted-fields":"hosted-fields",a="Unable to render <PayPalHostedFieldsProvider /> because window."+(void 0===r?"paypal":r)+".HostedFields is undefined.";throw n.includes("hosted-fields")||(a+="\nTo fix the issue, add 'hosted-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '"+o+"'}}>"),new Error(a)}(((e={components:f.components})["data-namespace"]=f["data-namespace"],e))),!(null===(t=null==S?void 0:S.current)||void 0===t?void 0:t.isEligible()))return y(!1);b&&b.teardown(),S.current.render({createOrder:i,styles:n,fields:x(d)}).then((function(e){w(e)})).catch((function(e){T((function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. "+e)}))}))}}),[v,n]),e.createElement("div",{ref:I},E?e.createElement(A.Provider,{value:b},l):u)},V=function(t){t.hostedFieldType,t.options;var n=f(t,["hostedFieldType","options"]);return e.createElement("div",p({},n))},H={PAYPAL:"paypal",VENMO:"venmo",APPLEPAY:"applepay",ITAU:"itau",CREDIT:"credit",PAYLATER:"paylater",CARD:"card",IDEAL:"ideal",SEPA:"sepa",BANCONTACT:"bancontact",GIROPAY:"giropay",SOFORT:"sofort",EPS:"eps",MYBANK:"mybank",P24:"p24",VERKKOPANKKI:"verkkopankki",PAYU:"payu",BLIK:"blik",TRUSTLY:"trustly",ZIMPLER:"zimpler",MAXIMA:"maxima",OXXO:"oxxo",BOLETO:"boleto",WECHATPAY:"wechatpay",MERCADOPAGO:"mercadopago"};export{M as BraintreePayPalButtons,u as DISPATCH_ACTION,H as FUNDING,l as PAYPAL_HOSTED_FIELDS_TYPES,S as PayPalButtons,V as PayPalHostedField,Y as PayPalHostedFieldsProvider,F as PayPalMarks,B as PayPalMessages,_ as PayPalScriptProvider,s as SCRIPT_LOADING_STATE,P as ScriptContext,E as destroySDKScript,m as getScriptID,y as scriptReducer,I as usePayPalHostedFields,w as usePayPalScriptReducer,g as useScriptProviderContext};

@@ -17,3 +17,3 @@ /**

*/
export declare enum SCRIPT_PROVIDER_DISPATCH_ACTION {
export declare enum DISPATCH_ACTION {
LOADING_STATUS = "setLoadingStatus",

@@ -20,0 +20,0 @@ RESET_OPTIONS = "resetOptions",

import { SCRIPT_ID } from "../constants";
import { BraintreePayPalCheckout } from "./braintree/paypalCheckout";
import { SCRIPT_PROVIDER_DISPATCH_ACTION, SCRIPT_LOADING_STATE } from "./enums";
import { DISPATCH_ACTION, SCRIPT_LOADING_STATE } from "./enums";
import type { ReactNode, Dispatch } from "react";

@@ -10,9 +10,9 @@ import type { PayPalScriptOptions } from "@paypal/paypal-js/types/script-options";

export declare type ScriptReducerAction = {
type: `${SCRIPT_PROVIDER_DISPATCH_ACTION.LOADING_STATUS}`;
type: `${DISPATCH_ACTION.LOADING_STATUS}`;
value: SCRIPT_LOADING_STATE;
} | {
type: `${SCRIPT_PROVIDER_DISPATCH_ACTION.RESET_OPTIONS}`;
type: `${DISPATCH_ACTION.RESET_OPTIONS}`;
value: PayPalScriptOptions | ReactPayPalScriptOptions;
} | {
type: `${SCRIPT_PROVIDER_DISPATCH_ACTION.SET_BRAINTREE_INSTANCE}`;
type: `${DISPATCH_ACTION.SET_BRAINTREE_INSTANCE}`;
value: BraintreePayPalCheckout;

@@ -19,0 +19,0 @@ };

{
"name": "@paypal/react-paypal-js",
"version": "7.4.0",
"version": "7.4.1",
"description": "React components for the PayPal JS SDK",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc