@paypal/react-paypal-js
Version:
React components for the PayPal JS SDK
18 lines (17 loc) • 23 kB
JavaScript
/*!
* react-paypal-js v9.2.0 (2026-04-27T17:34:47.479Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
;var e,t,r,n=require("react");exports.SCRIPT_LOADING_STATE=void 0,(e=exports.SCRIPT_LOADING_STATE||(exports.SCRIPT_LOADING_STATE={})).INITIAL="initial",e.PENDING="pending",e.REJECTED="rejected",e.RESOLVED="resolved",exports.DISPATCH_ACTION=void 0,(t=exports.DISPATCH_ACTION||(exports.DISPATCH_ACTION={})).LOADING_STATUS="setLoadingStatus",t.RESET_OPTIONS="resetOptions",t.SET_BRAINTREE_INSTANCE="braintreeInstance",exports.PAYPAL_HOSTED_FIELDS_TYPES=void 0,(r=exports.PAYPAL_HOSTED_FIELDS_TYPES||(exports.PAYPAL_HOSTED_FIELDS_TYPES={})).NUMBER="number",r.CVV="cvv",r.EXPIRATION_DATE="expirationDate",r.EXPIRATION_MONTH="expirationMonth",r.EXPIRATION_YEAR="expirationYear",r.POSTAL_CODE="postalCode";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},o(e,t)};var a=function(){return a=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},a.apply(this,arguments)};function i(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"==typeof SuppressedError&&SuppressedError;var s="data-react-paypal-script-id",l="dataClientToken",u="dataJsSdkLibrary",d="react-paypal-js",p="dataNamespace",f="dataSdkIntegrationSource",v="dataUserIdToken",m="Failed to load the PayPal JS SDK script.",E="3.117.0",P="https://js.braintreegateway.com/web/".concat(E,"/js/client.min.js"),h="https://js.braintreegateway.com/web/".concat(E,"/js/paypal-checkout.min.js"),y="paypal";function S(e){return void 0===e&&(e=y),window[e]}function T(e){var t=e.reactComponentName,r=e.sdkComponentKey,n=e.sdkRequestedComponents,o=void 0===n?"":n,a=e.sdkDataNamespace,i=void 0===a?y:a,c=r.charAt(0).toUpperCase().concat(r.substring(1)),s="Unable to render <".concat(t," /> because window.").concat(i,".").concat(c," is undefined."),l="string"==typeof o?o:o.join(",");if(!l.includes(r)){var u=[l,r].filter(Boolean).join();s+="\nTo fix the issue, add '".concat(r,"' to the list of components passed to the parent PayPalScriptProvider:")+"\n`<PayPalScriptProvider options={{ components: '".concat(u,"'}}>`.")}return s}function A(e){var t=e,r=s;t[r];var n=i(t,[r+""]);return"react-paypal-js-".concat(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(n)))}function I(e){var t=self.document.querySelector("script[".concat(s,'="').concat(e,'"]'));(null==t?void 0:t.parentNode)&&t.parentNode.removeChild(t)}function N(e,t){var r,n;switch(t.type){case exports.DISPATCH_ACTION.LOADING_STATUS:return"object"==typeof t.value?a(a({},e),{loadingStatus:t.value.state,loadingStatusErrorMessage:t.value.message}):a(a({},e),{loadingStatus:t.value});case exports.DISPATCH_ACTION.RESET_OPTIONS:return I(e.options[s]),a(a({},e),{loadingStatus:exports.SCRIPT_LOADING_STATE.PENDING,options:a(a((r={},r[f]=d,r),t.value),(n={},n[s]="".concat(A(t.value)),n))});case exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE:return a(a({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var C=n.createContext(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 b(){var e=O(n.useContext(C));return[a(a({},e),{isInitial:e.loadingStatus===exports.SCRIPT_LOADING_STATE.INITIAL,isPending:e.loadingStatus===exports.SCRIPT_LOADING_STATE.PENDING,isResolved:e.loadingStatus===exports.SCRIPT_LOADING_STATE.RESOLVED,isRejected:e.loadingStatus===exports.SCRIPT_LOADING_STATE.REJECTED}),e.dispatch]}function g(){var e=function(e){var t,r;if(!(null===(t=null==e?void 0:e.options)||void 0===t?void 0:t[l])&&!(null===(r=null==e?void 0:e.options)||void 0===r?void 0:r[v]))throw new Error("Invalid authorization data. Use dataClientToken or dataUserIdToken to authorize.");return e}(O(n.useContext(C)));return[e,e.dispatch]}var w=n.createContext({});function x(e){var t=n.useRef(new Proxy({},{get:function(e,t,r){return"function"==typeof e[t]?function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return e[t].apply(e,r)}:Reflect.get(e,t,r)}}));return t.current=Object.assign(t.current,e),t.current}var _=function(e){function t(t){var r=e.call(this,t)||this;return r.state={hasError:!1},r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(t,e),t.getDerivedStateFromError=function(){return{hasError:!0}},t.prototype.componentDidCatch=function(e,t){console.error("Error in PayPalButtons component:",e,t),"function"==typeof this.props.onError&&this.props.onError({message:e.message,name:e.name,stack:e.stack,componentStack:t.componentStack})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(n.Component),R=function(e){var t,r=e.className,o=void 0===r?"":r,s=e.disabled,l=void 0!==s&&s,u=e.children,d=e.forceReRender,f=void 0===d?[]:d,v=i(e,["className","disabled","children","forceReRender"]),m=l?{opacity:.38}:{},E="".concat(o," ").concat(l?"paypal-buttons-disabled":"").trim(),P=n.useRef(null),h=n.useRef(null),y=x(v),A=b()[0],I=A.isResolved,N=A.options,C=n.useState(null),O=C[0],g=C[1],w=n.useState(!0),_=w[0],R=w[1],F=n.useState(null)[1];function L(){null!==h.current&&h.current.close().catch(function(){})}return(null===(t=h.current)||void 0===t?void 0:t.updateProps)&&h.current.updateProps({message:v.message}),n.useEffect(function(){if(!1===I)return L;var e=S(N.dataNamespace);if(void 0===e||void 0===e.Buttons)return F(function(){throw new Error(T({reactComponentName:D.displayName,sdkComponentKey:"buttons",sdkRequestedComponents:N.components,sdkDataNamespace:N[p]}))}),L;try{h.current=e.Buttons(a(a({},y),{onInit:function(e,t){g(t),"function"==typeof v.onInit&&v.onInit(e,t)}}))}catch(e){return F(function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: ".concat(e))})}return!1===h.current.isEligible()?(R(!1),L):P.current?(h.current.render(P.current).catch(function(e){null!==P.current&&0!==P.current.children.length&&F(function(){throw new Error("Failed to render <PayPalButtons /> component. ".concat(e))})}),L):L},c(c([I],f,!0),[v.fundingSource],!1)),n.useEffect(function(){null!==O&&(!0===l?O.disable().catch(function(){}):O.enable().catch(function(){}))},[l,O]),n.createElement(n.Fragment,null,_?n.createElement("div",{ref:P,style:m,className:E}):u)};R.displayName="PayPalButtons";var D=function(e){return n.createElement(_,{onError:e.onError},n.createElement(R,a({},e)))};function F(e){var t=Object.prototype.hasOwnProperty.call(e,"sdkBaseUrl")?e.sdkBaseUrl:void 0,r=e.environment;e.sdkBaseUrl;var n=function(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}(e,["environment","sdkBaseUrl"]),o=t||function(e){return"sandbox"===e?"https://www.sandbox.paypal.com/sdk/js":"https://www.paypal.com/sdk/js"}(r),a=n,i=Object.keys(a).filter(function(e){return void 0!==a[e]&&null!==a[e]&&""!==a[e]}).reduce(function(e,t){var r,n=a[t].toString();return r=function(e,t){return(t?"-":"")+e.toLowerCase()},"data"===(t=t.replace(/[A-Z]+(?![a-z])|[A-Z]/g,r)).substring(0,4)||"crossorigin"===t?e.attributes[t]=n:e.queryParams[t]=n,e},{queryParams:{},attributes:{}}),c=i.queryParams,s=i.attributes;return c["merchant-id"]&&-1!==c["merchant-id"].indexOf(",")&&(s["data-merchant-id"]=c["merchant-id"],c["merchant-id"]="*"),{url:"".concat(o,"?").concat(L(c)),attributes:s}}function L(e){var t="";return Object.keys(e).forEach(function(r){0!==t.length&&(t+="&"),t+=r+"="+e[r]}),t}function k(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 j(e,t){if(void 0===t&&(t=Promise),G(e,t),"undefined"==typeof document)return t.resolve(null);var r=F(e),n=r.url,o=r.attributes,a=o["data-namespace"]||"paypal",i=B(a);return o["data-js-sdk-library"]||(o["data-js-sdk-library"]="paypal-js"),function(e,t){var r=document.querySelector('script[src="'.concat(e,'"]'));if(null===r)return null;var n=k(e,t),o=r.cloneNode();if(delete o.dataset.uidAuto,Object.keys(o.dataset).length!==Object.keys(n.dataset).length)return null;var a=!0;return Object.keys(o.dataset).forEach(function(e){o.dataset[e]!==n.dataset[e]&&(a=!1)}),a?r:null}(n,o)&&i?t.resolve(i):H({url:n,attributes:o},t).then(function(){var e=B(a);if(e)return e;throw new Error("The window.".concat(a," global variable is not available."))})}function H(e,t){void 0===t&&(t=Promise),G(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 document)return e();!function(e){var t=e.url,r=e.attributes,n=e.onSuccess,o=e.onError,a=k(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(){var e=new Error('The script "'.concat(r,'" failed to load. Check the HTTP status code and response body in DevTools to learn more.'));return t(e)}})})}function B(e){return window[e]}function G(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");var r=e.environment;if(r&&"production"!==r&&"sandbox"!==r)throw new Error('The `environment` option must be either "production" or "sandbox".');if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}D.displayName="PayPalButtons","function"==typeof SuppressedError&&SuppressedError;var Y=function(e){return e&&function(e){var t,r;if("function"!=typeof(null===(t=null==e?void 0:e.client)||void 0===t?void 0:t.create)&&"function"!=typeof(null===(r=null==e?void 0:e.paypalCheckout)||void 0===r?void 0:r.create))throw new Error("The braintreeNamespace property is not a valid BraintreeNamespace type.");return!0}(e)?Promise.resolve(e):Promise.all([H({url:P}),H({url:h})]).then(function(){return void 0===e&&(e="braintree"),window[e];var e})},U=function(e){var t=e.className,r=void 0===t?"":t,o=e.children,c=i(e,["className","children"]),s=b()[0],l=s.isResolved,u=s.options,d=n.useRef(null),f=n.useState(!0),v=f[0],m=f[1],E=n.useState(null)[1];return n.useEffect(function(){if(!1!==l){var e=S(u[p]);if(void 0===e||void 0===e.Marks)return E(function(){throw new Error(T({reactComponentName:U.displayName,sdkComponentKey:"marks",sdkRequestedComponents:u.components,sdkDataNamespace:u[p]}))});!function(e){var t=d.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&&E(function(){throw new Error("Failed to render <PayPalMarks /> component. ".concat(e))})})}(e.Marks(a({},c)))}},[l,c.fundingSource]),n.createElement(n.Fragment,null,v?n.createElement("div",{ref:d,className:r}):o)};U.displayName="PayPalMarks";var M=function(e){var t=e.className,r=void 0===t?"":t,o=e.forceReRender,s=void 0===o?[]:o,l=i(e,["className","forceReRender"]),u=b()[0],d=u.isResolved,f=u.options,v=n.useRef(null),m=n.useRef(null),E=n.useState(null)[1];return n.useEffect(function(){if(!1!==d){var e=S(f[p]);if(void 0===e||void 0===e.Messages)return E(function(){throw new Error(T({reactComponentName:M.displayName,sdkComponentKey:"messages",sdkRequestedComponents:f.components,sdkDataNamespace:f[p]}))});m.current=e.Messages(a({},l)),m.current.render(v.current).catch(function(e){null!==v.current&&0!==v.current.children.length&&E(function(){throw new Error("Failed to render <PayPalMessages /> component. ".concat(e))})})}},c([d],s,!0)),n.createElement("div",{ref:v,className:r})};M.displayName="PayPalMessages";var V=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")},q=function(e){V(e),function(e){if(e.length!==new Set(e).size)throw new Error("Cannot use duplicate HostedFields as children")}(e)};function X(){}var z=n.createContext({cardFieldsForm:null,fields:{},registerField:X,unregisterField:X}),K=function(){return n.useContext(z)},J=function(e){var t=e.children;return n.createElement("div",{style:{width:"100%"}},t)},Z=function(e){var t=e.className,r=e.fieldName,o=i(e,["className","fieldName"]),a=K(),c=a.cardFieldsForm,s=a.registerField,l=a.unregisterField,u=n.useRef(null),d=x(o.inputEvents),p=n.useState(null)[1];function f(){l(r)}return n.useEffect(function(){if(!c)return p(function(){throw new Error("Individual CardFields must be rendered inside the PayPalCardFieldsProvider")}),f;if(!u.current)return f;o.inputEvents&&(o.inputEvents=d);var e=s(r,o,c);return null==e||e.render(u.current).catch(function(e){(function(e){var t;return!!(null===(t=e.current)||void 0===t?void 0:t.children.length)})(u)&&p(function(){throw new Error("Failed to render <PayPal".concat(r," /> component. ").concat(e))})}),f},[]),n.createElement("div",{ref:u,className:t})},W=function(e){var t=e.children;return n.createElement("div",{style:{display:"flex",width:"100%"}},t)},Q={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",PAYU:"payu",BLIK:"blik",TRUSTLY:"trustly",OXXO:"oxxo",BOLETO:"boleto",BOLETOBANCARIO:"boletobancario",WECHATPAY:"wechatpay",MERCADOPAGO:"mercadopago",MULTIBANCO:"multibanco",SATISPAY:"satispay",PAIDY:"paidy",ZIMPLER:"zimpler",MAXIMA:"maxima"},$=Q;exports.BraintreePayPalButtons=function(e){var t=e.className,r=void 0===t?"":t,o=e.disabled,c=void 0!==o&&o,s=e.children,u=e.forceReRender,d=void 0===u?[]:u,p=e.braintreeNamespace,f=e.merchantAccountId,E=i(e,["className","disabled","children","forceReRender","braintreeNamespace","merchantAccountId"]),P=n.useState(null)[1],h=g(),y=h[0],S=h[1];return n.useEffect(function(){Y(p).then(function(e){var t=y.options[v],r=y.options[l];return e.client.create({authorization:t||r}).then(function(t){var r=f?{merchantAccountId:f}:{};return e.paypalCheckout.create(a(a({},r),{client:t}))}).then(function(e){S({type:exports.DISPATCH_ACTION.SET_BRAINTREE_INSTANCE,value:e})})}).catch(function(e){P(function(){throw new Error("".concat(m," ").concat(e))})})},[y.options]),n.createElement(n.Fragment,null,y.braintreePayPalCheckoutInstance&&n.createElement(D,a({className:r,disabled:c,forceReRender:d},function(e,t){var r=e.createOrder,n=e.createBillingAgreement,o=e.onApprove;return"function"==typeof r&&(e.createOrder=function(e,n){return r(e,a(a({},n),{braintree:t}))}),"function"==typeof n&&(e.createBillingAgreement=function(e,r){return n(e,a(a({},r),{braintree:t}))}),"function"==typeof o&&(e.onApprove=function(e,r){return o(e,a(a({},r),{braintree:t}))}),a({},e)}(E,y.braintreePayPalCheckoutInstance)),s))},exports.FUNDING=$,exports.PayPalButtons=D,exports.PayPalCVVField=function(e){return n.createElement(Z,a({fieldName:"CVVField"},e))},exports.PayPalCardFieldsContext=z,exports.PayPalCardFieldsForm=function(e){var t=e.className;return n.createElement("div",{className:t},n.createElement(Z,{fieldName:"NameField"}),n.createElement(Z,{fieldName:"NumberField"}),n.createElement(W,null,n.createElement(J,null,n.createElement(Z,{fieldName:"ExpiryField"})),n.createElement(J,null,n.createElement(Z,{fieldName:"CVVField"}))))},exports.PayPalCardFieldsProvider=function(e){var t=e.children,r=i(e,["children"]),o=x(r.inputEvents),c=x(r),s=b()[0],l=s.isResolved,u=s.options,d=function(){var e=n.useState(null)[1],t=n.useRef({});return{fields:t.current,registerField:function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];var o=r[0],a=r[1],i=r[2];return t.current[o]&&e(function(){throw new Error("Cannot use duplicate CardFields as children")}),t.current[o]=null==i?void 0:i[o](a),t.current[o]},unregisterField:function(e){var r=t.current[e];r&&(r.close().catch(X),delete t.current[e])}}}(),f=d.fields,v=d.registerField,m=d.unregisterField,E=n.useState(null),P=E[0],h=E[1],T=n.useRef(null),A=n.useState(!1),I=A[0],N=A[1],C=n.useState(null)[1];return n.useEffect(function(){var e,t,n;if(l){r.inputEvents&&(c.inputEvents=o);try{T.current=null!==(n=null===(t=(e=S(u[p])).CardFields)||void 0===t?void 0:t.call(e,a({},c)))&&void 0!==n?n:null}catch(e){return void C(function(){throw new Error("Failed to render <PayPalCardFieldsProvider /> component. Failed to initialize: ".concat(e))})}if(T.current)return N(T.current.isEligible()),h(T.current),function(){h(null),T.current=null};C(function(){var e;throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e[p],o=void 0===n?y:n,a=r?"".concat(r,",card-fields"):"card-fields",i="Unable to render <PayPalCardFieldsProvider /> because window.".concat(o,".CardFields is undefined.");return r.includes("card-fields")||(i+="\nTo fix the issue, add 'card-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '".concat(a,"'}}>")),i}(((e={components:u.components})[p]=u[p],e)))})}},[l]),I?n.createElement(J,null,n.createElement(z.Provider,{value:{cardFieldsForm:P,fields:f,registerField:v,unregisterField:m}},t)):n.createElement("div",null)},exports.PayPalExpiryField=function(e){return n.createElement(Z,a({fieldName:"ExpiryField"},e))},exports.PayPalHostedField=function(e){var t=e.hostedFieldType,r=e.options,o=i(e,["hostedFieldType","options"]),c=n.useContext(w);return n.useEffect(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={})[t]={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))},[]),n.createElement("div",a({},o))},exports.PayPalHostedFieldsProvider=function(e){var t=e.styles,r=e.createOrder,o=e.notEligibleError,i=e.children,c=e.installments,s=g()[0],l=s.options,u=s.loadingStatus,d=n.useState(!0),f=d[0],v=d[1],m=n.useState(),E=m[0],P=m[1],h=n.useState(null)[1],T=n.useRef(null),A=n.useRef(),I=function(e){void 0===e&&(e={});var t=n.useRef(e);return[t,function(e){t.current=a(a({},t.current),e)}]}(),N=I[0],C=I[1];return n.useEffect(function(){var e;if(q(Object.keys(N.current)),u===exports.SCRIPT_LOADING_STATE.RESOLVED){if(A.current=S(l[p]).HostedFields,!A.current)throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e[p],o=void 0===n?y:n,a=r?"".concat(r,",hosted-fields"):"hosted-fields",i="Unable to render <PayPalHostedFieldsProvider /> because window.".concat(o,".HostedFields is undefined.");return r.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:l.components})[p]=l[p],e)));if(!A.current.isEligible())return v(!1);E&&E.teardown(),A.current.render({createOrder:r,fields:N.current,installments:c,styles:t}).then(function(e){T.current&&P(e)}).catch(function(e){h(function(){throw new Error("Failed to render <PayPalHostedFieldsProvider /> component. ".concat(e))})})}},[u,t]),n.createElement("div",{ref:T},f?n.createElement(w.Provider,{value:{cardFields:E,registerHostedField:C}},i):o)},exports.PayPalMarks=U,exports.PayPalMessages=M,exports.PayPalNameField=function(e){return n.createElement(Z,a({fieldName:"NameField"},e))},exports.PayPalNumberField=function(e){return n.createElement(Z,a({fieldName:"NumberField"},e))},exports.PayPalScriptProvider=function(e){var t,r=e.options,o=void 0===r?{clientId:"test"}:r,i=e.children,c=e.deferLoading,l=void 0!==c&&c,p=n.useReducer(N,{options:a(a({},o),(t={},t[u]=d,t[f]=d,t[s]="".concat(A(o)),t)),loadingStatus:l?exports.SCRIPT_LOADING_STATE.INITIAL:exports.SCRIPT_LOADING_STATE.PENDING}),v=p[0],E=p[1];return n.useEffect(function(){if(!1===l&&v.loadingStatus===exports.SCRIPT_LOADING_STATE.INITIAL)return E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.PENDING});if(v.loadingStatus===exports.SCRIPT_LOADING_STATE.PENDING){var e=!0;return j(v.options).then(function(){e&&E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:exports.SCRIPT_LOADING_STATE.RESOLVED})}).catch(function(t){console.error("".concat(m," ").concat(t)),e&&E({type:exports.DISPATCH_ACTION.LOADING_STATUS,value:{state:exports.SCRIPT_LOADING_STATE.REJECTED,message:String(t)}})}),function(){e=!1}}},[v.options,l,v.loadingStatus]),n.createElement(C.Provider,{value:a(a({},v),{dispatch:E})},i)},exports.ScriptContext=C,exports.destroySDKScript=I,exports.getScriptID=A,exports.scriptReducer=N,exports.usePayPalCardFields=K,exports.usePayPalHostedFields=function(){return n.useContext(w)},exports.usePayPalScriptReducer=b,exports.useScriptProviderContext=g;