@paypal/react-paypal-js
Advanced tools
Comparing version 7.6.2 to 7.7.0
/*! | ||
* react-paypal-js v7.6.2 (2022-05-09T20:57:39.607Z) | ||
* react-paypal-js v7.7.0 (2022-05-10T17:43:04.667Z) | ||
* Copyright 2020-present, PayPal, Inc. All rights reserved. | ||
@@ -674,3 +674,3 @@ * | ||
var BraintreePayPalButtons = function (_a) { | ||
var _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, children = _a.children, _d = _a.forceReRender, forceReRender = _d === void 0 ? [] : _d, braintreeNamespace = _a.braintreeNamespace, buttonProps = __rest(_a, ["className", "disabled", "children", "forceReRender", "braintreeNamespace"]); | ||
var _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, children = _a.children, _d = _a.forceReRender, forceReRender = _d === void 0 ? [] : _d, braintreeNamespace = _a.braintreeNamespace, merchantAccountId = _a.merchantAccountId, buttonProps = __rest(_a, ["className", "disabled", "children", "forceReRender", "braintreeNamespace", "merchantAccountId"]); | ||
var _e = React.useState(null), setErrorState = _e[1]; | ||
@@ -688,5 +688,6 @@ var _f = useScriptProviderContext(), providerContext = _f[0], dispatch = _f[1]; | ||
.then(function (clientInstance) { | ||
return braintree.paypalCheckout.create({ | ||
client: clientInstance, | ||
}); | ||
var merchantProp = merchantAccountId | ||
? { merchantAccountId: merchantAccountId } | ||
: {}; | ||
return braintree.paypalCheckout.create(__assign(__assign({}, merchantProp), { client: clientInstance })); | ||
}) | ||
@@ -693,0 +694,0 @@ .then(function (paypalCheckoutInstance) { |
/*! | ||
* react-paypal-js v7.6.2 (2022-05-09T20:57:39.607Z) | ||
* react-paypal-js v7.7.0 (2022-05-10T17:43:04.667Z) | ||
* 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 n,r,o,a=t(e);exports.SCRIPT_LOADING_STATE=void 0,(n=exports.SCRIPT_LOADING_STATE||(exports.SCRIPT_LOADING_STATE={})).INITIAL="initial",n.PENDING="pending",n.REJECTED="rejected",n.RESOLVED="resolved",exports.DISPATCH_ACTION=void 0,(r=exports.DISPATCH_ACTION||(exports.DISPATCH_ACTION={})).LOADING_STATUS="setLoadingStatus",r.RESET_OPTIONS="resetOptions",r.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",c="data-client-token",s="data-user-id-token",u="data-sdk-integration-source",l="react-paypal-js",d="data-namespace",p="https://js.braintreegateway.com/web/".concat("3.84.0","/js/client.min.js"),f="https://js.braintreegateway.com/web/".concat("3.84.0","/js/paypal-checkout.min.js"),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 E(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 S(e){return void 0===e&&(e="paypal"),window[e]}function T(e){var t=e.reactComponentName,n=e.sdkComponentKey,r=e.sdkRequestedComponents,o=void 0===r?"":r,a=e.sdkDataNamespace,i=void 0===a?"paypal":a,c=n.charAt(0).toUpperCase().concat(n.substring(1)),s="Unable to render <".concat(t," /> because window.").concat(i,".").concat(c," is undefined.");if(!o.includes(n)){var u=[o,n].filter(Boolean).join();s+="\nTo fix the issue, add '".concat(n,"' to the list of components passed to the parent PayPalScriptProvider:")+"\n`<PayPalScriptProvider options={{ components: '".concat(u,"'}}>`.")}return s}function h(e){return"react-paypal-js-".concat(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 A(e){var t=self.document.querySelector("script[".concat(i,'="').concat(e,'"]'));(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function y(e,t){var n;switch(t.type){case exports.DISPATCH_ACTION.LOADING_STATUS:return P(P({},e),{loadingStatus:t.value});case exports.DISPATCH_ACTION.RESET_OPTIONS:return A(e.options[i]),delete t.value[i],P(P({},e),{loadingStatus:exports.SCRIPT_LOADING_STATE.PENDING,options:P(P({},t.value),(n={},n[i]="".concat(h(t.value)),n[u]=l,n))});case exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:return P(P({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var m=e.createContext(null);function I(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 N(){var t=I(e.useContext(m));return[P(P({},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 O(){var t=function(e){var t,n;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t[c])&&!(null===(n=null==e?void 0:e.options)||void 0===n?void 0:n[s]))throw new Error("Invalid authorization data. Use data-client-token or data-user-id-token to authorize.");return e}(I(e.useContext(m)));return[t,t.dispatch]}var C=e.createContext({});var R=function(t){var n=t.className,r=void 0===n?"":n,o=t.disabled,i=void 0!==o&&o,c=t.children,s=t.forceReRender,u=void 0===s?[]:s,l=E(t,["className","disabled","children","forceReRender"]),p=i?{opacity:.38}:{},f="".concat(r," ").concat(i?"paypal-buttons-disabled":"").trim(),h=e.useRef(null),A=e.useRef(null),y=N()[0],m=y.isResolved,I=y.options,O=e.useState(null),C=O[0],_=O[1],b=e.useState(!0),w=b[0],g=b[1],D=e.useState(null)[1];function x(){null!==A.current&&A.current.close().catch((function(){}))}return e.useEffect((function(){if(!1===m)return x;var e=S(I[d]);if(void 0===e||void 0===e.Buttons)return D((function(){throw new Error(T({reactComponentName:R.displayName,sdkComponentKey:"buttons",sdkRequestedComponents:I.components,sdkDataNamespace:I[d]}))})),x;try{A.current=e.Buttons(P(P({},l),{onInit:function(e,t){_(t),"function"==typeof l.onInit&&l.onInit(e,t)}}))}catch(e){return D((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: ".concat(e))}))}return!1===A.current.isEligible()?(g(!1),x):h.current?(A.current.render(h.current).catch((function(e){null!==h.current&&0!==h.current.children.length&&D((function(){throw new Error("Failed to render <PayPalButtons /> component. ".concat(e))}))})),x):x}),v(v([m],u,!0),[l.fundingSource],!1)),e.useEffect((function(){null!==C&&(!0===i?C.disable().catch((function(){})):C.enable().catch((function(){})))}),[i,C]),a.default.createElement(a.default.Fragment,null,w?a.default.createElement("div",{ref:h,style:p,className:f}):c)};function _(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL),function(e){var t=e["merchant-id"],n=e["data-merchant-id"],r="",o="";Array.isArray(t)?t.length>1?(r="*",o=t.toString()):r=t.toString():"string"==typeof t&&t.length>0?r=t:"string"==typeof n&&n.length>0&&(r="*",o=n);e["merchant-id"]=r,e["data-merchant-id"]=o}(e);var n=Object.keys(e).filter((function(t){return void 0!==e[t]&&null!==e[t]&&""!==e[t]})).reduce((function(t,n){var r=e[n].toString();return"data-"===n.substring(0,5)?t.dataAttributes[n]=r:t.queryParams[n]=r,t}),{queryParams:{},dataAttributes:{}}),r=n.queryParams,o=n.dataAttributes;return{url:"".concat(t,"?").concat(b(r)),dataAttributes:o}}function b(e){var t="";return Object.keys(e).forEach((function(n){0!==t.length&&(t+="&"),t+=n+"="+e[n]})),t}function w(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 g(e,t){if(void 0===t&&(t=x()),k(e,t),"undefined"==typeof window)return t.resolve(null);var n=_(e),r=n.url,o=n.dataAttributes,a=o["data-namespace"]||"paypal",i=L(a);return function(e,t){var n=document.querySelector('script[src="'.concat(e,'"]'));if(null===n)return null;var r=w(e,t),o=n.cloneNode();if(delete o.dataset.uidAuto,Object.keys(o.dataset).length!==Object.keys(r.dataset).length)return null;var a=!0;return Object.keys(o.dataset).forEach((function(e){o.dataset[e]!==r.dataset[e]&&(a=!1)})),a?n:null}(r,o)&&i?t.resolve(i):D({url:r,attributes:o},t).then((function(){var e=L(a);if(e)return e;throw new Error("The window.".concat(a," global variable is not available."))}))}function D(e,t){void 0===t&&(t=x()),k(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=w(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(){var e=new Error('The script "'.concat(n,'" failed to load.'));return window.fetch?fetch(n).then((function(n){return 200===n.status&&t(e),n.text()})).then((function(e){var n=function(e){var t=e.split("/* Original Error:")[1];return t?t.replace(/\n/g,"").replace("*/","").trim():e}(e);t(new Error(n))})).catch((function(e){t(e)})):t(e)}})}))}function x(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function L(e){return window[e]}function k(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.")}R.displayName="PayPalButtons";var F=function(e){return e&&function(e){var t,n;if("function"!=typeof(null===(t=null==e?void 0:e.client)||void 0===t?void 0:t.create)&&"function"!=typeof(null===(n=null==e?void 0:e.paypalCheckout)||void 0===n?void 0:n.create))throw new Error("The braintreeNamespace property is not a valid BraintreeNamespace type.");return!0}(e)?Promise.resolve(e):Promise.all([D({url:p}),D({url:f})]).then((function(){return void 0===e&&(e="braintree"),window[e];var e}))},H=function(t){var n=t.className,r=void 0===n?"":n,o=t.children,i=E(t,["className","children"]),c=N()[0],s=c.isResolved,u=c.options,l=e.useRef(null),p=e.useState(!0),f=p[0],v=p[1],h=e.useState(null)[1];return e.useEffect((function(){if(!1!==s){var e=S(u[d]);if(void 0===e||void 0===e.Marks)return h((function(){throw new Error(T({reactComponentName:H.displayName,sdkComponentKey:"marks",sdkRequestedComponents:u.components,sdkDataNamespace:u[d]}))}));!function(e){var t=l.current;if(!t||!e.isEligible())return v(!1);t.firstChild&&t.removeChild(t.firstChild),e.render(t).catch((function(e){null!==t&&0!==t.children.length&&h((function(){throw new Error("Failed to render <PayPalMarks /> component. ".concat(e))}))}))}(e.Marks(P({},i)))}}),[s,i.fundingSource]),a.default.createElement(a.default.Fragment,null,f?a.default.createElement("div",{ref:l,className:r}):o)};H.displayName="PayPalMarks";var j=function(t){var n=t.className,r=void 0===n?"":n,o=t.forceReRender,i=void 0===o?[]:o,c=E(t,["className","forceReRender"]),s=N()[0],u=s.isResolved,l=s.options,p=e.useRef(null),f=e.useRef(null),h=e.useState(null)[1];return e.useEffect((function(){if(!1!==u){var e=S(l[d]);if(void 0===e||void 0===e.Messages)return h((function(){throw new Error(T({reactComponentName:j.displayName,sdkComponentKey:"messages",sdkRequestedComponents:l.components,sdkDataNamespace:l[d]}))}));f.current=e.Messages(P({},c)),f.current.render(p.current).catch((function(e){null!==p.current&&0!==p.current.children.length&&h((function(){throw new Error("Failed to render <PayPalMessages /> component. ".concat(e))}))}))}}),v([u],i,!0)),a.default.createElement("div",{ref:p,className:r})};j.displayName="PayPalMessages";var 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")},Y=function(e){G(e),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(e)},B={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",MULTIBLANCO:"multiblanco"};exports.BraintreePayPalButtons=function(t){var n=t.className,r=void 0===n?"":n,o=t.disabled,i=void 0!==o&&o,u=t.children,l=t.forceReRender,d=void 0===l?[]:l,p=t.braintreeNamespace,f=E(t,["className","disabled","children","forceReRender","braintreeNamespace"]),v=e.useState(null)[1],S=O(),T=S[0],h=S[1];return e.useEffect((function(){F(p).then((function(e){var t=T.options[s],n=T.options[c];return e.client.create({authorization:t||n}).then((function(t){return e.paypalCheckout.create({client:t})})).then((function(e){h({type:exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,value:e})}))})).catch((function(e){v((function(){throw new Error("".concat("Failed to load the PayPal JS SDK script."," ").concat(e))}))}))}),[T.options]),a.default.createElement(a.default.Fragment,null,T.braintreePayPalCheckoutInstance&&a.default.createElement(R,P({className:r,disabled:i,forceReRender:d},function(e,t){var n=e.createOrder,r=e.createBillingAgreement,o=e.onApprove;return"function"==typeof n&&(e.createOrder=function(e,r){return n(e,P(P({},r),{braintree:t}))}),"function"==typeof r&&(e.createBillingAgreement=function(e,n){return r(e,P(P({},n),{braintree:t}))}),"function"==typeof o&&(e.onApprove=function(e,n){return o(e,P(P({},n),{braintree:t}))}),P({},e)}(f,T.braintreePayPalCheckoutInstance)),u))},exports.FUNDING=B,exports.PayPalButtons=R,exports.PayPalHostedField=function(t){var n=t.hostedFieldType,r=t.options,o=E(t,["hostedFieldType","options"]),i=e.useContext(C);return e.useEffect((function(){var e;if(!(null==i?void 0:i.registerHostedField))throw new Error("The HostedField cannot be register in the PayPalHostedFieldsProvider parent component");i.registerHostedField(((e={})[n]={selector:r.selector,placeholder:r.placeholder,type:r.type,formatInput:r.formatInput,maskInput:r.maskInput,select:r.select,maxlength:r.maxlength,minlength:r.minlength,prefill:r.prefill,rejectUnsupportedCards:r.rejectUnsupportedCards},e))}),[]),a.default.createElement("div",P({},o))},exports.PayPalHostedFieldsProvider=function(t){var n=t.styles,r=t.createOrder,o=t.notEligibleError,i=t.children,c=O()[0],s=c.options,u=c.loadingStatus,l=e.useState(!0),p=l[0],f=l[1],E=e.useState(),v=E[0],T=E[1],h=e.useState(null)[1],A=e.useRef(null),y=e.useRef(),m=function(t){void 0===t&&(t={});var n=e.useRef(t);return[n,function(e){n.current=P(P({},n.current),e)}]}(),I=m[0],N=m[1];return e.useEffect((function(){var e;if(Y(Object.keys(I.current)),u===exports.SCRIPT_LOADING_STATE.RESOLVED){if(y.current=S(s[d]).HostedFields,!y.current)throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e[d],o=void 0===r?"paypal":r,a=n?"".concat(n,",hosted-fields"):"hosted-fields",i="Unable to render <PayPalHostedFieldsProvider /> because window.".concat(o,".HostedFields is undefined.");return n.includes("hosted-fields")||(i+="\nTo fix the issue, add 'hosted-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '".concat(a,"'}}>")),i}(((e={components:s.components})[d]=s[d],e)));if(!y.current.isEligible())return f(!1);v&&v.teardown(),y.current.render({createOrder:r,styles:n,fields:I.current}).then((function(e){A.current&&T(e)})).catch((function(e){h((function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. ".concat(e))}))}))}}),[u,n]),a.default.createElement("div",{ref:A},p?a.default.createElement(C.Provider,{value:{cardFields:v,registerHostedField:N}},i):o)},exports.PayPalMarks=H,exports.PayPalMessages=j,exports.PayPalScriptProvider=function(t){var n,r=t.options,o=void 0===r?{"client-id":"test"}:r,c=t.children,s=t.deferLoading,d=void 0!==s&&s,p=e.useReducer(y,{options:P(P({},o),(n={},n[i]="".concat(h(o)),n[u]=l,n)),loadingStatus:d?exports.SCRIPT_LOADING_STATE.INITIAL:exports.SCRIPT_LOADING_STATE.PENDING}),f=p[0],E=p[1];return e.useEffect((function(){if(!1===d&&f.loadingStatus===exports.SCRIPT_LOADING_STATE.INITIAL)return E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.PENDING});if(f.loadingStatus===exports.SCRIPT_LOADING_STATE.PENDING){var e=!0;return g(f.options).then((function(){e&&E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.RESOLVED})})).catch((function(t){console.error("".concat("Failed to load the PayPal JS SDK script."," ").concat(t)),e&&E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.REJECTED})})),function(){e=!1}}}),[f.options,d,f.loadingStatus]),a.default.createElement(m.Provider,{value:P(P({},f),{dispatch:E})},c)},exports.ScriptContext=m,exports.destroySDKScript=A,exports.getScriptID=h,exports.scriptReducer=y,exports.usePayPalHostedFields=function(){return e.useContext(C)},exports.usePayPalScriptReducer=N,exports.useScriptProviderContext=O; | ||
"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 n,r,o,a=t(e);exports.SCRIPT_LOADING_STATE=void 0,(n=exports.SCRIPT_LOADING_STATE||(exports.SCRIPT_LOADING_STATE={})).INITIAL="initial",n.PENDING="pending",n.REJECTED="rejected",n.RESOLVED="resolved",exports.DISPATCH_ACTION=void 0,(r=exports.DISPATCH_ACTION||(exports.DISPATCH_ACTION={})).LOADING_STATUS="setLoadingStatus",r.RESET_OPTIONS="resetOptions",r.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",c="data-client-token",s="data-user-id-token",u="data-sdk-integration-source",l="react-paypal-js",d="data-namespace",p="https://js.braintreegateway.com/web/".concat("3.84.0","/js/client.min.js"),f="https://js.braintreegateway.com/web/".concat("3.84.0","/js/paypal-checkout.min.js"),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 E(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 S(e){var t=e.reactComponentName,n=e.sdkComponentKey,r=e.sdkRequestedComponents,o=void 0===r?"":r,a=e.sdkDataNamespace,i=void 0===a?"paypal":a,c=n.charAt(0).toUpperCase().concat(n.substring(1)),s="Unable to render <".concat(t," /> because window.").concat(i,".").concat(c," is undefined.");if(!o.includes(n)){var u=[o,n].filter(Boolean).join();s+="\nTo fix the issue, add '".concat(n,"' to the list of components passed to the parent PayPalScriptProvider:")+"\n`<PayPalScriptProvider options={{ components: '".concat(u,"'}}>`.")}return s}function T(e){return"react-paypal-js-".concat(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 A(e){var t=self.document.querySelector("script[".concat(i,'="').concat(e,'"]'));(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function m(e,t){var n;switch(t.type){case exports.DISPATCH_ACTION.LOADING_STATUS:return P(P({},e),{loadingStatus:t.value});case exports.DISPATCH_ACTION.RESET_OPTIONS:return A(e.options[i]),delete t.value[i],P(P({},e),{loadingStatus:exports.SCRIPT_LOADING_STATE.PENDING,options:P(P({},t.value),(n={},n[i]="".concat(T(t.value)),n[u]=l,n))});case exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:return P(P({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var y=e.createContext(null);function I(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 N(){var t=I(e.useContext(y));return[P(P({},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 O(){var t=function(e){var t,n;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t[c])&&!(null===(n=null==e?void 0:e.options)||void 0===n?void 0:n[s]))throw new Error("Invalid authorization data. Use data-client-token or data-user-id-token to authorize.");return e}(I(e.useContext(y)));return[t,t.dispatch]}var C=e.createContext({});var R=function(t){var n=t.className,r=void 0===n?"":n,o=t.disabled,i=void 0!==o&&o,c=t.children,s=t.forceReRender,u=void 0===s?[]:s,l=E(t,["className","disabled","children","forceReRender"]),p=i?{opacity:.38}:{},f="".concat(r," ").concat(i?"paypal-buttons-disabled":"").trim(),T=e.useRef(null),A=e.useRef(null),m=N()[0],y=m.isResolved,I=m.options,O=e.useState(null),C=O[0],_=O[1],b=e.useState(!0),w=b[0],g=b[1],D=e.useState(null)[1];function x(){null!==A.current&&A.current.close().catch((function(){}))}return e.useEffect((function(){if(!1===y)return x;var e=h(I[d]);if(void 0===e||void 0===e.Buttons)return D((function(){throw new Error(S({reactComponentName:R.displayName,sdkComponentKey:"buttons",sdkRequestedComponents:I.components,sdkDataNamespace:I[d]}))})),x;try{A.current=e.Buttons(P(P({},l),{onInit:function(e,t){_(t),"function"==typeof l.onInit&&l.onInit(e,t)}}))}catch(e){return D((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: ".concat(e))}))}return!1===A.current.isEligible()?(g(!1),x):T.current?(A.current.render(T.current).catch((function(e){null!==T.current&&0!==T.current.children.length&&D((function(){throw new Error("Failed to render <PayPalButtons /> component. ".concat(e))}))})),x):x}),v(v([y],u,!0),[l.fundingSource],!1)),e.useEffect((function(){null!==C&&(!0===i?C.disable().catch((function(){})):C.enable().catch((function(){})))}),[i,C]),a.default.createElement(a.default.Fragment,null,w?a.default.createElement("div",{ref:T,style:p,className:f}):c)};function _(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL),function(e){var t=e["merchant-id"],n=e["data-merchant-id"],r="",o="";Array.isArray(t)?t.length>1?(r="*",o=t.toString()):r=t.toString():"string"==typeof t&&t.length>0?r=t:"string"==typeof n&&n.length>0&&(r="*",o=n);e["merchant-id"]=r,e["data-merchant-id"]=o}(e);var n=Object.keys(e).filter((function(t){return void 0!==e[t]&&null!==e[t]&&""!==e[t]})).reduce((function(t,n){var r=e[n].toString();return"data-"===n.substring(0,5)?t.dataAttributes[n]=r:t.queryParams[n]=r,t}),{queryParams:{},dataAttributes:{}}),r=n.queryParams,o=n.dataAttributes;return{url:"".concat(t,"?").concat(b(r)),dataAttributes:o}}function b(e){var t="";return Object.keys(e).forEach((function(n){0!==t.length&&(t+="&"),t+=n+"="+e[n]})),t}function w(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 g(e,t){if(void 0===t&&(t=x()),k(e,t),"undefined"==typeof window)return t.resolve(null);var n=_(e),r=n.url,o=n.dataAttributes,a=o["data-namespace"]||"paypal",i=L(a);return function(e,t){var n=document.querySelector('script[src="'.concat(e,'"]'));if(null===n)return null;var r=w(e,t),o=n.cloneNode();if(delete o.dataset.uidAuto,Object.keys(o.dataset).length!==Object.keys(r.dataset).length)return null;var a=!0;return Object.keys(o.dataset).forEach((function(e){o.dataset[e]!==r.dataset[e]&&(a=!1)})),a?n:null}(r,o)&&i?t.resolve(i):D({url:r,attributes:o},t).then((function(){var e=L(a);if(e)return e;throw new Error("The window.".concat(a," global variable is not available."))}))}function D(e,t){void 0===t&&(t=x()),k(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=w(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(){var e=new Error('The script "'.concat(n,'" failed to load.'));return window.fetch?fetch(n).then((function(n){return 200===n.status&&t(e),n.text()})).then((function(e){var n=function(e){var t=e.split("/* Original Error:")[1];return t?t.replace(/\n/g,"").replace("*/","").trim():e}(e);t(new Error(n))})).catch((function(e){t(e)})):t(e)}})}))}function x(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function L(e){return window[e]}function k(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.")}R.displayName="PayPalButtons";var F=function(e){return e&&function(e){var t,n;if("function"!=typeof(null===(t=null==e?void 0:e.client)||void 0===t?void 0:t.create)&&"function"!=typeof(null===(n=null==e?void 0:e.paypalCheckout)||void 0===n?void 0:n.create))throw new Error("The braintreeNamespace property is not a valid BraintreeNamespace type.");return!0}(e)?Promise.resolve(e):Promise.all([D({url:p}),D({url:f})]).then((function(){return void 0===e&&(e="braintree"),window[e];var e}))},H=function(t){var n=t.className,r=void 0===n?"":n,o=t.children,i=E(t,["className","children"]),c=N()[0],s=c.isResolved,u=c.options,l=e.useRef(null),p=e.useState(!0),f=p[0],v=p[1],T=e.useState(null)[1];return e.useEffect((function(){if(!1!==s){var e=h(u[d]);if(void 0===e||void 0===e.Marks)return T((function(){throw new Error(S({reactComponentName:H.displayName,sdkComponentKey:"marks",sdkRequestedComponents:u.components,sdkDataNamespace:u[d]}))}));!function(e){var t=l.current;if(!t||!e.isEligible())return v(!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. ".concat(e))}))}))}(e.Marks(P({},i)))}}),[s,i.fundingSource]),a.default.createElement(a.default.Fragment,null,f?a.default.createElement("div",{ref:l,className:r}):o)};H.displayName="PayPalMarks";var j=function(t){var n=t.className,r=void 0===n?"":n,o=t.forceReRender,i=void 0===o?[]:o,c=E(t,["className","forceReRender"]),s=N()[0],u=s.isResolved,l=s.options,p=e.useRef(null),f=e.useRef(null),T=e.useState(null)[1];return e.useEffect((function(){if(!1!==u){var e=h(l[d]);if(void 0===e||void 0===e.Messages)return T((function(){throw new Error(S({reactComponentName:j.displayName,sdkComponentKey:"messages",sdkRequestedComponents:l.components,sdkDataNamespace:l[d]}))}));f.current=e.Messages(P({},c)),f.current.render(p.current).catch((function(e){null!==p.current&&0!==p.current.children.length&&T((function(){throw new Error("Failed to render <PayPalMessages /> component. ".concat(e))}))}))}}),v([u],i,!0)),a.default.createElement("div",{ref:p,className:r})};j.displayName="PayPalMessages";var 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")},Y=function(e){G(e),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(e)},B={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",MULTIBLANCO:"multiblanco"};exports.BraintreePayPalButtons=function(t){var n=t.className,r=void 0===n?"":n,o=t.disabled,i=void 0!==o&&o,u=t.children,l=t.forceReRender,d=void 0===l?[]:l,p=t.braintreeNamespace,f=t.merchantAccountId,v=E(t,["className","disabled","children","forceReRender","braintreeNamespace","merchantAccountId"]),h=e.useState(null)[1],S=O(),T=S[0],A=S[1];return e.useEffect((function(){F(p).then((function(e){var t=T.options[s],n=T.options[c];return e.client.create({authorization:t||n}).then((function(t){var n=f?{merchantAccountId:f}:{};return e.paypalCheckout.create(P(P({},n),{client:t}))})).then((function(e){A({type:exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,value:e})}))})).catch((function(e){h((function(){throw new Error("".concat("Failed to load the PayPal JS SDK script."," ").concat(e))}))}))}),[T.options]),a.default.createElement(a.default.Fragment,null,T.braintreePayPalCheckoutInstance&&a.default.createElement(R,P({className:r,disabled:i,forceReRender:d},function(e,t){var n=e.createOrder,r=e.createBillingAgreement,o=e.onApprove;return"function"==typeof n&&(e.createOrder=function(e,r){return n(e,P(P({},r),{braintree:t}))}),"function"==typeof r&&(e.createBillingAgreement=function(e,n){return r(e,P(P({},n),{braintree:t}))}),"function"==typeof o&&(e.onApprove=function(e,n){return o(e,P(P({},n),{braintree:t}))}),P({},e)}(v,T.braintreePayPalCheckoutInstance)),u))},exports.FUNDING=B,exports.PayPalButtons=R,exports.PayPalHostedField=function(t){var n=t.hostedFieldType,r=t.options,o=E(t,["hostedFieldType","options"]),i=e.useContext(C);return e.useEffect((function(){var e;if(!(null==i?void 0:i.registerHostedField))throw new Error("The HostedField cannot be register in the PayPalHostedFieldsProvider parent component");i.registerHostedField(((e={})[n]={selector:r.selector,placeholder:r.placeholder,type:r.type,formatInput:r.formatInput,maskInput:r.maskInput,select:r.select,maxlength:r.maxlength,minlength:r.minlength,prefill:r.prefill,rejectUnsupportedCards:r.rejectUnsupportedCards},e))}),[]),a.default.createElement("div",P({},o))},exports.PayPalHostedFieldsProvider=function(t){var n=t.styles,r=t.createOrder,o=t.notEligibleError,i=t.children,c=O()[0],s=c.options,u=c.loadingStatus,l=e.useState(!0),p=l[0],f=l[1],E=e.useState(),v=E[0],S=E[1],T=e.useState(null)[1],A=e.useRef(null),m=e.useRef(),y=function(t){void 0===t&&(t={});var n=e.useRef(t);return[n,function(e){n.current=P(P({},n.current),e)}]}(),I=y[0],N=y[1];return e.useEffect((function(){var e;if(Y(Object.keys(I.current)),u===exports.SCRIPT_LOADING_STATE.RESOLVED){if(m.current=h(s[d]).HostedFields,!m.current)throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e[d],o=void 0===r?"paypal":r,a=n?"".concat(n,",hosted-fields"):"hosted-fields",i="Unable to render <PayPalHostedFieldsProvider /> because window.".concat(o,".HostedFields is undefined.");return n.includes("hosted-fields")||(i+="\nTo fix the issue, add 'hosted-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '".concat(a,"'}}>")),i}(((e={components:s.components})[d]=s[d],e)));if(!m.current.isEligible())return f(!1);v&&v.teardown(),m.current.render({createOrder:r,styles:n,fields:I.current}).then((function(e){A.current&&S(e)})).catch((function(e){T((function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. ".concat(e))}))}))}}),[u,n]),a.default.createElement("div",{ref:A},p?a.default.createElement(C.Provider,{value:{cardFields:v,registerHostedField:N}},i):o)},exports.PayPalMarks=H,exports.PayPalMessages=j,exports.PayPalScriptProvider=function(t){var n,r=t.options,o=void 0===r?{"client-id":"test"}:r,c=t.children,s=t.deferLoading,d=void 0!==s&&s,p=e.useReducer(m,{options:P(P({},o),(n={},n[i]="".concat(T(o)),n[u]=l,n)),loadingStatus:d?exports.SCRIPT_LOADING_STATE.INITIAL:exports.SCRIPT_LOADING_STATE.PENDING}),f=p[0],E=p[1];return e.useEffect((function(){if(!1===d&&f.loadingStatus===exports.SCRIPT_LOADING_STATE.INITIAL)return E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.PENDING});if(f.loadingStatus===exports.SCRIPT_LOADING_STATE.PENDING){var e=!0;return g(f.options).then((function(){e&&E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.RESOLVED})})).catch((function(t){console.error("".concat("Failed to load the PayPal JS SDK script."," ").concat(t)),e&&E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.REJECTED})})),function(){e=!1}}}),[f.options,d,f.loadingStatus]),a.default.createElement(y.Provider,{value:P(P({},f),{dispatch:E})},c)},exports.ScriptContext=y,exports.destroySDKScript=A,exports.getScriptID=T,exports.scriptReducer=m,exports.usePayPalHostedFields=function(){return e.useContext(C)},exports.usePayPalScriptReducer=N,exports.useScriptProviderContext=O; |
/*! | ||
* react-paypal-js v7.6.2 (2022-05-09T20:57:39.607Z) | ||
* react-paypal-js v7.7.0 (2022-05-10T17:43:04.667Z) | ||
* Copyright 2020-present, PayPal, Inc. All rights reserved. | ||
@@ -825,3 +825,4 @@ * | ||
braintreeNamespace = _a.braintreeNamespace, | ||
buttonProps = __rest(_a, ["className", "disabled", "children", "forceReRender", "braintreeNamespace"]); | ||
merchantAccountId = _a.merchantAccountId, | ||
buttonProps = __rest(_a, ["className", "disabled", "children", "forceReRender", "braintreeNamespace", "merchantAccountId"]); | ||
@@ -842,5 +843,8 @@ var _e = useState(null), | ||
}).then(function (clientInstance) { | ||
return braintree.paypalCheckout.create({ | ||
var merchantProp = merchantAccountId ? { | ||
merchantAccountId: merchantAccountId | ||
} : {}; | ||
return braintree.paypalCheckout.create(__assign(__assign({}, merchantProp), { | ||
client: clientInstance | ||
}); | ||
})); | ||
}).then(function (paypalCheckoutInstance) { | ||
@@ -847,0 +851,0 @@ dispatch({ |
/*! | ||
* react-paypal-js v7.6.2 (2022-05-09T20:57:39.607Z) | ||
* react-paypal-js v7.7.0 (2022-05-10T17:43:04.667Z) | ||
* 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}from"react";var c,l,s;!function(e){e.INITIAL="initial",e.PENDING="pending",e.REJECTED="rejected",e.RESOLVED="resolved"}(c||(c={})),function(e){e.LOADING_STATUS="setLoadingStatus",e.RESET_OPTIONS="resetOptions",e.SET_BRAINTREE_INSTANCE="braintreeInstance"}(l||(l={})),function(e){e.NUMBER="number",e.CVV="cvv",e.EXPIRATION_DATE="expirationDate",e.EXPIRATION_MONTH="expirationMonth",e.EXPIRATION_YEAR="expirationYear",e.POSTAL_CODE="postalCode"}(s||(s={}));var u="data-react-paypal-script-id",d="data-client-token",f="data-user-id-token",p="data-sdk-integration-source",v="react-paypal-js",h="data-namespace",m="https://js.braintreegateway.com/web/".concat("3.84.0","/js/client.min.js"),y="https://js.braintreegateway.com/web/".concat("3.84.0","/js/paypal-checkout.min.js"),E=function(){return(E=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 P(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 w(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 b(e){return void 0===e&&(e="paypal"),window[e]}function N(e){var t=e.reactComponentName,n=e.sdkComponentKey,r=e.sdkRequestedComponents,o=void 0===r?"":r,a=e.sdkDataNamespace,i=void 0===a?"paypal":a,c=n.charAt(0).toUpperCase().concat(n.substring(1)),l="Unable to render <".concat(t," /> because window.").concat(i,".").concat(c," is undefined.");if(!o.includes(n)){var s=[o,n].filter(Boolean).join();l+="\nTo fix the issue, add '".concat(n,"' to the list of components passed to the parent PayPalScriptProvider:")+"\n`<PayPalScriptProvider options={{ components: '".concat(s,"'}}>`.")}return l}function g(e){return"react-paypal-js-".concat(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 A(e){var t=self.document.querySelector("script[".concat(u,'="').concat(e,'"]'));(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function I(e,t){var n;switch(t.type){case l.LOADING_STATUS:return E(E({},e),{loadingStatus:t.value});case l.RESET_OPTIONS:return A(e.options[u]),delete t.value[u],E(E({},e),{loadingStatus:c.PENDING,options:E(E({},t.value),(n={},n[u]="".concat(g(t.value)),n[p]=v,n))});case l.SET_BRAINTREE_INSTANCE:return E(E({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var S=t(null);function O(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 T(){var e=O(n(S));return[E(E({},e),{isInitial:e.loadingStatus===c.INITIAL,isPending:e.loadingStatus===c.PENDING,isResolved:e.loadingStatus===c.RESOLVED,isRejected:e.loadingStatus===c.REJECTED}),e.dispatch]}function R(){var e=function(e){var t,n;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t[d])&&!(null===(n=null==e?void 0:e.options)||void 0===n?void 0:n[f]))throw new Error("Invalid authorization data. Use data-client-token or data-user-id-token to authorize.");return e}(O(n(S)));return[e,e.dispatch]}var k=t({});function C(){return n(k)}var D=function(t){var n=t.className,i=void 0===n?"":n,c=t.disabled,l=void 0!==c&&c,s=t.children,u=t.forceReRender,d=void 0===u?[]:u,f=P(t,["className","disabled","children","forceReRender"]),p=l?{opacity:.38}:{},v="".concat(i," ").concat(l?"paypal-buttons-disabled":"").trim(),m=r(null),y=r(null),g=T()[0],A=g.isResolved,I=g.options,S=o(null),O=S[0],R=S[1],k=o(!0),C=k[0],j=k[1],L=o(null)[1];function F(){null!==y.current&&y.current.close().catch((function(){}))}return a((function(){if(!1===A)return F;var e=b(I[h]);if(void 0===e||void 0===e.Buttons)return L((function(){throw new Error(N({reactComponentName:D.displayName,sdkComponentKey:"buttons",sdkRequestedComponents:I.components,sdkDataNamespace:I[h]}))})),F;try{y.current=e.Buttons(E(E({},f),{onInit:function(e,t){R(t),"function"==typeof f.onInit&&f.onInit(e,t)}}))}catch(e){return L((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: ".concat(e))}))}return!1===y.current.isEligible()?(j(!1),F):m.current?(y.current.render(m.current).catch((function(e){null!==m.current&&0!==m.current.children.length&&L((function(){throw new Error("Failed to render <PayPalButtons /> component. ".concat(e))}))})),F):F}),w(w([A],d,!0),[f.fundingSource],!1)),a((function(){null!==O&&(!0===l?O.disable().catch((function(){})):O.enable().catch((function(){})))}),[l,O]),e.createElement(e.Fragment,null,C?e.createElement("div",{ref:m,style:p,className:v}):s)};function j(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL),function(e){var t=e["merchant-id"],n=e["data-merchant-id"],r="",o="";Array.isArray(t)?t.length>1?(r="*",o=t.toString()):r=t.toString():"string"==typeof t&&t.length>0?r=t:"string"==typeof n&&n.length>0&&(r="*",o=n);e["merchant-id"]=r,e["data-merchant-id"]=o}(e);var n=Object.keys(e).filter((function(t){return void 0!==e[t]&&null!==e[t]&&""!==e[t]})).reduce((function(t,n){var r=e[n].toString();return"data-"===n.substring(0,5)?t.dataAttributes[n]=r:t.queryParams[n]=r,t}),{queryParams:{},dataAttributes:{}}),r=n.queryParams,o=n.dataAttributes;return{url:"".concat(t,"?").concat(L(r)),dataAttributes:o}}function L(e){var t="";return Object.keys(e).forEach((function(n){0!==t.length&&(t+="&"),t+=n+"="+e[n]})),t}function F(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 B(e,t){if(void 0===t&&(t=U()),x(e,t),"undefined"==typeof window)return t.resolve(null);var n=j(e),r=n.url,o=n.dataAttributes,a=o["data-namespace"]||"paypal",i=_(a);return function(e,t){var n=document.querySelector('script[src="'.concat(e,'"]'));if(null===n)return null;var r=F(e,t),o=n.cloneNode();if(delete o.dataset.uidAuto,Object.keys(o.dataset).length!==Object.keys(r.dataset).length)return null;var a=!0;return Object.keys(o.dataset).forEach((function(e){o.dataset[e]!==r.dataset[e]&&(a=!1)})),a?n:null}(r,o)&&i?t.resolve(i):M({url:r,attributes:o},t).then((function(){var e=_(a);if(e)return e;throw new Error("The window.".concat(a," global variable is not available."))}))}function M(e,t){void 0===t&&(t=U()),x(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=F(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(){var e=new Error('The script "'.concat(n,'" failed to load.'));return window.fetch?fetch(n).then((function(n){return 200===n.status&&t(e),n.text()})).then((function(e){var n=function(e){var t=e.split("/* Original Error:")[1];return t?t.replace(/\n/g,"").replace("*/","").trim():e}(e);t(new Error(n))})).catch((function(e){t(e)})):t(e)}})}))}function U(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function _(e){return window[e]}function x(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.")}D.displayName="PayPalButtons";var H=function(e){return e&&function(e){var t,n;if("function"!=typeof(null===(t=null==e?void 0:e.client)||void 0===t?void 0:t.create)&&"function"!=typeof(null===(n=null==e?void 0:e.paypalCheckout)||void 0===n?void 0:n.create))throw new Error("The braintreeNamespace property is not a valid BraintreeNamespace type.");return!0}(e)?Promise.resolve(e):Promise.all([M({url:m}),M({url:y})]).then((function(){return void 0===e&&(e="braintree"),window[e];var e}))},G=function(t){var n=t.className,r=void 0===n?"":n,i=t.disabled,c=void 0!==i&&i,s=t.children,u=t.forceReRender,p=void 0===u?[]:u,v=t.braintreeNamespace,h=P(t,["className","disabled","children","forceReRender","braintreeNamespace"]),m=o(null)[1],y=R(),w=y[0],b=y[1];return a((function(){H(v).then((function(e){var t=w.options[f],n=w.options[d];return e.client.create({authorization:t||n}).then((function(t){return e.paypalCheckout.create({client:t})})).then((function(e){b({type:l.SET_BRAINTREE_INSTANCE,value:e})}))})).catch((function(e){m((function(){throw new Error("".concat("Failed to load the PayPal JS SDK script."," ").concat(e))}))}))}),[w.options]),e.createElement(e.Fragment,null,w.braintreePayPalCheckoutInstance&&e.createElement(D,E({className:r,disabled:c,forceReRender:p},function(e,t){var n=e.createOrder,r=e.createBillingAgreement,o=e.onApprove;return"function"==typeof n&&(e.createOrder=function(e,r){return n(e,E(E({},r),{braintree:t}))}),"function"==typeof r&&(e.createBillingAgreement=function(e,n){return r(e,E(E({},n),{braintree:t}))}),"function"==typeof o&&(e.onApprove=function(e,n){return o(e,E(E({},n),{braintree:t}))}),E({},e)}(h,w.braintreePayPalCheckoutInstance)),s))},K=function(t){var n=t.className,i=void 0===n?"":n,c=t.children,l=P(t,["className","children"]),s=T()[0],u=s.isResolved,d=s.options,f=r(null),p=o(!0),v=p[0],m=p[1],y=o(null)[1];return a((function(){if(!1!==u){var e=b(d[h]);if(void 0===e||void 0===e.Marks)return y((function(){throw new Error(N({reactComponentName:K.displayName,sdkComponentKey:"marks",sdkRequestedComponents:d.components,sdkDataNamespace:d[h]}))}));!function(e){var t=f.current;if(!t||!e.isEligible())return m(!1);t.firstChild&&t.removeChild(t.firstChild),e.render(t).catch((function(e){null!==t&&0!==t.children.length&&y((function(){throw new Error("Failed to render <PayPalMarks /> component. ".concat(e))}))}))}(e.Marks(E({},l)))}}),[u,l.fundingSource]),e.createElement(e.Fragment,null,v?e.createElement("div",{ref:f,className:i}):c)};K.displayName="PayPalMarks";var Y=function(t){var n=t.className,i=void 0===n?"":n,c=t.forceReRender,l=void 0===c?[]:c,s=P(t,["className","forceReRender"]),u=T()[0],d=u.isResolved,f=u.options,p=r(null),v=r(null),m=o(null)[1];return a((function(){if(!1!==d){var e=b(f[h]);if(void 0===e||void 0===e.Messages)return m((function(){throw new Error(N({reactComponentName:Y.displayName,sdkComponentKey:"messages",sdkRequestedComponents:f.components,sdkDataNamespace:f[h]}))}));v.current=e.Messages(E({},s)),v.current.render(p.current).catch((function(e){null!==p.current&&0!==p.current.children.length&&m((function(){throw new Error("Failed to render <PayPalMessages /> component. ".concat(e))}))}))}}),w([d],l,!0)),e.createElement("div",{ref:p,className:i})};Y.displayName="PayPalMessages";var V=function(t){var n,r=t.options,o=void 0===r?{"client-id":"test"}:r,s=t.children,d=t.deferLoading,f=void 0!==d&&d,h=i(I,{options:E(E({},o),(n={},n[u]="".concat(g(o)),n[p]=v,n)),loadingStatus:f?c.INITIAL:c.PENDING}),m=h[0],y=h[1];return a((function(){if(!1===f&&m.loadingStatus===c.INITIAL)return y({type:l.LOADING_STATUS,value:c.PENDING});if(m.loadingStatus===c.PENDING){var e=!0;return B(m.options).then((function(){e&&y({type:l.LOADING_STATUS,value:c.RESOLVED})})).catch((function(t){console.error("".concat("Failed to load the PayPal JS SDK script."," ").concat(t)),e&&y({type:l.LOADING_STATUS,value:c.REJECTED})})),function(){e=!1}}}),[m.options,f,m.loadingStatus]),e.createElement(S.Provider,{value:E(E({},m),{dispatch:y})},s)},q=function(e){if(!e.includes(s.NUMBER)||!e.includes(s.CVV)||function(e){return!e.includes(s.EXPIRATION_DATE)&&!e.includes(s.EXPIRATION_MONTH)&&!e.includes(s.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){q(e),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(e)},z=function(t){var n=t.styles,i=t.createOrder,l=t.notEligibleError,s=t.children,u=R()[0],d=u.options,f=u.loadingStatus,p=o(!0),v=p[0],m=p[1],y=o(),P=y[0],w=y[1],N=o(null)[1],g=r(null),A=r(),I=function(e){void 0===e&&(e={});var t=r(e);return[t,function(e){t.current=E(E({},t.current),e)}]}(),S=I[0],O=I[1];return a((function(){var e;if(X(Object.keys(S.current)),f===c.RESOLVED){if(A.current=b(d[h]).HostedFields,!A.current)throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e[h],o=void 0===r?"paypal":r,a=n?"".concat(n,",hosted-fields"):"hosted-fields",i="Unable to render <PayPalHostedFieldsProvider /> because window.".concat(o,".HostedFields is undefined.");return n.includes("hosted-fields")||(i+="\nTo fix the issue, add 'hosted-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '".concat(a,"'}}>")),i}(((e={components:d.components})[h]=d[h],e)));if(!A.current.isEligible())return m(!1);P&&P.teardown(),A.current.render({createOrder:i,styles:n,fields:S.current}).then((function(e){g.current&&w(e)})).catch((function(e){N((function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. ".concat(e))}))}))}}),[f,n]),e.createElement("div",{ref:g},v?e.createElement(k.Provider,{value:{cardFields:P,registerHostedField:O}},s):l)},J=function(t){var r=t.hostedFieldType,o=t.options,i=P(t,["hostedFieldType","options"]),c=n(k);return a((function(){var e;if(!(null==c?void 0:c.registerHostedField))throw new Error("The HostedField cannot be register in the PayPalHostedFieldsProvider parent component");c.registerHostedField(((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))}),[]),e.createElement("div",E({},i))},W={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",MULTIBLANCO:"multiblanco"};export{G as BraintreePayPalButtons,l as DISPATCH_ACTION,W as FUNDING,s as PAYPAL_HOSTED_FIELDS_TYPES,D as PayPalButtons,J as PayPalHostedField,z as PayPalHostedFieldsProvider,K as PayPalMarks,Y as PayPalMessages,V as PayPalScriptProvider,c as SCRIPT_LOADING_STATE,S as ScriptContext,A as destroySDKScript,g as getScriptID,I as scriptReducer,C as usePayPalHostedFields,T as usePayPalScriptReducer,R as useScriptProviderContext}; | ||
import e,{createContext as t,useContext as n,useRef as r,useState as o,useEffect as a,useReducer as i}from"react";var c,l,u;!function(e){e.INITIAL="initial",e.PENDING="pending",e.REJECTED="rejected",e.RESOLVED="resolved"}(c||(c={})),function(e){e.LOADING_STATUS="setLoadingStatus",e.RESET_OPTIONS="resetOptions",e.SET_BRAINTREE_INSTANCE="braintreeInstance"}(l||(l={})),function(e){e.NUMBER="number",e.CVV="cvv",e.EXPIRATION_DATE="expirationDate",e.EXPIRATION_MONTH="expirationMonth",e.EXPIRATION_YEAR="expirationYear",e.POSTAL_CODE="postalCode"}(u||(u={}));var s="data-react-paypal-script-id",d="data-client-token",f="data-user-id-token",p="data-sdk-integration-source",v="react-paypal-js",h="data-namespace",m="https://js.braintreegateway.com/web/".concat("3.84.0","/js/client.min.js"),y="https://js.braintreegateway.com/web/".concat("3.84.0","/js/paypal-checkout.min.js"),E=function(){return(E=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 P(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 w(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 b(e){return void 0===e&&(e="paypal"),window[e]}function N(e){var t=e.reactComponentName,n=e.sdkComponentKey,r=e.sdkRequestedComponents,o=void 0===r?"":r,a=e.sdkDataNamespace,i=void 0===a?"paypal":a,c=n.charAt(0).toUpperCase().concat(n.substring(1)),l="Unable to render <".concat(t," /> because window.").concat(i,".").concat(c," is undefined.");if(!o.includes(n)){var u=[o,n].filter(Boolean).join();l+="\nTo fix the issue, add '".concat(n,"' to the list of components passed to the parent PayPalScriptProvider:")+"\n`<PayPalScriptProvider options={{ components: '".concat(u,"'}}>`.")}return l}function g(e){return"react-paypal-js-".concat(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 A(e){var t=self.document.querySelector("script[".concat(s,'="').concat(e,'"]'));(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function I(e,t){var n;switch(t.type){case l.LOADING_STATUS:return E(E({},e),{loadingStatus:t.value});case l.RESET_OPTIONS:return A(e.options[s]),delete t.value[s],E(E({},e),{loadingStatus:c.PENDING,options:E(E({},t.value),(n={},n[s]="".concat(g(t.value)),n[p]=v,n))});case l.SET_BRAINTREE_INSTANCE:return E(E({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var S=t(null);function O(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 T(){var e=O(n(S));return[E(E({},e),{isInitial:e.loadingStatus===c.INITIAL,isPending:e.loadingStatus===c.PENDING,isResolved:e.loadingStatus===c.RESOLVED,isRejected:e.loadingStatus===c.REJECTED}),e.dispatch]}function R(){var e=function(e){var t,n;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t[d])&&!(null===(n=null==e?void 0:e.options)||void 0===n?void 0:n[f]))throw new Error("Invalid authorization data. Use data-client-token or data-user-id-token to authorize.");return e}(O(n(S)));return[e,e.dispatch]}var k=t({});function C(){return n(k)}var D=function(t){var n=t.className,i=void 0===n?"":n,c=t.disabled,l=void 0!==c&&c,u=t.children,s=t.forceReRender,d=void 0===s?[]:s,f=P(t,["className","disabled","children","forceReRender"]),p=l?{opacity:.38}:{},v="".concat(i," ").concat(l?"paypal-buttons-disabled":"").trim(),m=r(null),y=r(null),g=T()[0],A=g.isResolved,I=g.options,S=o(null),O=S[0],R=S[1],k=o(!0),C=k[0],j=k[1],L=o(null)[1];function F(){null!==y.current&&y.current.close().catch((function(){}))}return a((function(){if(!1===A)return F;var e=b(I[h]);if(void 0===e||void 0===e.Buttons)return L((function(){throw new Error(N({reactComponentName:D.displayName,sdkComponentKey:"buttons",sdkRequestedComponents:I.components,sdkDataNamespace:I[h]}))})),F;try{y.current=e.Buttons(E(E({},f),{onInit:function(e,t){R(t),"function"==typeof f.onInit&&f.onInit(e,t)}}))}catch(e){return L((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: ".concat(e))}))}return!1===y.current.isEligible()?(j(!1),F):m.current?(y.current.render(m.current).catch((function(e){null!==m.current&&0!==m.current.children.length&&L((function(){throw new Error("Failed to render <PayPalButtons /> component. ".concat(e))}))})),F):F}),w(w([A],d,!0),[f.fundingSource],!1)),a((function(){null!==O&&(!0===l?O.disable().catch((function(){})):O.enable().catch((function(){})))}),[l,O]),e.createElement(e.Fragment,null,C?e.createElement("div",{ref:m,style:p,className:v}):u)};function j(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL),function(e){var t=e["merchant-id"],n=e["data-merchant-id"],r="",o="";Array.isArray(t)?t.length>1?(r="*",o=t.toString()):r=t.toString():"string"==typeof t&&t.length>0?r=t:"string"==typeof n&&n.length>0&&(r="*",o=n);e["merchant-id"]=r,e["data-merchant-id"]=o}(e);var n=Object.keys(e).filter((function(t){return void 0!==e[t]&&null!==e[t]&&""!==e[t]})).reduce((function(t,n){var r=e[n].toString();return"data-"===n.substring(0,5)?t.dataAttributes[n]=r:t.queryParams[n]=r,t}),{queryParams:{},dataAttributes:{}}),r=n.queryParams,o=n.dataAttributes;return{url:"".concat(t,"?").concat(L(r)),dataAttributes:o}}function L(e){var t="";return Object.keys(e).forEach((function(n){0!==t.length&&(t+="&"),t+=n+"="+e[n]})),t}function F(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 B(e,t){if(void 0===t&&(t=U()),x(e,t),"undefined"==typeof window)return t.resolve(null);var n=j(e),r=n.url,o=n.dataAttributes,a=o["data-namespace"]||"paypal",i=_(a);return function(e,t){var n=document.querySelector('script[src="'.concat(e,'"]'));if(null===n)return null;var r=F(e,t),o=n.cloneNode();if(delete o.dataset.uidAuto,Object.keys(o.dataset).length!==Object.keys(r.dataset).length)return null;var a=!0;return Object.keys(o.dataset).forEach((function(e){o.dataset[e]!==r.dataset[e]&&(a=!1)})),a?n:null}(r,o)&&i?t.resolve(i):M({url:r,attributes:o},t).then((function(){var e=_(a);if(e)return e;throw new Error("The window.".concat(a," global variable is not available."))}))}function M(e,t){void 0===t&&(t=U()),x(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=F(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(){var e=new Error('The script "'.concat(n,'" failed to load.'));return window.fetch?fetch(n).then((function(n){return 200===n.status&&t(e),n.text()})).then((function(e){var n=function(e){var t=e.split("/* Original Error:")[1];return t?t.replace(/\n/g,"").replace("*/","").trim():e}(e);t(new Error(n))})).catch((function(e){t(e)})):t(e)}})}))}function U(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function _(e){return window[e]}function x(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.")}D.displayName="PayPalButtons";var H=function(e){return e&&function(e){var t,n;if("function"!=typeof(null===(t=null==e?void 0:e.client)||void 0===t?void 0:t.create)&&"function"!=typeof(null===(n=null==e?void 0:e.paypalCheckout)||void 0===n?void 0:n.create))throw new Error("The braintreeNamespace property is not a valid BraintreeNamespace type.");return!0}(e)?Promise.resolve(e):Promise.all([M({url:m}),M({url:y})]).then((function(){return void 0===e&&(e="braintree"),window[e];var e}))},G=function(t){var n=t.className,r=void 0===n?"":n,i=t.disabled,c=void 0!==i&&i,u=t.children,s=t.forceReRender,p=void 0===s?[]:s,v=t.braintreeNamespace,h=t.merchantAccountId,m=P(t,["className","disabled","children","forceReRender","braintreeNamespace","merchantAccountId"]),y=o(null)[1],w=R(),b=w[0],N=w[1];return a((function(){H(v).then((function(e){var t=b.options[f],n=b.options[d];return e.client.create({authorization:t||n}).then((function(t){var n=h?{merchantAccountId:h}:{};return e.paypalCheckout.create(E(E({},n),{client:t}))})).then((function(e){N({type:l.SET_BRAINTREE_INSTANCE,value:e})}))})).catch((function(e){y((function(){throw new Error("".concat("Failed to load the PayPal JS SDK script."," ").concat(e))}))}))}),[b.options]),e.createElement(e.Fragment,null,b.braintreePayPalCheckoutInstance&&e.createElement(D,E({className:r,disabled:c,forceReRender:p},function(e,t){var n=e.createOrder,r=e.createBillingAgreement,o=e.onApprove;return"function"==typeof n&&(e.createOrder=function(e,r){return n(e,E(E({},r),{braintree:t}))}),"function"==typeof r&&(e.createBillingAgreement=function(e,n){return r(e,E(E({},n),{braintree:t}))}),"function"==typeof o&&(e.onApprove=function(e,n){return o(e,E(E({},n),{braintree:t}))}),E({},e)}(m,b.braintreePayPalCheckoutInstance)),u))},K=function(t){var n=t.className,i=void 0===n?"":n,c=t.children,l=P(t,["className","children"]),u=T()[0],s=u.isResolved,d=u.options,f=r(null),p=o(!0),v=p[0],m=p[1],y=o(null)[1];return a((function(){if(!1!==s){var e=b(d[h]);if(void 0===e||void 0===e.Marks)return y((function(){throw new Error(N({reactComponentName:K.displayName,sdkComponentKey:"marks",sdkRequestedComponents:d.components,sdkDataNamespace:d[h]}))}));!function(e){var t=f.current;if(!t||!e.isEligible())return m(!1);t.firstChild&&t.removeChild(t.firstChild),e.render(t).catch((function(e){null!==t&&0!==t.children.length&&y((function(){throw new Error("Failed to render <PayPalMarks /> component. ".concat(e))}))}))}(e.Marks(E({},l)))}}),[s,l.fundingSource]),e.createElement(e.Fragment,null,v?e.createElement("div",{ref:f,className:i}):c)};K.displayName="PayPalMarks";var Y=function(t){var n=t.className,i=void 0===n?"":n,c=t.forceReRender,l=void 0===c?[]:c,u=P(t,["className","forceReRender"]),s=T()[0],d=s.isResolved,f=s.options,p=r(null),v=r(null),m=o(null)[1];return a((function(){if(!1!==d){var e=b(f[h]);if(void 0===e||void 0===e.Messages)return m((function(){throw new Error(N({reactComponentName:Y.displayName,sdkComponentKey:"messages",sdkRequestedComponents:f.components,sdkDataNamespace:f[h]}))}));v.current=e.Messages(E({},u)),v.current.render(p.current).catch((function(e){null!==p.current&&0!==p.current.children.length&&m((function(){throw new Error("Failed to render <PayPalMessages /> component. ".concat(e))}))}))}}),w([d],l,!0)),e.createElement("div",{ref:p,className:i})};Y.displayName="PayPalMessages";var V=function(t){var n,r=t.options,o=void 0===r?{"client-id":"test"}:r,u=t.children,d=t.deferLoading,f=void 0!==d&&d,h=i(I,{options:E(E({},o),(n={},n[s]="".concat(g(o)),n[p]=v,n)),loadingStatus:f?c.INITIAL:c.PENDING}),m=h[0],y=h[1];return a((function(){if(!1===f&&m.loadingStatus===c.INITIAL)return y({type:l.LOADING_STATUS,value:c.PENDING});if(m.loadingStatus===c.PENDING){var e=!0;return B(m.options).then((function(){e&&y({type:l.LOADING_STATUS,value:c.RESOLVED})})).catch((function(t){console.error("".concat("Failed to load the PayPal JS SDK script."," ").concat(t)),e&&y({type:l.LOADING_STATUS,value:c.REJECTED})})),function(){e=!1}}}),[m.options,f,m.loadingStatus]),e.createElement(S.Provider,{value:E(E({},m),{dispatch:y})},u)},q=function(e){if(!e.includes(u.NUMBER)||!e.includes(u.CVV)||function(e){return!e.includes(u.EXPIRATION_DATE)&&!e.includes(u.EXPIRATION_MONTH)&&!e.includes(u.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){q(e),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(e)},z=function(t){var n=t.styles,i=t.createOrder,l=t.notEligibleError,u=t.children,s=R()[0],d=s.options,f=s.loadingStatus,p=o(!0),v=p[0],m=p[1],y=o(),P=y[0],w=y[1],N=o(null)[1],g=r(null),A=r(),I=function(e){void 0===e&&(e={});var t=r(e);return[t,function(e){t.current=E(E({},t.current),e)}]}(),S=I[0],O=I[1];return a((function(){var e;if(X(Object.keys(S.current)),f===c.RESOLVED){if(A.current=b(d[h]).HostedFields,!A.current)throw new Error(function(e){var t=e.components,n=void 0===t?"":t,r=e[h],o=void 0===r?"paypal":r,a=n?"".concat(n,",hosted-fields"):"hosted-fields",i="Unable to render <PayPalHostedFieldsProvider /> because window.".concat(o,".HostedFields is undefined.");return n.includes("hosted-fields")||(i+="\nTo fix the issue, add 'hosted-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '".concat(a,"'}}>")),i}(((e={components:d.components})[h]=d[h],e)));if(!A.current.isEligible())return m(!1);P&&P.teardown(),A.current.render({createOrder:i,styles:n,fields:S.current}).then((function(e){g.current&&w(e)})).catch((function(e){N((function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. ".concat(e))}))}))}}),[f,n]),e.createElement("div",{ref:g},v?e.createElement(k.Provider,{value:{cardFields:P,registerHostedField:O}},u):l)},J=function(t){var r=t.hostedFieldType,o=t.options,i=P(t,["hostedFieldType","options"]),c=n(k);return a((function(){var e;if(!(null==c?void 0:c.registerHostedField))throw new Error("The HostedField cannot be register in the PayPalHostedFieldsProvider parent component");c.registerHostedField(((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))}),[]),e.createElement("div",E({},i))},W={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",MULTIBLANCO:"multiblanco"};export{G as BraintreePayPalButtons,l as DISPATCH_ACTION,W as FUNDING,u as PAYPAL_HOSTED_FIELDS_TYPES,D as PayPalButtons,J as PayPalHostedField,z as PayPalHostedFieldsProvider,K as PayPalMarks,Y as PayPalMessages,V as PayPalScriptProvider,c as SCRIPT_LOADING_STATE,S as ScriptContext,A as destroySDKScript,g as getScriptID,I as scriptReducer,C as usePayPalHostedFields,T as usePayPalScriptReducer,R as useScriptProviderContext}; |
@@ -34,2 +34,3 @@ import type { PayPalButtonsComponentProps } from "./paypalButtonTypes"; | ||
braintreeNamespace?: BraintreeNamespace; | ||
merchantAccountId?: string; | ||
} | ||
@@ -36,0 +37,0 @@ export declare type BraintreeNamespace = { |
{ | ||
"name": "@paypal/react-paypal-js", | ||
"version": "7.6.2", | ||
"version": "7.7.0", | ||
"description": "React components for the PayPal JS SDK", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
208334
3527