@paynext/sdk 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +6 -4
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -44,7 +44,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
44
44
|
* See the License for the specific language governing permissions and
|
|
45
45
|
* limitations under the License.
|
|
46
46
|
*/var ee;(function(e){e.INITIAL="initial",e.PENDING="pending",e.REJECTED="rejected",e.RESOLVED="resolved"})(ee||(ee={}));var ke;(function(e){e.LOADING_STATUS="setLoadingStatus",e.RESET_OPTIONS="resetOptions",e.SET_BRAINTREE_INSTANCE="braintreeInstance"})(ke||(ke={}));var Xa;(function(e){e.NUMBER="number",e.CVV="cvv",e.EXPIRATION_DATE="expirationDate",e.EXPIRATION_MONTH="expirationMonth",e.EXPIRATION_YEAR="expirationYear",e.POSTAL_CODE="postalCode"})(Xa||(Xa={}));var F=function(){return F=Object.assign||function(t){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},F.apply(this,arguments)};function Ja(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function Qa(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,s;r<i;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var Ct="data-react-paypal-script-id",Re={DATA_JS_SDK_LIBRARY:"dataJsSdkLibrary",DATA_LIBRARY_VALUE:"react-paypal-js",DATA_NAMESPACE:"dataNamespace",DATA_SDK_INTEGRATION_SOURCE:"dataSdkIntegrationSource"},x0="Failed to load the PayPal JS SDK script.",eo="paypal",C0="usePayPalScriptReducer must be used within a PayPalScriptProvider";function w0(e){return e===void 0&&(e=eo),window[e]}function k0(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}function T0(e){var t=e.reactComponentName,n=e.sdkComponentKey,r=e.sdkRequestedComponents,i=r===void 0?"":r,s=e.sdkDataNamespace,a=s===void 0?eo:s,o=n.charAt(0).toUpperCase().concat(n.substring(1)),l="Unable to render <".concat(t," /> because window.").concat(a,".").concat(o," is undefined."),u=typeof i=="string"?i:i.join(",");if(!u.includes(n)){var c=[u,n].filter(Boolean).join();l+=`
|
|
47
|
-
To fix the issue, add '`.concat(n,"' to the list of components passed to the parent PayPalScriptProvider:")+"\n`<PayPalScriptProvider options={{ components: '".concat(c,"'}}>`.")}return l}function to(e){var t=e,n=Ct;t[n];var r=Ja(t,[n+""]);return"react-paypal-js-".concat(k0(JSON.stringify(r)))}function P0(e){var t=self.document.querySelector("script[".concat(Ct,'="').concat(e,'"]'));t?.parentNode&&t.parentNode.removeChild(t)}function S0(e,t){var n,r;switch(t.type){case ke.LOADING_STATUS:return typeof t.value=="object"?F(F({},e),{loadingStatus:t.value.state,loadingStatusErrorMessage:t.value.message}):F(F({},e),{loadingStatus:t.value});case ke.RESET_OPTIONS:return P0(e.options[Ct]),F(F({},e),{loadingStatus:ee.PENDING,options:F(F((n={},n[Re.DATA_SDK_INTEGRATION_SOURCE]=Re.DATA_LIBRARY_VALUE,n),t.value),(r={},r[Ct]="".concat(to(t.value)),r))});case ke.SET_BRAINTREE_INSTANCE:return F(F({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var no=f.createContext(null);function A0(e){if(typeof e?.dispatch=="function"&&e.dispatch.length!==0)return e;throw new Error(C0)}function E0(){var e=A0(f.useContext(no)),t=F(F({},e),{isInitial:e.loadingStatus===ee.INITIAL,isPending:e.loadingStatus===ee.PENDING,isResolved:e.loadingStatus===ee.RESOLVED,isRejected:e.loadingStatus===ee.REJECTED});return[t,e.dispatch]}f.createContext({});function j0(e){var t=f.useRef(new Proxy({},{get:function(n,r,i){return typeof n[r]=="function"?function(){for(var s=[],a=0;a<arguments.length;a++)s[a]=arguments[a];return n[r].apply(n,s)}:Reflect.get(n,r,i)}}));return t.current=Object.assign(t.current,e),t.current}var Tr=function(e){var t,n=e.className,r=n===void 0?"":n,i=e.disabled,s=i===void 0?!1:i,a=e.children,o=e.forceReRender,l=o===void 0?[]:o,u=Ja(e,["className","disabled","children","forceReRender"]),c=s?{opacity:.38}:{},d="".concat(r," ").concat(s?"paypal-buttons-disabled":"").trim(),h=f.useRef(null),m=f.useRef(null),g=j0(u),y=E0()[0],b=y.isResolved,v=y.options,k=f.useState(null),x=k[0],T=k[1],w=f.useState(!0),P=w[0],E=w[1],S=f.useState(null),_=S[1];function I(){m.current!==null&&m.current.close().catch(function(){})}return!((t=m.current)===null||t===void 0)&&t.updateProps&&m.current.updateProps({message:u.message}),f.useEffect(function(){if(b===!1)return I;var q=w0(v.dataNamespace);if(q===void 0||q.Buttons===void 0)return _(function(){throw new Error(T0({reactComponentName:Tr.displayName,sdkComponentKey:"buttons",sdkRequestedComponents:v.components,sdkDataNamespace:v[Re.DATA_NAMESPACE]}))}),I;var te=function(H,U){T(U),typeof u.onInit=="function"&&u.onInit(H,U)};try{m.current=q.Buttons(F(F({},g),{onInit:te}))}catch(H){return _(function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: ".concat(H))})}return m.current.isEligible()===!1?(E(!1),I):(h.current&&m.current.render(h.current).catch(function(H){h.current===null||h.current.children.length===0||_(function(){throw new Error("Failed to render <PayPalButtons /> component. ".concat(H))})}),I)},Qa(Qa([b],l,!0),[u.fundingSource],!1)),f.useEffect(function(){x!==null&&(s===!0?x.disable().catch(function(){}):x.enable().catch(function(){}))},[s,x]),f.createElement(f.Fragment,null,P?f.createElement("div",{ref:h,style:c,className:d}):a)};Tr.displayName="PayPalButtons";function _0(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}typeof SuppressedError=="function"&&SuppressedError;function V0(e,t){var n=document.querySelector('script[src="'.concat(e,'"]'));if(n===null)return null;var r=ro(e,t),i=n.cloneNode();if(delete i.dataset.uidAuto,Object.keys(i.dataset).length!==Object.keys(r.dataset).length)return null;var s=!0;return Object.keys(i.dataset).forEach(function(a){i.dataset[a]!==r.dataset[a]&&(s=!1)}),s?n:null}function R0(e){var t=e.url,n=e.attributes,r=e.onSuccess,i=e.onError,s=ro(t,n);s.onerror=i,s.onload=r,document.head.insertBefore(s,document.head.firstElementChild)}function I0(e){var t=e.sdkBaseUrl,n=e.environment,r=_0(e,["sdkBaseUrl","environment"]),i=t||L0(n),s=r,a=Object.keys(s).filter(function(u){return typeof s[u]<"u"&&s[u]!==null&&s[u]!==""}).reduce(function(u,c){var d=s[c].toString();return c=M0(c),c.substring(0,4)==="data"||c==="crossorigin"?u.attributes[c]=d:u.queryParams[c]=d,u},{queryParams:{},attributes:{}}),o=a.queryParams,l=a.attributes;return o["merchant-id"]&&o["merchant-id"].indexOf(",")!==-1&&(l["data-merchant-id"]=o["merchant-id"],o["merchant-id"]="*"),{url:"".concat(i,"?").concat(D0(o)),attributes:l}}function M0(e){var t=function(n,r){return(r?"-":"")+n.toLowerCase()};return e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,t)}function D0(e){var t="";return Object.keys(e).forEach(function(n){t.length!==0&&(t+="&"),t+=n+"="+e[n]}),t}function L0(e){return e==="sandbox"?"https://www.sandbox.paypal.com/sdk/js":"https://www.paypal.com/sdk/js"}function ro(e,t){t===void 0&&(t={});var n=document.createElement("script");return n.src=e,Object.keys(t).forEach(function(r){n.setAttribute(r,t[r]),r==="data-csp-nonce"&&n.setAttribute("nonce",t["data-csp-nonce"])}),n}function N0(e,t){if(t===void 0&&(t=Promise),so(e,t),typeof document>"u")return t.resolve(null);var n=I0(e),r=n.url,i=n.attributes,s=i["data-namespace"]||"paypal",a=io(s);return i["data-js-sdk-library"]||(i["data-js-sdk-library"]="paypal-js"),V0(r,i)&&a?t.resolve(a):O0({url:r,attributes:i},t).then(function(){var o=io(s);if(o)return o;throw new Error("The window.".concat(s," global variable is not available."))})}function O0(e,t){t===void 0&&(t=Promise),so(e,t);var n=e.url,r=e.attributes;if(typeof n!="string"||n.length===0)throw new Error("Invalid url.");if(typeof r<"u"&&typeof r!="object")throw new Error("Expected attributes to be an object.");return new t(function(i,s){if(typeof document>"u")return i();R0({url:n,attributes:r,onSuccess:function(){return i()},onError:function(){var a=new Error('The script "'.concat(n,'" failed to load. Check the HTTP status code and response body in DevTools to learn more.'));return s(a)}})})}function io(e){return window[e]}function so(e,t){if(typeof e!="object"||e===null)throw new Error("Expected an options object.");var n=e.environment;if(n&&n!=="production"&&n!=="sandbox")throw new Error('The `environment` option must be either "production" or "sandbox".');if(typeof t<"u"&&typeof t!="function")throw new Error("Expected PromisePonyfill to be a function.")}var B0=function(e){var t,n=e.options,r=n===void 0?{clientId:"test"}:n,i=e.children,s=e.deferLoading,a=s===void 0?!1:s,o=f.useReducer(S0,{options:F(F({},r),(t={},t[Re.DATA_JS_SDK_LIBRARY]=Re.DATA_LIBRARY_VALUE,t[Re.DATA_SDK_INTEGRATION_SOURCE]=Re.DATA_LIBRARY_VALUE,t[Ct]="".concat(to(r)),t)),loadingStatus:a?ee.INITIAL:ee.PENDING}),l=o[0],u=o[1];return f.useEffect(function(){if(a===!1&&l.loadingStatus===ee.INITIAL)return u({type:ke.LOADING_STATUS,value:ee.PENDING});if(l.loadingStatus===ee.PENDING){var c=!0;return N0(l.options).then(function(){c&&u({type:ke.LOADING_STATUS,value:ee.RESOLVED})}).catch(function(d){console.error("".concat(x0," ").concat(d)),c&&u({type:ke.LOADING_STATUS,value:{state:ee.REJECTED,message:String(d)}})}),function(){c=!1}}},[l.options,a,l.loadingStatus]),f.createElement(no.Provider,{value:F(F({},l),{dispatch:u})},i)};function ao(){}f.createContext({cardFieldsForm:null,fields:{},registerField:ao,unregisterField:ao});const q0={paypalBtn:"_paypalBtn_2m8yd_1"},F0=({onCreate:e,onApprove:t,onReady:n,transaction:r})=>p.jsx("div",{className:q0.paypalBtn,children:p.jsx(B0,{options:{clientId:"test",vault:!0},children:p.jsx(Tr,{style:{layout:"vertical",tagline:!1,height:40,borderRadius:12},fundingSource:"paypal",onInit:n,createBillingAgreement:async()=>await e(r),onApprove:async({billingToken:i})=>{i&&t(i)}})})}),K0=e=>!e||!e.amount||!e.currency||!e.country||!e.merchant_id||e.checkout_config&&!e.checkout_config?.find(({is_active:n,type:r})=>n&&r==="google-pay")?null:{amount:e.amount,currency:e.currency,country:e.country,merchantId:e.merchant_id,lineItems:[]},z0=e=>!e||!e.amount||!e.currency||!e.country||!e.merchant_id||e.checkout_config&&!e.checkout_config?.find(({is_active:n,type:r})=>n&&r==="apple-pay")?null:{amount:e.amount,currency:e.currency,country:e.country,merchantId:e.merchant_id,lineItems:e.apple_pay_info?.line_items||[]},$0=e=>!e||!e.amount||!e.currency||!e.country||!e.merchant_id||e.checkout_config&&!e.checkout_config.find(({is_active:n,type:r})=>n&&r==="paypal")?null:{intent:"TOKENIZE",purchase_units:[{amount:{currency_code:e.currency,value:(e.amount/100).toString()},reference_id:e.merchant_id}]},U0=(e=[])=>e.reduce((t,n)=>{switch(n){case Y.Visa:return t.push("visa"),t;case Y.Mastercard:return t.push("masterCard"),t;case Y.AmericanExpress:return t.push("amex"),t;case Y.Discover:return t.push("discover"),t;case Y.JCB:return t.push("jcb"),t;case Y.UnionPay:return t.push("chinaUnionPay"),t;default:return t}},[]),G0=({onError:e,onSubmit:t,onReset:n,clientToken:r})=>{const i=Po(),s=ko(),[a,o]=f.useState(!1),[l,u]=f.useState(!1),[c,d]=f.useState(!1),[h,m]=f.useState(!1),[g,y]=f.useState(!1),{googlePay:b,applePay:v,paypal:k}=f.useMemo(()=>({googlePay:K0(s),applePay:z0(s),paypal:$0(s)}),[s]);f.useEffect(()=>{const V=setTimeout(()=>{y(!0)},2e3);return()=>clearTimeout(V)},[]);const x=f.useCallback(async V=>{if(!i)return;n?.();const ne=await i?.encrypt(V.number),R=await i?.encrypt(V.cvc),[M,z]=V.expiry.split("/");t({clientSession:r,card:{firstSixDigits:V.number.slice(0,6),lastFourDigits:V.number.slice(-4),expMonth:Number(M),expYear:Number(z),cardBrand:V.cardBrand||"",number:ne,cvc:R,type:Rr.Card,metadata:{name:V.name,userAgent:Qt?navigator?.userAgent:""}}})},[i,t,n,r]),T=f.useCallback(V=>{t({clientSession:r,googlePay:V})},[t,r]),w=f.useCallback(()=>{d(!0)},[]),P=f.useCallback(V=>{console.error(V),e(V)},[e]),E=f.useCallback(V=>{t({clientSession:r,applePay:V})},[t,r]),S=f.useCallback(V=>{console.error(V),e(V)},[e]),_=f.useCallback(()=>{m(!0)},[]),I=f.useCallback(()=>{u(!0)},[]),q=f.useCallback(async()=>{const V=await mo(r);if(V.error){const ne=V.error||"Paypal request failed";throw e(ne),ne}return V.paypal_agreement_token_response.token_id||""},[r,e]),te=f.useCallback(V=>{t({clientSession:r,paypal:{billing_agreement_token:V}})},[t,r]),H=f.useCallback(()=>{n?.(),o(!0)},[n]),U=f.useCallback(()=>{n?.(),o(!1)},[n]);return{isCardOpen:a,transaction:s,isReady:(!b||c)&&(!v||h)&&(!k||l)&&g,googlePay:b,applePay:v,paypal:k,isPayPalReady:l,handlePayPalReady:I,handleGooglePayReady:w,handleApplePayReady:_,handlePayCard:x,handleGooglePay:T,handleGooglePayError:P,handleApplePay:E,handleApplePayError:S,handleCardOpen:H,handleCardClose:U,handlePayPalCreate:q,handlePayPal:te}},Zt={variants:{initial:{y:100,opacity:0},animate:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20}},exit:{y:100,opacity:0,transition:{duration:.3}},open:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20,delay:.3}},close:{y:100,opacity:0,display:"none",transition:{duration:.3}}},btnVariants:{initial:{y:-100,opacity:0},animate:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20}},exit:{y:-100,opacity:0,transition:{duration:.3}},open:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20,delay:.3}},close:{y:-100,opacity:0,display:"none",transition:{duration:.3}}},success:{initial:{y:100,opacity:0},animate:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20}}}},Xt={container:"_container_ipway_1",icon:"_icon_ipway_5",iconContainer:"_iconContainer_ipway_9",title:"_title_ipway_13"},W0=({title:e})=>p.jsxs("div",{className:Xt.container,children:[p.jsx("div",{className:Xt.iconContainer,children:p.jsx("svg",{fill:"none",height:"24",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg",className:Xt.icon,children:p.jsx("path",{d:`
|
|
47
|
+
To fix the issue, add '`.concat(n,"' to the list of components passed to the parent PayPalScriptProvider:")+"\n`<PayPalScriptProvider options={{ components: '".concat(c,"'}}>`.")}return l}function to(e){var t=e,n=Ct;t[n];var r=Ja(t,[n+""]);return"react-paypal-js-".concat(k0(JSON.stringify(r)))}function P0(e){var t=self.document.querySelector("script[".concat(Ct,'="').concat(e,'"]'));t?.parentNode&&t.parentNode.removeChild(t)}function S0(e,t){var n,r;switch(t.type){case ke.LOADING_STATUS:return typeof t.value=="object"?F(F({},e),{loadingStatus:t.value.state,loadingStatusErrorMessage:t.value.message}):F(F({},e),{loadingStatus:t.value});case ke.RESET_OPTIONS:return P0(e.options[Ct]),F(F({},e),{loadingStatus:ee.PENDING,options:F(F((n={},n[Re.DATA_SDK_INTEGRATION_SOURCE]=Re.DATA_LIBRARY_VALUE,n),t.value),(r={},r[Ct]="".concat(to(t.value)),r))});case ke.SET_BRAINTREE_INSTANCE:return F(F({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var no=f.createContext(null);function A0(e){if(typeof e?.dispatch=="function"&&e.dispatch.length!==0)return e;throw new Error(C0)}function E0(){var e=A0(f.useContext(no)),t=F(F({},e),{isInitial:e.loadingStatus===ee.INITIAL,isPending:e.loadingStatus===ee.PENDING,isResolved:e.loadingStatus===ee.RESOLVED,isRejected:e.loadingStatus===ee.REJECTED});return[t,e.dispatch]}f.createContext({});function j0(e){var t=f.useRef(new Proxy({},{get:function(n,r,i){return typeof n[r]=="function"?function(){for(var s=[],a=0;a<arguments.length;a++)s[a]=arguments[a];return n[r].apply(n,s)}:Reflect.get(n,r,i)}}));return t.current=Object.assign(t.current,e),t.current}var Tr=function(e){var t,n=e.className,r=n===void 0?"":n,i=e.disabled,s=i===void 0?!1:i,a=e.children,o=e.forceReRender,l=o===void 0?[]:o,u=Ja(e,["className","disabled","children","forceReRender"]),c=s?{opacity:.38}:{},d="".concat(r," ").concat(s?"paypal-buttons-disabled":"").trim(),h=f.useRef(null),m=f.useRef(null),g=j0(u),y=E0()[0],b=y.isResolved,v=y.options,k=f.useState(null),x=k[0],T=k[1],w=f.useState(!0),P=w[0],E=w[1],S=f.useState(null),_=S[1];function I(){m.current!==null&&m.current.close().catch(function(){})}return!((t=m.current)===null||t===void 0)&&t.updateProps&&m.current.updateProps({message:u.message}),f.useEffect(function(){if(b===!1)return I;var q=w0(v.dataNamespace);if(q===void 0||q.Buttons===void 0)return _(function(){throw new Error(T0({reactComponentName:Tr.displayName,sdkComponentKey:"buttons",sdkRequestedComponents:v.components,sdkDataNamespace:v[Re.DATA_NAMESPACE]}))}),I;var te=function(H,U){T(U),typeof u.onInit=="function"&&u.onInit(H,U)};try{m.current=q.Buttons(F(F({},g),{onInit:te}))}catch(H){return _(function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: ".concat(H))})}return m.current.isEligible()===!1?(E(!1),I):(h.current&&m.current.render(h.current).catch(function(H){h.current===null||h.current.children.length===0||_(function(){throw new Error("Failed to render <PayPalButtons /> component. ".concat(H))})}),I)},Qa(Qa([b],l,!0),[u.fundingSource],!1)),f.useEffect(function(){x!==null&&(s===!0?x.disable().catch(function(){}):x.enable().catch(function(){}))},[s,x]),f.createElement(f.Fragment,null,P?f.createElement("div",{ref:h,style:c,className:d}):a)};Tr.displayName="PayPalButtons";function _0(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}typeof SuppressedError=="function"&&SuppressedError;function V0(e,t){var n=document.querySelector('script[src="'.concat(e,'"]'));if(n===null)return null;var r=ro(e,t),i=n.cloneNode();if(delete i.dataset.uidAuto,Object.keys(i.dataset).length!==Object.keys(r.dataset).length)return null;var s=!0;return Object.keys(i.dataset).forEach(function(a){i.dataset[a]!==r.dataset[a]&&(s=!1)}),s?n:null}function R0(e){var t=e.url,n=e.attributes,r=e.onSuccess,i=e.onError,s=ro(t,n);s.onerror=i,s.onload=r,document.head.insertBefore(s,document.head.firstElementChild)}function I0(e){var t=e.sdkBaseUrl,n=e.environment,r=_0(e,["sdkBaseUrl","environment"]),i=t||L0(n),s=r,a=Object.keys(s).filter(function(u){return typeof s[u]<"u"&&s[u]!==null&&s[u]!==""}).reduce(function(u,c){var d=s[c].toString();return c=M0(c),c.substring(0,4)==="data"||c==="crossorigin"?u.attributes[c]=d:u.queryParams[c]=d,u},{queryParams:{},attributes:{}}),o=a.queryParams,l=a.attributes;return o["merchant-id"]&&o["merchant-id"].indexOf(",")!==-1&&(l["data-merchant-id"]=o["merchant-id"],o["merchant-id"]="*"),{url:"".concat(i,"?").concat(D0(o)),attributes:l}}function M0(e){var t=function(n,r){return(r?"-":"")+n.toLowerCase()};return e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,t)}function D0(e){var t="";return Object.keys(e).forEach(function(n){t.length!==0&&(t+="&"),t+=n+"="+e[n]}),t}function L0(e){return e==="sandbox"?"https://www.sandbox.paypal.com/sdk/js":"https://www.paypal.com/sdk/js"}function ro(e,t){t===void 0&&(t={});var n=document.createElement("script");return n.src=e,Object.keys(t).forEach(function(r){n.setAttribute(r,t[r]),r==="data-csp-nonce"&&n.setAttribute("nonce",t["data-csp-nonce"])}),n}function N0(e,t){if(t===void 0&&(t=Promise),so(e,t),typeof document>"u")return t.resolve(null);var n=I0(e),r=n.url,i=n.attributes,s=i["data-namespace"]||"paypal",a=io(s);return i["data-js-sdk-library"]||(i["data-js-sdk-library"]="paypal-js"),V0(r,i)&&a?t.resolve(a):O0({url:r,attributes:i},t).then(function(){var o=io(s);if(o)return o;throw new Error("The window.".concat(s," global variable is not available."))})}function O0(e,t){t===void 0&&(t=Promise),so(e,t);var n=e.url,r=e.attributes;if(typeof n!="string"||n.length===0)throw new Error("Invalid url.");if(typeof r<"u"&&typeof r!="object")throw new Error("Expected attributes to be an object.");return new t(function(i,s){if(typeof document>"u")return i();R0({url:n,attributes:r,onSuccess:function(){return i()},onError:function(){var a=new Error('The script "'.concat(n,'" failed to load. Check the HTTP status code and response body in DevTools to learn more.'));return s(a)}})})}function io(e){return window[e]}function so(e,t){if(typeof e!="object"||e===null)throw new Error("Expected an options object.");var n=e.environment;if(n&&n!=="production"&&n!=="sandbox")throw new Error('The `environment` option must be either "production" or "sandbox".');if(typeof t<"u"&&typeof t!="function")throw new Error("Expected PromisePonyfill to be a function.")}var B0=function(e){var t,n=e.options,r=n===void 0?{clientId:"test"}:n,i=e.children,s=e.deferLoading,a=s===void 0?!1:s,o=f.useReducer(S0,{options:F(F({},r),(t={},t[Re.DATA_JS_SDK_LIBRARY]=Re.DATA_LIBRARY_VALUE,t[Re.DATA_SDK_INTEGRATION_SOURCE]=Re.DATA_LIBRARY_VALUE,t[Ct]="".concat(to(r)),t)),loadingStatus:a?ee.INITIAL:ee.PENDING}),l=o[0],u=o[1];return f.useEffect(function(){if(a===!1&&l.loadingStatus===ee.INITIAL)return u({type:ke.LOADING_STATUS,value:ee.PENDING});if(l.loadingStatus===ee.PENDING){var c=!0;return N0(l.options).then(function(){c&&u({type:ke.LOADING_STATUS,value:ee.RESOLVED})}).catch(function(d){console.error("".concat(x0," ").concat(d)),c&&u({type:ke.LOADING_STATUS,value:{state:ee.REJECTED,message:String(d)}})}),function(){c=!1}}},[l.options,a,l.loadingStatus]),f.createElement(no.Provider,{value:F(F({},l),{dispatch:u})},i)};function ao(){}f.createContext({cardFieldsForm:null,fields:{},registerField:ao,unregisterField:ao});const q0={paypalBtn:"_paypalBtn_2m8yd_1"},F0=({onCreate:e,onApprove:t,onReady:n,transaction:r})=>p.jsx("div",{className:q0.paypalBtn,children:p.jsx(B0,{options:{clientId:"test",vault:!0},children:p.jsx(Tr,{style:{layout:"vertical",tagline:!1,height:40,borderRadius:12},fundingSource:"paypal",onInit:n,createBillingAgreement:async()=>await e(r),onApprove:async({billingToken:i})=>{i&&t(i)}})})}),K0=e=>!e||typeof e.amount!="number"||!e.currency||!e.country||!e.merchant_id||e.checkout_config&&!e.checkout_config?.find(({is_active:n,type:r})=>n&&r==="google-pay")?null:{amount:e.amount,currency:e.currency,country:e.country,merchantId:e.merchant_id,lineItems:[]},z0=e=>!e||typeof e.amount!="number"||!e.currency||!e.country||!e.merchant_id||e.checkout_config&&!e.checkout_config?.find(({is_active:n,type:r})=>n&&r==="apple-pay")?null:{amount:e.amount,currency:e.currency,country:e.country,merchantId:e.merchant_id,lineItems:e.apple_pay_info?.line_items||[]},$0=e=>!e||typeof e.amount!="number"||!e.currency||!e.country||!e.merchant_id||e.checkout_config&&!e.checkout_config.find(({is_active:n,type:r})=>n&&r==="paypal")?null:{intent:"TOKENIZE",purchase_units:[{amount:{currency_code:e.currency,value:(e.amount/100).toString()},reference_id:e.merchant_id}]},U0=(e=[])=>e.reduce((t,n)=>{switch(n){case Y.Visa:return t.push("visa"),t;case Y.Mastercard:return t.push("masterCard"),t;case Y.AmericanExpress:return t.push("amex"),t;case Y.Discover:return t.push("discover"),t;case Y.JCB:return t.push("jcb"),t;case Y.UnionPay:return t.push("chinaUnionPay"),t;default:return t}},[]),G0=({onError:e,onSubmit:t,onReset:n,clientToken:r})=>{const i=Po(),s=ko(),[a,o]=f.useState(!1),[l,u]=f.useState(!1),[c,d]=f.useState(!1),[h,m]=f.useState(!1),[g,y]=f.useState(!1);console.log({transaction:s});const{googlePay:b,applePay:v,paypal:k}=f.useMemo(()=>({googlePay:K0(s),applePay:z0(s),paypal:$0(s)}),[s]);f.useEffect(()=>{const V=setTimeout(()=>{y(!0)},2e3);return()=>clearTimeout(V)},[]);const x=f.useCallback(async V=>{if(!i)return;n?.();const ne=await i?.encrypt(V.number),R=await i?.encrypt(V.cvc),[M,z]=V.expiry.split("/");t({clientSession:r,card:{firstSixDigits:V.number.slice(0,6),lastFourDigits:V.number.slice(-4),expMonth:Number(M),expYear:Number(z),cardBrand:V.cardBrand||"",number:ne,cvc:R,type:Rr.Card,metadata:{name:V.name,userAgent:Qt?navigator?.userAgent:""}}})},[i,t,n,r]),T=f.useCallback(V=>{t({clientSession:r,googlePay:V})},[t,r]),w=f.useCallback(()=>{d(!0)},[]),P=f.useCallback(V=>{console.error(V),e(V)},[e]),E=f.useCallback(V=>{t({clientSession:r,applePay:V})},[t,r]),S=f.useCallback(V=>{console.error(V),e(V)},[e]),_=f.useCallback(()=>{m(!0)},[]),I=f.useCallback(()=>{u(!0)},[]),q=f.useCallback(async()=>{const V=await mo(r);if(V.error){const ne=V.error||"Paypal request failed";throw e(ne),ne}return V.paypal_agreement_token_response.token_id||""},[r,e]),te=f.useCallback(V=>{t({clientSession:r,paypal:{billing_agreement_token:V}})},[t,r]),H=f.useCallback(()=>{n?.(),o(!0)},[n]),U=f.useCallback(()=>{n?.(),o(!1)},[n]);return{isCardOpen:a,transaction:s,isReady:(!b||c)&&(!v||h)&&(!k||l)&&g,googlePay:b,applePay:v,paypal:k,isPayPalReady:l,handlePayPalReady:I,handleGooglePayReady:w,handleApplePayReady:_,handlePayCard:x,handleGooglePay:T,handleGooglePayError:P,handleApplePay:E,handleApplePayError:S,handleCardOpen:H,handleCardClose:U,handlePayPalCreate:q,handlePayPal:te}},Zt={variants:{initial:{y:100,opacity:0},animate:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20}},exit:{y:100,opacity:0,transition:{duration:.3}},open:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20,delay:.3}},close:{y:100,opacity:0,display:"none",transition:{duration:.3}}},btnVariants:{initial:{y:-100,opacity:0},animate:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20}},exit:{y:-100,opacity:0,transition:{duration:.3}},open:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20,delay:.3}},close:{y:-100,opacity:0,display:"none",transition:{duration:.3}}},success:{initial:{y:100,opacity:0},animate:{y:0,opacity:1,transition:{type:"spring",stiffness:80,damping:20}}}},Xt={container:"_container_ipway_1",icon:"_icon_ipway_5",iconContainer:"_iconContainer_ipway_9",title:"_title_ipway_13"},W0=({title:e})=>p.jsxs("div",{className:Xt.container,children:[p.jsx("div",{className:Xt.iconContainer,children:p.jsx("svg",{fill:"none",height:"24",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg",className:Xt.icon,children:p.jsx("path",{d:`
|
|
48
48
|
M12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2Z
|
|
49
49
|
M16.78 9.7L11.11 15.37C10.97 15.51 10.78 15.59 10.58 15.59C10.38 15.59 10.19 15.51 10.05 15.37L7.22 12.54
|
|
50
50
|
C6.93 12.25 6.93 11.77 7.22 11.48C7.51 11.19 7.99 11.19 8.28 11.48L10.58 13.78L15.72 8.64
|