@paypal/react-paypal-js
Version:
React components for the PayPal JS SDK
18 lines (17 loc) • 42.6 kB
JavaScript
/*!
* react-paypal-js v10.1.2 (2026-07-07T20:12:38.513Z)
* 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.
*/
import e,{createContext as n,useContext as r,useRef as t,useState as a,useCallback as o,useEffect as i,useMemo as l,useLayoutEffect as s,useReducer as c}from"react";import{loadCoreSdkScript as u}from"@paypal/paypal-js/sdk-v6";var d,p,y;function m(e){const n=e;return"function"==typeof n?.client?.create&&"function"==typeof n?.paypalCheckoutV6?.create}!function(e){e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(d||(d={})),function(e){e.SET_LOADING_STATUS="setLoadingStatus",e.SET_INSTANCE="setInstance",e.SET_ELIGIBILITY="setEligibility",e.SET_ERROR="setError",e.RESET_STATE="resetState"}(p||(p={})),function(e){e.SET_LOADING_STATUS="setLoadingStatus",e.SET_INSTANCE="setInstance",e.SET_ELIGIBILITY="setEligibility",e.SET_ERROR="setError",e.RESET_STATE="resetState"}(y||(y={}));const h={sdkInstance:null,eligiblePaymentMethods:null,eligiblePaymentMethodsPayload:null,loadingStatus:d.PENDING,error:null,isHydrated:!1};function g(e,n){switch(n.type){case p.SET_LOADING_STATUS:return{...e,loadingStatus:n.value};case p.SET_INSTANCE:return{...e,sdkInstance:n.value,loadingStatus:d.RESOLVED};case p.SET_ELIGIBILITY:return{...e,eligiblePaymentMethods:n.value.eligiblePaymentMethods,eligiblePaymentMethodsPayload:n.value.payload};case p.SET_ERROR:return{...e,error:n.value,loadingStatus:d.REJECTED};case p.RESET_STATE:return h;default:return e}}const E=n(null);function P(){const e=r(E);if(null===e)throw new Error("usePayPal must be used within a PayPalProvider");return e}function f(e){const n=t(new Proxy({},{get:(e,n,r)=>"function"==typeof e[n]?(...r)=>e[n](...r):Reflect.get(e,n,r)}));return n.current=Object.assign(n.current,e),n.current}function v(e){return e instanceof Error?e:new Error(String(e))}function C(e){const n=t();return n.current&&S(e,n.current.value)||(n.current={value:e}),n.current.value}function S(e,n,r=10,t=0){if(t>r)return!1;if(e===n)return!0;if(null==e||null==n)return!1;if(typeof e!=typeof n)return!1;if("object"!=typeof e)return!1;if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(let a=0;a<e.length;a++)if(!S(e[a],n[a],r,t+1))return!1;return!0}if(Array.isArray(e)||Array.isArray(n))return!1;const a=e,o=n,i=Object.keys(a),l=Object.keys(o);if(i.length!==l.length)return!1;for(const e of i)if(!S(a[e],o[e],r,t+1))return!1;return!0}function b({sessionCreator:e,failedSdkRef:n,sdkInstance:r,setError:t,errorMessage:a}){if(n.current===r)return null;try{return e()}catch(e){n.current=r;return t(new Error(a,{cause:e})),null}}const I=n(null),k=n(null);function w(e=!1){const[n,r]=a(null);return[n,o(n=>{r(n),!e&&n&&console.error(n)},[e])]}const T="one-time-payment",N="save-payment",M=({children:n,amount:r,isCobrandedEligible:t,...s})=>{const{sdkInstance:c,loadingStatus:u}=P(),[p,y]=a(null),[m,h]=a(null),[g,E]=a(null),[,S]=w(),b=f(s),N=C(r),M=o(e=>{S(e),E(e)},[S]);i(()=>{if(u===d.PENDING)return;if(!c)return void M(v("no sdk instance available"));if(M(null),!m)return;let e;try{e=m===T?c.createCardFieldsOneTimePaymentSession():c.createCardFieldsSavePaymentSession(),y(e)}catch(e){M(v(e))}return()=>{e?.destroy(),y(null)}},[c,u,m,M]),i(()=>{if(p)try{Object.keys(b).forEach(e=>{const n=b[e];n&&"function"==typeof n&&p.on(e,n)})}catch(e){M(v(`Failed to register event handlers: ${e}`))}},[p,b,M]),i(()=>{if(!p)return;const e={};let n=!1;if(void 0!==N&&(e.amount=N,n=!0),void 0!==t&&(e.isCobrandedEligible=t,n=!0),n)try{p.update(e)}catch(e){M(v(`Failed to update card fields configuration: ${e}`))}},[p,N,t,M]);const A=l(()=>({cardFieldsSession:p,setCardFieldsSessionType:h,setError:M}),[p,h,M]),D=l(()=>({error:g}),[g]);return e.createElement(I.Provider,{value:A},e.createElement(k.Provider,{value:D},n))};function A(){const e=t(!1);return i(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function D({presentationMode:e="auto",fullPageOverlay:n,autoRedirect:r,createOrder:a,orderId:l,...s}){const{sdkInstance:c,loadingStatus:u}=P(),p=A(),y=t(null),m=f(s),[h,g]=w(),E=t(null),v=u===d.PENDING,C=o(()=>{y.current?.destroy(),y.current=null},[]);i(()=>{E.current!==c&&(E.current=null),c?g(null):u!==d.PENDING&&g(new Error("no sdk instance available"))},[c,g,u]),i(()=>{if(!c)return;const n=b({sessionCreator:()=>c.createPayLaterOneTimePaymentSession({orderId:l,...m}),failedSdkRef:E,sdkInstance:c,setError:g,errorMessage:'Failed to create payment session. This may occur if the required component "paypal-payments" is not included in the SDK components array.'});if(!n)return;y.current=n;if("redirect"===e||"direct-app-switch"===e){(async()=>{try{if(!n)return;const e=n.hasReturned?.();e&&await(n.resume?.())}catch(e){g(e)}})()}return()=>{n.destroy()}},[c,l,m,e,g]);return{error:h,isPending:v,handleCancel:o(()=>{y.current?.cancel()},[]),handleClick:o(async()=>{if(!p.current)return;if(!y.current)return void g(new Error("PayLater session not available"));const t={presentationMode:e,fullPageOverlay:n,autoRedirect:r};return await y.current.start(t,a?.())},[a,e,n,r,p,g]),handleDestroy:C}}const O=({disabled:n=!1,...r})=>{const{eligiblePaymentMethods:t,isHydrated:a}=P(),{error:o,isPending:l,handleClick:s}=D(r),c=t?.getDetails("paylater"),u=c?.countryCode,d=c?.productCode;return i(()=>{o&&console.error(o)},[o]),l?null:a?e.createElement("paypal-pay-later-button",{onClick:s,countryCode:u,productCode:d,disabled:n||!!o||void 0}):e.createElement("div",null)};function R({presentationMode:e="auto",fullPageOverlay:n,autoRedirect:r,createOrder:a,orderId:l,...s}){const{sdkInstance:c,loadingStatus:u}=P(),p=A(),y=t(null),m=f(s),[h,g]=w(),E=t(null),v=u===d.PENDING,C=o(()=>{y.current?.destroy(),y.current=null},[]),S=o(()=>{y.current?.cancel()},[]);i(()=>{E.current!==c&&(E.current=null),c?g(null):u!==d.PENDING&&g(new Error("no sdk instance available"))},[c,g,u]),i(()=>{if(!c)return;const n=b({sessionCreator:()=>c.createPayPalCreditOneTimePaymentSession({orderId:l,...m}),failedSdkRef:E,sdkInstance:c,setError:g,errorMessage:'Failed to create payment session. This may occur if the required component "paypal-payments" is not included in the SDK components array.'});if(!n)return;y.current=n;if("redirect"===e||"direct-app-switch"===e){(async()=>{try{if(!n)return;const e=n.hasReturned?.();e&&await(n.resume?.())}catch(e){g(e)}})()}return()=>{n.destroy()}},[c,l,m,e,g]);return{error:h,isPending:v,handleClick:o(async()=>{if(!p.current)return;if(!y.current)return void g(new Error("PayPal session not available"));const t={presentationMode:e,fullPageOverlay:n,autoRedirect:r};return await y.current.start(t,a?.())},[p,e,n,r,a,g]),handleDestroy:C,handleCancel:S}}const G=({disabled:n=!1,...r})=>{const{eligiblePaymentMethods:t,isHydrated:a}=P(),{error:o,isPending:l,handleClick:s}=R(r),c=t?.getDetails("credit"),u=c?.countryCode;return i(()=>{o&&console.error(o)},[o]),l?null:a?e.createElement("paypal-credit-button",{onClick:s,countryCode:u,disabled:n||!!o||void 0}):e.createElement("div",null)};function B({presentationMode:e="auto",fullPageOverlay:n,autoRedirect:r,createVaultToken:a,vaultSetupToken:l,...s}){const{sdkInstance:c,loadingStatus:u}=P(),p=A(),y=t(null),m=f(s),[h,g]=w(),E=t(null),v=u===d.PENDING,C=o(()=>{y.current?.destroy(),y.current=null},[]);i(()=>{E.current!==c&&(E.current=null),c?g(null):u!==d.PENDING&&g(new Error("no sdk instance available"))},[c,g,u]),i(()=>{if(!c)return;const n=b({sessionCreator:()=>c.createPayPalSavePaymentSession({vaultSetupToken:l,...m}),failedSdkRef:E,sdkInstance:c,setError:g,errorMessage:'Failed to create payment session. This may occur if the required component "paypal-payments" is not included in the SDK components array.'});if(!n)return;y.current=n;if("redirect"===e||"direct-app-switch"===e){(async()=>{try{if(!n)return;const e=n.hasReturned?.();e&&await(n.resume?.())}catch(e){g(e)}})()}return()=>{n.destroy()}},[c,l,m,e,g]);const S=o(()=>{y.current?.cancel()},[]);return{error:h,isPending:v,handleClick:o(async()=>{if(!p.current)return;if(!y.current)return void g(new Error("Credit Save Payment session not available"));const t={presentationMode:e,fullPageOverlay:n,autoRedirect:r};a?await y.current.start(t,a()):await y.current.start(t)},[p,e,n,r,a,g]),handleDestroy:C,handleCancel:S}}const L=({disabled:n=!1,...r})=>{const{eligiblePaymentMethods:t,isHydrated:a}=P(),{error:o,isPending:l,handleClick:s}=B(r),c=t?.getDetails("credit"),u=c?.countryCode;return i(()=>{o&&console.error(o)},[o]),l?null:a?e.createElement("paypal-credit-button",{onClick:s,countryCode:u,disabled:n||!!o||void 0}):e.createElement("div",null)};function U({fullPageOverlay:e,createOrder:n,orderId:r,onShippingAddressChange:a,onShippingOptionsChange:l,...s}){const{sdkInstance:c,loadingStatus:u}=P(),p=A(),y=t(null),m=t(null),h=f(s),[g,E]=w(),v=t(null),C=u===d.PENDING,S=o(()=>{y.current?.destroy(),y.current=null},[]),I=o(()=>{y.current?.cancel()},[]);i(()=>{v.current!==c&&(v.current=null),c?E(null):u!==d.PENDING&&E(new Error("no sdk instance available"))},[c,E,u]),i(()=>{if(!c)return;const e=b({sessionCreator:()=>c.createPayPalGuestOneTimePaymentSession({orderId:r,...h,...a&&{onShippingAddressChange:a},...l&&{onShippingOptionsChange:l}}),failedSdkRef:v,sdkInstance:c,setError:E,errorMessage:'Failed to create payment session. This may occur if the required component "paypal-guest-payments" is not included in the SDK components array.'});return e?(y.current=e,()=>{e.destroy()}):void 0},[c,r,h,a,l,p,E]);const k=o(async()=>{if(p.current)if(y.current)try{const r={presentationMode:"auto",fullPageOverlay:e,...m.current?{targetElement:m.current}:{}};await y.current.start(r,n?.())}catch(e){p.current&&E(e)}else E(new Error("PayPal Guest Checkout session not available"))},[p,e,n,E]);return{buttonRef:m,error:g,isPending:C,handleClick:k,handleCancel:I,handleDestroy:S}}const _=({disabled:n=!1,...r})=>{const{error:t,isPending:a,handleClick:o,buttonRef:l}=U(r),{isHydrated:s}=P();i(()=>{t&&console.error(t)},[t]);const c=s?e.createElement("paypal-basic-card-button",{ref:l,onClick:o,disabled:!(!n&&!a&&null===t)||void 0}):e.createElement("div",null);return e.createElement("paypal-basic-card-container",null,c)};function F({presentationMode:e="auto",fullPageOverlay:n,autoRedirect:r,createOrder:a,orderId:l,savePayment:s,testBuyerCountry:c,...u}){const{sdkInstance:p,loadingStatus:y}=P(),m=A(),h=t(null),g=f(u),[E,v]=w(),C=t(null),S=y===d.PENDING,I=o(()=>{h.current?.destroy(),h.current=null},[]),k=o(()=>{h.current?.cancel()},[]);i(()=>{C.current!==p&&(C.current=null),p?v(null):y!==d.PENDING&&v(new Error("no sdk instance available"))},[p,v,y]),i(()=>{if(!p)return;const n=b({sessionCreator:()=>p.createPayPalOneTimePaymentSession({orderId:l,savePayment:s,testBuyerCountry:c,...g}),failedSdkRef:C,sdkInstance:p,setError:v,errorMessage:'Failed to create payment session. This may occur if the required component "paypal-payments" is not included in the SDK components array.'});if(!n)return;h.current=n;if("redirect"===e||"direct-app-switch"===e){(async()=>{try{if(!n)return;const e=n.hasReturned?.();e&&await(n.resume?.())}catch(e){v(e)}})()}return()=>{n.destroy()}},[p,l,g,e,v,s,c]);return{error:E,isPending:S,handleClick:o(async()=>{if(!m.current)return;if(!h.current)return void v(new Error("PayPal session not available"));const t={presentationMode:e,fullPageOverlay:n,autoRedirect:r};return await h.current.start(t,a?.())},[m,e,n,r,a,v]),handleCancel:k,handleDestroy:I}}const H=({type:n="pay",disabled:r=!1,...t})=>{const{error:a,isPending:o,handleClick:l}=F(t),{isHydrated:s}=P();return i(()=>{a&&console.error(a)},[a]),s?e.createElement("paypal-button",{onClick:l,type:n,disabled:!(!r&&!o&&null===a)||void 0}):e.createElement("div",null)};function V({presentationMode:e="auto",fullPageOverlay:n,createSubscription:r,...a}){const{sdkInstance:l,loadingStatus:s}=P(),c=A(),u=t(null),p=f(a),[y,m]=w(),h=t(null),g=s===d.PENDING,E=o(()=>{u.current?.destroy(),u.current=null},[]),v=o(()=>{u.current?.cancel()},[]);i(()=>{h.current!==l&&(h.current=null),l?m(null):s!==d.PENDING&&m(new Error("no sdk instance available"))},[l,m,s]),i(()=>{if(!l)return;const e=b({sessionCreator:()=>l.createPayPalSubscriptionPaymentSession({...p}),failedSdkRef:h,sdkInstance:l,setError:m,errorMessage:'Failed to create payment session. This may occur if the required component "paypal-subscriptions" is not included in the SDK components array.'});return e?(u.current=e,()=>{e.destroy()}):void 0},[l,p,m]);return{error:y,isPending:g,handleClick:o(async()=>{if(!c.current)return;if(!u.current)return void m(new Error("PayPal subscription session not available"));const t={presentationMode:e,fullPageOverlay:n};return await u.current.start(t,r())},[c,e,n,r,m]),handleCancel:v,handleDestroy:E}}const q=({type:n="subscribe",disabled:r=!1,...t})=>{const{error:a,isPending:o,handleClick:l}=V(t),{isHydrated:s}=P();return i(()=>{a&&console.error(a)},[a]),s?e.createElement("paypal-button",{onClick:l,type:n,disabled:!(!r&&!o&&null===a)||void 0}):e.createElement("div",null)},j=n(null),K="undefined"!=typeof window?s:i,z=({clientMetadataId:n,clientToken:r,clientId:o,components:s=["paypal-payments"],locale:y,pageType:m,partnerAttributionId:P,shopperSessionId:f,testBuyerCountry:S,eligibleMethodsResponse:b,children:I,merchantId:k,...T})=>{const N=function(e){const n=t(e);return function(e,n){if(!e&&!n)return!0;if(!e||!n)return!1;if(e.length!==n.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==n[r])return!1;return!0}(n.current,e)||(n.current=e),n.current}(s),M=C(k),[A,D]=a(null),[O,R]=c(g,h),[G,B]=a(!1),L=t({...T,dataSdkIntegrationSource:"react-paypal-js"});K(()=>{B(!0)},[]);const[,U]=w();i(()=>{let e=!0;return(async()=>{try{const n=await u({environment:L.current.environment,debug:L.current.debug,dataNamespace:L.current.dataNamespace,dataSdkIntegrationSource:L.current.dataSdkIntegrationSource});n&&e&&D(n)}catch(n){e&&(U(n),R({type:p.SET_ERROR,value:v(n)}))}})(),()=>{e=!1}},[U]),i(()=>{if(!A)return;if(!r&&!o)return;R({type:p.SET_LOADING_STATUS,value:d.PENDING});let e=!0;return(async()=>{try{const t=r||o,a=!!r;let i;if("string"==typeof t)i=t;else if(t)try{i=await t}catch(n){const r=new Error(`Failed to resolve ${a?"clientToken":"clientId"}. Expected a Promise that resolves to a string, but it was rejected with: ${v(n).message}`);return void(e&&(U(r),R({type:p.SET_ERROR,value:r})))}if(!i||!e)return;const l={clientMetadataId:n,components:N,locale:y,pageType:m,partnerAttributionId:P,shopperSessionId:f,testBuyerCountry:S,merchantId:M},s=a?{...l,clientToken:i}:{...l,clientId:i},c=await A.createInstance(s);if(!e)return;R({type:p.SET_INSTANCE,value:c})}catch(n){e&&(U(n),R({type:p.SET_ERROR,value:v(n)}))}})(),()=>{e=!1}},[n,r,o,y,N,M,m,P,A,f,S,U]),i(()=>{const e=O.sdkInstance;if(e)try{if(b){const n=e.hydrateEligibleMethods(b);R({type:p.SET_ELIGIBILITY,value:{eligiblePaymentMethods:n,payload:null}})}}catch(e){U(e),R({type:p.SET_ERROR,value:v(e)})}},[O.sdkInstance,b,U]);const _=l(()=>({sdkInstance:O.sdkInstance,eligiblePaymentMethods:O.eligiblePaymentMethods,eligiblePaymentMethodsPayload:O.eligiblePaymentMethodsPayload,error:O.error,loadingStatus:O.loadingStatus,isHydrated:G}),[O.sdkInstance,O.eligiblePaymentMethods,O.eligiblePaymentMethodsPayload,O.error,O.loadingStatus,G]);return e.createElement(j.Provider,{value:R},e.createElement(E.Provider,{value:_},I))},Y={braintreePayPalCheckoutInstance:null,eligiblePaymentMethods:null,eligiblePaymentMethodsPayload:null,loadingStatus:d.PENDING,error:null,isHydrated:!1};function $(e,n){switch(n.type){case y.SET_LOADING_STATUS:return{...e,loadingStatus:n.value};case y.SET_INSTANCE:return{...e,braintreePayPalCheckoutInstance:n.value,loadingStatus:d.RESOLVED};case y.SET_ELIGIBILITY:return{...e,eligiblePaymentMethods:n.value.eligiblePaymentMethods,eligiblePaymentMethodsPayload:n.value.payload};case y.SET_ERROR:return{...e,error:n.value,loadingStatus:d.REJECTED};case y.RESET_STATE:return Y;default:return e}}const x=n(null),J=n(null),W=({namespace:n,braintreeClientToken:r,children:o})=>{const[s,u]=c($,Y),[p,h]=a(!1),[,g]=w(),E=t(null);K(()=>{h(!0)},[]),i(()=>{if(!m(n)){const e=new Error("Invalid Braintree namespace. Ensure the Braintree client and paypal-checkout-v6 scripts are loaded and that namespace.client.create and namespace.paypalCheckoutV6.create are functions.");return g(e),void u({type:y.SET_ERROR,value:e})}let e=!0;u({type:y.SET_LOADING_STATUS,value:d.PENDING});return(async()=>{if(!r){const n=new Error("Braintree client token is required to initialize the PayPal Checkout instance.");return void(e&&(g(n),u({type:y.SET_ERROR,value:n})))}try{const t=await n.client.create({authorization:r});if(!e)return;const a=await n.paypalCheckoutV6.create({client:t});if(!e)return;if(await a.loadPayPalSDK(),!e)return;E.current=a,u({type:y.SET_INSTANCE,value:a})}catch(n){e&&(g(n),u({type:y.SET_ERROR,value:v(n)}))}})(),()=>{e=!1,E.current?.teardown(),E.current=null}},[n,r,g]);const P=l(()=>({braintreePayPalCheckoutInstance:s.braintreePayPalCheckoutInstance,eligiblePaymentMethods:s.eligiblePaymentMethods,eligiblePaymentMethodsPayload:s.eligiblePaymentMethodsPayload,loadingStatus:s.loadingStatus,error:s.error,isHydrated:p}),[s.braintreePayPalCheckoutInstance,s.eligiblePaymentMethods,s.eligiblePaymentMethodsPayload,s.loadingStatus,s.error,p]);return e.createElement(J.Provider,{value:u},e.createElement(x.Provider,{value:P},o))};function Z(){const e=r(x);if(null===e)throw new Error("useBraintreePayPal must be used within a BraintreePayPalProvider");return e}function Q({onApprove:e,onCancel:n,onError:r,onShippingAddressChange:a,onShippingOptionsChange:l,amount:s,currency:c,intent:u,commit:p,offerCredit:y,userAuthenticationEmail:m,returnUrl:h,cancelUrl:g,displayName:E,presentationMode:P,shippingCallbackUrl:v,lineItems:S,shippingOptions:I,amountBreakdown:k,shippingAddressOverride:T}){const{braintreePayPalCheckoutInstance:N,loadingStatus:M,error:D}=Z(),O=A(),R=t(null),[G,B]=w(),L=t(null),U=f({onApprove:e,onCancel:n,onError:r,onShippingAddressChange:a,onShippingOptionsChange:l}),_=C(S),F=C(I),H=C(k),V=C(T),q=M===d.PENDING;i(()=>{L.current!==N&&(L.current=null),N?B(null):M!==d.PENDING&&B(D?new Error(`Braintree provider error: ${D.message}`,{cause:D}):new Error("Braintree One-Time Payment checkout instance not available"))},[N,B,M,D]),i(()=>{if(!N)return;const e=b({sessionCreator:()=>N.createOneTimePaymentSession({amount:s,currency:c,intent:u,commit:p,offerCredit:y,userAuthenticationEmail:m,returnUrl:h,cancelUrl:g,displayName:E,presentationMode:P,shippingCallbackUrl:v,lineItems:_,shippingOptions:F,amountBreakdown:H,shippingAddressOverride:V,...U}),failedSdkRef:L,sdkInstance:N,setError:B,errorMessage:"Failed to create Braintree payment session. Ensure the BraintreePayPalProvider is properly initialized with a valid client token and namespace."});return e?(R.current=e,()=>{R.current=null}):void 0},[N,s,c,u,p,y,m,h,g,E,P,v,_,F,H,V,U,B]);return{error:G,isPending:q,handleClick:o(()=>{O.current&&(R.current?R.current.start():B(new Error("Braintree payment session not available")))},[O,B])}}const X=({type:n="pay",disabled:r=!1,onApprove:t,onCancel:a,onError:o,onShippingAddressChange:l,onShippingOptionsChange:s,amount:c,currency:u,intent:d,commit:p,offerCredit:y,userAuthenticationEmail:m,returnUrl:h,cancelUrl:g,displayName:E,presentationMode:P,lineItems:f,shippingOptions:v,amountBreakdown:C})=>{const{error:S,isPending:b,handleClick:I}=Q({onApprove:t,onCancel:a,onError:o,onShippingAddressChange:l,onShippingOptionsChange:s,amount:c,currency:u,intent:d,commit:p,offerCredit:y,userAuthenticationEmail:m,returnUrl:h,cancelUrl:g,displayName:E,presentationMode:P,lineItems:f,shippingOptions:v,amountBreakdown:C}),{isHydrated:k}=Z();return i(()=>{S&&console.error(S)},[S]),k?e.createElement("paypal-button",{onClick:I,type:n,disabled:!(!r&&!b&&null===S)||void 0}):e.createElement("div",null)};function ee({onApprove:e,onCancel:n,onError:r,billingAgreementDescription:a,planType:l,amount:s,currency:c,offerCredit:u,userAction:p,displayName:y,returnUrl:m,cancelUrl:h,presentationMode:g,planMetadata:E,shippingAddressOverride:P}){const{braintreePayPalCheckoutInstance:v,loadingStatus:S,error:I}=Z(),k=A(),T=t(null),[N,M]=w(),D=t(null),O=f({onApprove:e,onCancel:n,onError:r}),R=C(E),G=C(P),B=S===d.PENDING;i(()=>{D.current!==v&&(D.current=null),v?M(null):S!==d.PENDING&&M(I?new Error(`Braintree provider error: ${I.message}`,{cause:I}):new Error("Braintree Billing Agreement checkout instance not available"))},[v,M,S,I]),i(()=>{if(!v)return;const e=b({sessionCreator:()=>v.createBillingAgreementSession({billingAgreementDescription:a,planType:l,amount:s,currency:c,offerCredit:u,userAction:p,displayName:y,returnUrl:m,cancelUrl:h,presentationMode:g,planMetadata:R,shippingAddressOverride:G,...O}),failedSdkRef:D,sdkInstance:v,setError:M,errorMessage:"Failed to create Braintree billing agreement session. Ensure the BraintreePayPalProvider is properly initialized with a valid client token and namespace."});return e?(T.current=e,()=>{T.current=null}):void 0},[v,a,l,s,c,u,p,y,m,h,g,R,G,O,M]);return{error:N,isPending:B,handleClick:o(()=>{k.current&&(T.current?T.current.start():M(new Error("Braintree billing agreement session not available")))},[k,M])}}const ne=({type:n="pay",disabled:r=!1,onApprove:t,onCancel:a,onError:o,billingAgreementDescription:l,planType:s,amount:c,currency:u,offerCredit:d,userAction:p,displayName:y,returnUrl:m,cancelUrl:h,presentationMode:g,planMetadata:E,shippingAddressOverride:P})=>{const{error:f,isPending:v,handleClick:C}=ee({onApprove:t,onCancel:a,onError:o,billingAgreementDescription:l,planType:s,amount:c,currency:u,offerCredit:d,userAction:p,displayName:y,returnUrl:m,cancelUrl:h,presentationMode:g,planMetadata:E,shippingAddressOverride:P}),{isHydrated:S}=Z();return i(()=>{f&&console.error(f)},[f]),S?e.createElement("paypal-button",{onClick:C,type:n,disabled:!(!r&&!v&&null===f)||void 0}):e.createElement("div",null)};function re({onApprove:e,onCancel:n,onError:r,onShippingAddressChange:a,onShippingOptionsChange:l,amount:s,currency:c,intent:u,commit:p,userAuthenticationEmail:y,returnUrl:m,cancelUrl:h,displayName:g,presentationMode:E,shippingCallbackUrl:P,billingAgreementDetails:v,lineItems:S,shippingOptions:I,amountBreakdown:k}){const{braintreePayPalCheckoutInstance:T,loadingStatus:N,error:M}=Z(),D=A(),O=t(null),[R,G]=w(),B=t(null),L=f({onApprove:e,onCancel:n,onError:r,onShippingAddressChange:a,onShippingOptionsChange:l}),U=C(v),_=C(S),F=C(I),H=C(k),V=N===d.PENDING;i(()=>{B.current!==T&&(B.current=null),T?G(null):N!==d.PENDING&&G(M?new Error(`Braintree provider error: ${M.message}`,{cause:M}):new Error("Braintree Checkout With Vault checkout instance not available"))},[T,G,N,M]),i(()=>{if(!T)return;const e=b({sessionCreator:()=>T.createCheckoutWithVaultSession({amount:s,currency:c,intent:u,commit:p,userAuthenticationEmail:y,returnUrl:m,cancelUrl:h,displayName:g,presentationMode:E,shippingCallbackUrl:P,billingAgreementDetails:U,lineItems:_,shippingOptions:F,amountBreakdown:H,...L}),failedSdkRef:B,sdkInstance:T,setError:G,errorMessage:"Failed to create Braintree checkout with vault session. Ensure the BraintreePayPalProvider is properly initialized with a valid client token and namespace."});return e?(O.current=e,()=>{O.current=null}):void 0},[T,s,c,u,p,y,m,h,g,E,P,U,_,F,H,L,G]);return{error:R,isPending:V,handleClick:o(()=>{D.current&&(O.current?O.current.start():G(new Error("Braintree checkout with vault session not available")))},[D,G])}}const te=({type:n="pay",disabled:r=!1,onApprove:t,onCancel:a,onError:o,onShippingAddressChange:l,onShippingOptionsChange:s,amount:c,currency:u,intent:d,commit:p,userAuthenticationEmail:y,returnUrl:m,cancelUrl:h,displayName:g,presentationMode:E,billingAgreementDetails:P,lineItems:f,shippingOptions:v,amountBreakdown:C})=>{const{error:S,isPending:b,handleClick:I}=re({onApprove:t,onCancel:a,onError:o,onShippingAddressChange:l,onShippingOptionsChange:s,amount:c,currency:u,intent:d,commit:p,userAuthenticationEmail:y,returnUrl:m,cancelUrl:h,displayName:g,presentationMode:E,billingAgreementDetails:P,lineItems:f,shippingOptions:v,amountBreakdown:C}),{isHydrated:k}=Z();return i(()=>{S&&console.error(S)},[S]),k?e.createElement("paypal-button",{onClick:I,type:n,disabled:!!(r||b||S)||void 0}):e.createElement("div",null)};function ae({onApprove:e,onCancel:n,onComplete:r,onError:a,onShippingAddressChange:l,onShippingOptionsChange:s,amount:c,currency:u,intent:p,userAuthenticationEmail:y,returnUrl:m,cancelUrl:h,displayName:g,presentationMode:E,shippingCallbackUrl:P,lineItems:v,shippingOptions:S,amountBreakdown:I,shippingAddressOverride:k,contactPreference:T}){const{braintreePayPalCheckoutInstance:N,loadingStatus:M,error:D}=Z(),O=A(),R=t(null),[G,B]=w(),L=t(null),U=f({onApprove:e,onCancel:n,onComplete:r,onError:a,onShippingAddressChange:l,onShippingOptionsChange:s}),_=C(v),F=C(S),H=C(I),V=C(k),q=M===d.PENDING;i(()=>{L.current!==N&&(L.current=null),N?B(null):M!==d.PENDING&&B(D?new Error(`Braintree provider error: ${D.message}`,{cause:D}):new Error("Braintree Pay Later checkout instance not available"))},[N,B,M,D]),i(()=>{if(!N)return;const e=b({sessionCreator:()=>N.createPayLaterSession({amount:c,currency:u,intent:p,userAuthenticationEmail:y,returnUrl:m,cancelUrl:h,displayName:g,presentationMode:E,shippingCallbackUrl:P,lineItems:_,shippingOptions:F,amountBreakdown:H,shippingAddressOverride:V,contactPreference:T,...U}),failedSdkRef:L,sdkInstance:N,setError:B,errorMessage:"Failed to create Braintree Pay Later session. Ensure the BraintreePayPalProvider is properly initialized with a valid client token and namespace."});return e?(R.current=e,()=>{R.current=null}):void 0},[N,c,u,p,y,m,h,g,E,P,T,_,F,H,V,U,B]);return{error:G,isPending:q,handleClick:o(()=>{O.current&&(R.current?R.current.start():B(new Error("Braintree payment session not available")))},[O,B])}}const oe=({disabled:n=!1,...r})=>{const{eligiblePaymentMethods:t,isHydrated:a}=Z(),{error:o,isPending:l,handleClick:s}=ae(r),c=t?.getDetails("paylater");return i(()=>{o&&console.error(o)},[o]),a?e.createElement("paypal-pay-later-button",{onClick:s,countryCode:c?.countryCode,productCode:c?.productCode,disabled:!(!n&&!l&&null===o)||void 0}):e.createElement("div",null)};function ie({presentationMode:e="auto",fullPageOverlay:n,autoRedirect:r,createVaultToken:a,vaultSetupToken:l,...s}){const{sdkInstance:c,loadingStatus:u}=P(),p=A(),y=t(null),m=f(s),[h,g]=w(),E=t(null),v=u===d.PENDING,C=o(()=>{y.current?.destroy(),y.current=null},[]);i(()=>{E.current!==c&&(E.current=null),c?g(null):u!==d.PENDING&&g(new Error("no sdk instance available"))},[c,g,u]),i(()=>{if(!c)return;const n=b({sessionCreator:()=>c.createPayPalSavePaymentSession({vaultSetupToken:l,...m}),failedSdkRef:E,sdkInstance:c,setError:g,errorMessage:'Failed to create payment session. This may occur if the required component "paypal-payments" is not included in the SDK components array.'});if(!n)return;y.current=n;if("redirect"===e||"direct-app-switch"===e){(async()=>{try{if(!n)return;const e=n.hasReturned?.();e&&await(n.resume?.())}catch(e){g(e)}})()}return()=>{n.destroy()}},[c,l,m,e,g]);const S=o(()=>{y.current?.cancel()},[]);return{error:h,isPending:v,handleClick:o(async()=>{if(!p.current)return;if(!y.current)return void g(new Error("Save Payment session not available"));const t={presentationMode:e,fullPageOverlay:n,autoRedirect:r};a?await y.current.start(t,a()):await y.current.start(t)},[p,e,n,r,a,g]),handleCancel:S,handleDestroy:C}}const le=({type:n="pay",disabled:r=!1,...t})=>{const{error:a,isPending:o,handleClick:l}=ie(t),{isHydrated:s}=P();return i(()=>{a&&console.error(a)},[a]),s?e.createElement("paypal-button",{type:n,disabled:!(!r&&!o&&null===a)||void 0,onClick:l}):e.createElement("div",null)};function se({presentationMode:e="auto",fullPageOverlay:n,createOrder:r,orderId:a,...l}){const{sdkInstance:s,loadingStatus:c}=P(),u=A(),p=t(null),y=f(l),[m,h]=w(),g=t(null),E=c===d.PENDING,v=o(()=>{p.current?.destroy(),p.current=null},[]);i(()=>{g.current!==s&&(g.current=null),s?h(null):c!==d.PENDING&&h(new Error("no sdk instance available"))},[s,h,c]),i(()=>{if(!s)return;const e=b({sessionCreator:()=>s.createVenmoOneTimePaymentSession({orderId:a,...y}),failedSdkRef:g,sdkInstance:s,setError:h,errorMessage:'Failed to create payment session. This may occur if the required component "venmo-payments" is not included in the SDK components array.'});return e?(p.current=e,()=>{e.destroy()}):void 0},[s,a,y,h]);return{error:m,isPending:E,handleCancel:o(()=>{p.current?.cancel()},[]),handleClick:o(async()=>{if(!u.current)return;if(!p.current)return void h(new Error("Venmo session not available"));const t={presentationMode:e,fullPageOverlay:n};await p.current.start(t,r?.())},[u,e,n,r,h]),handleDestroy:v}}const ce=({type:n="pay",disabled:r=!1,...t})=>{const{error:a,isPending:o,handleClick:l}=se(t),{isHydrated:s}=P();return i(()=>{a&&console.error(a)},[a]),s?e.createElement("venmo-button",{onClick:l,type:n,disabled:!(!r&&!o&&null===a)||void 0}):e.createElement("div",null)};function ue({applePayConfig:e,paymentRequest:n,displayName:r,domainName:a,createOrder:l,applePaySessionVersion:s,...c}){const{sdkInstance:u,loadingStatus:p}=P(),y=A(),m=t(null),h=t(null),g=f(c),[E,C]=w(),S=t(null),I=p===d.PENDING,k=o(()=>{if(h.current){try{h.current.abort()}catch{}h.current=null}},[]),T=o(()=>{k(),m.current=null},[k]);i(()=>{S.current!==u&&(S.current=null),u?C(null):p!==d.PENDING&&C(new Error("no sdk instance available"))},[u,C,p]),i(()=>{if(!u)return;const e=b({sessionCreator:()=>u.createApplePayOneTimePaymentSession(),failedSdkRef:S,sdkInstance:u,setError:C,errorMessage:'Failed to create payment session. This may occur if the required component "applepay-payments" is not included in the SDK components array.'});return e?(m.current=e,()=>{m.current=null}):void 0},[u,C]);return{error:E,isPending:I,handleClick:o(async()=>{if(!y.current)return;if(C(null),!m.current)return void C(new Error("Apple Pay session not available"));if("undefined"==typeof window||!window.ApplePaySession?.canMakePayments())return void C(new Error("Apple Pay is not available"));if("https:"!==window.location.protocol)return void C(new Error("Apple Pay requires a secure (HTTPS) connection"));const{ApplePaySession:t}=window;try{const o=m.current,i=o.formatConfigForPaymentRequest(e),c={...n,...i},u=new t(s,c);h.current=u,u.onvalidatemerchant=async e=>{try{const n=await o.validateMerchant({validationUrl:e.validationURL,...r&&{displayName:r},...a&&{domainName:a}});u.completeMerchantValidation(n.merchantSession)}catch(e){const n=v(e);C(n),g.onError?.(n),u.abort()}},u.onpaymentmethodselected=()=>{u.completePaymentMethodSelection({newTotal:n.total})},u.onpaymentauthorized=async e=>{let n=!1;const r=e=>{if(!n){n=!0;try{u.completePayment({status:e})}catch(e){const n=v(e);C(n),g.onError?.(n)}}};try{const n=await l(),a=await o.confirmOrder({orderId:n.orderId,token:e.payment.token,billingContact:e.payment.billingContact,shippingContact:e.payment.shippingContact});await g.onApprove(a),r(t.STATUS_SUCCESS);try{await(g.onApproveCompleted?.(a))}catch(e){const n=v(e);C(n),g.onError?.(n)}}catch(e){const n=v(e);C(n),g.onError?.(n),r(t.STATUS_FAILURE)}},u.oncancel=()=>{h.current=null,g.onCancel?.()},u.begin()}catch(e){const n=v(e);C(n),g.onError?.(n)}},[y,e,n,r,a,l,s,g,C]),handleCancel:k,handleDestroy:T}}const de=({buttonstyle:n="black",type:r="pay",locale:a="en",className:o,...l})=>{const{error:s,handleClick:c,handleDestroy:u}=ue(l),{isHydrated:d}=P(),p=t(null),y=t(c);return y.current=c,i(()=>{const e=p.current;if(!e)return;const n=()=>{y.current().catch(()=>{})};return e.addEventListener("click",n),()=>e.removeEventListener("click",n)},[]),i(()=>{s&&console.error(s)},[s]),i(()=>()=>{u()},[u]),d?e.createElement("div",{className:o},e.createElement("apple-pay-button",{ref:p,buttonstyle:n,type:r,locale:a})):e.createElement("div",null)};function pe({googlePayConfig:e,transactionInfo:n,environment:r="TEST",createOrder:l,...s}){const{sdkInstance:c,loadingStatus:u}=P(),p=A(),y=t(null),m=t(null),h=t(l);h.current=l;const g=f(s),[E,C]=w(),[S,I]=a(null),[k,T]=a(null),N=t(null),M=u===d.PENDING,D=o(()=>{},[]),O=o(()=>{y.current=null,m.current=null,I(null),T(null)},[]);i(()=>{N.current!==c&&(N.current=null),c?C(null):u!==d.PENDING&&C(new Error("no sdk instance available"))},[c,C,u]),i(()=>{if(!c)return;const e=b({sessionCreator:()=>c.createGooglePayOneTimePaymentSession(),failedSdkRef:N,sdkInstance:c,setError:C,errorMessage:'Failed to create payment session. This may occur if the required component "googlepay-payments" is not included in the SDK components array.'});return e?(y.current=e,()=>{y.current=null}):void 0},[c,C]),i(()=>{if(!y.current)return m.current=null,I(null),void T(null);if("undefined"==typeof window||!window.google?.payments?.api?.PaymentsClient){m.current=null,I(null),T(null);const e=new Error('Google Pay JS SDK (pay.js) is not loaded. Add <script src="https://pay.google.com/gp/p/js/pay.js"><\/script> to your HTML before <GooglePayOneTimePaymentButton> mounts.');return C(e),void g.onError?.(e)}try{const n=y.current,t=n.formatConfigForPaymentRequest(e),a=new window.google.payments.api.PaymentsClient({environment:r,paymentDataCallbacks:{onPaymentAuthorized:async e=>{try{const r=await h.current(),t=await n.confirmOrder({orderId:r.orderId,paymentMethodData:e.paymentMethodData});return"PAYER_ACTION_REQUIRED"===t.status&&n.initiatePayerAction(),await g.onApprove(t),{transactionState:"SUCCESS"}}catch(e){const n=v(e);return C(n),g.onError?.(n),{transactionState:"ERROR",error:{intent:"PAYMENT_AUTHORIZATION",message:n.message,reason:"OTHER_ERROR"}}}}}});m.current=a,I(a),T(t)}catch(e){m.current=null,I(null),T(null);const n=v(e);C(n),g.onError?.(n)}},[e,r,g,c,C]);const R=o(async e=>{if(!m.current||!k)return null;try{return(await m.current.isReadyToPay({allowedPaymentMethods:k.allowedPaymentMethods,apiVersion:k.apiVersion,apiVersionMinor:k.apiVersionMinor})).result?m.current.createButton(e):null}catch(e){const n=v(e);return C(n),g.onError?.(n),null}},[k,g,C]),G=o(async()=>{if(p.current)if(C(null),y.current)if(m.current&&k)try{const e={apiVersion:k.apiVersion,apiVersionMinor:k.apiVersionMinor,allowedPaymentMethods:k.allowedPaymentMethods,merchantInfo:k.merchantInfo,transactionInfo:n,callbackIntents:["PAYMENT_AUTHORIZATION"]};await m.current.loadPaymentData(e)}catch(e){if("CANCELED"===e?.statusCode)return void g.onCancel?.()}else C(new Error("Google Pay client is not available"));else C(new Error("Google Pay session not available"))},[p,n,k,g,C]);return{error:E,isPending:M,paymentsClient:S,formattedConfig:k,createGooglePayButton:R,handleClick:G,handleCancel:D,handleDestroy:O}}const ye=({disabled:n=!1,buttonType:r="pay",buttonColor:a="default",buttonSizeMode:l="fill",buttonLocale:s,...c})=>{const{isPending:u,handleClick:d,handleDestroy:p,createGooglePayButton:y}=pe(c),{isHydrated:m}=P(),h=t(null),g=t(!1),E=t(d);E.current=d;const f=n||u,v=o(()=>{const e=h.current;if(!e||g.current)return;(async()=>{const n=await y({onClick:()=>{E.current()},buttonType:r,buttonColor:a,buttonSizeMode:l,...s&&{buttonLocale:s}});n&&(e.replaceChildren(n),g.current=!0)})()},[y,r,a,l,s]);return i(()=>{m&&!u&&(g.current=!1,v())},[m,u,v]),i(()=>()=>{p()},[p]),m?e.createElement("div",{ref:h,"aria-disabled":f||void 0,style:f?{pointerEvents:"none",opacity:"0.5"}:void 0}):e.createElement("div",null)};function me(){const e=r(k);if(null===e)throw new Error("usePayPalCardFields must be used within a PayPalCardFieldsProvider");return e}function he(){const e=r(I);if(null===e)throw new Error("usePayPalCardFieldsSession must be used within a PayPalCardFieldsProvider");return e}const ge=({containerStyles:n,containerClassName:r,...a})=>{const{cardFieldsSession:o,setError:l}=he(),s=t(null),c=t(a);return i(()=>{if(!o)return;let e;c.current=a;try{e=o.createCardFieldsComponent(c.current),s.current?.appendChild(e)}catch(e){l(v(e))}return()=>{e?.remove(),e?.destroy()}},[o]),e.createElement("div",{style:n,className:r,ref:s})},Ee=({containerStyles:n,containerClassName:r,placeholder:t,label:a,style:o,ariaDescription:i,ariaLabel:l,ariaInvalidErrorMessage:s})=>e.createElement(ge,{type:"number",containerStyles:n,containerClassName:r,placeholder:t,label:a,style:o,ariaDescription:i,ariaLabel:l,ariaInvalidErrorMessage:s}),Pe=({containerStyles:n,containerClassName:r,placeholder:t,label:a,style:o,ariaDescription:i,ariaLabel:l,ariaInvalidErrorMessage:s})=>e.createElement(ge,{type:"expiry",containerStyles:n,containerClassName:r,placeholder:t,label:a,style:o,ariaDescription:i,ariaLabel:l,ariaInvalidErrorMessage:s}),fe=({containerStyles:n,containerClassName:r,placeholder:t,label:a,style:o,ariaDescription:i,ariaLabel:l,ariaInvalidErrorMessage:s})=>e.createElement(ge,{type:"cvv",containerStyles:n,containerClassName:r,placeholder:t,label:a,style:o,ariaDescription:i,ariaLabel:l,ariaInvalidErrorMessage:s});function ve(e){const{braintreePayPalCheckoutInstance:n,eligiblePaymentMethods:o,eligiblePaymentMethodsPayload:l,loadingStatus:s,error:c}=Z(),u=function(){const e=r(J);if(null===e)throw new Error("useBraintreePayPalDispatch must be used within a BraintreePayPalProvider");return e}(),p=A(),[m,h]=w(),[g,E]=a(!1),P=t(o),f=t(l);P.current=o,f.current=l;const v=C(e),b=t(null),I=t(null);i(()=>{if(I.current?.instance!==n&&(I.current=null),!n)return;if(I.current?.instance===n&&I.current?.payload===v)return;if(b.current?.instance===n&&b.current?.payload===v)return;if(P.current&&null===b.current&&S(f.current,v))return void(b.current={instance:n,payload:v});b.current={instance:n,payload:v};let e=!0,r=!1;return E(!0),h(null),n.findEligibleMethods(v).then(n=>{e&&p.current&&u({type:y.SET_ELIGIBILITY,value:{eligiblePaymentMethods:n,payload:v}})}).catch(r=>{e&&p.current&&(I.current={instance:n,payload:v},h(r))}).finally(()=>{r=!0,e&&p.current&&E(!1)}),()=>{e=!1,r||b.current?.instance!==n||b.current?.payload!==v||(b.current=null)}},[n,v,u,h,p]);const k=!!o&&!S(l??void 0,v??void 0),T=!m&&(s===d.PENDING||g||!o||k);return c?{eligiblePaymentMethods:o,isLoading:!1,error:new Error(`Braintree PayPal context error: ${c}`)}:{eligiblePaymentMethods:o,isLoading:T,error:m}}function Ce(e={}){const{payload:n}=e,{sdkInstance:o,eligiblePaymentMethods:l,eligiblePaymentMethodsPayload:s,error:c}=P(),u=function(){const e=r(j);if(null===e)throw new Error("usePayPalDispatch must be used within a PayPalProvider");return e}(),[d,y]=w(),[m,h]=a(!1),g=t(l),E=t(s);g.current=l,E.current=s;const f=C(n),v=t(null);i(()=>{if(!o)return;if(v.current?.instance===o&&v.current?.payload===f)return;if(g.current&&null===v.current&&S(E.current,f))return void(v.current={instance:o,payload:f});v.current={instance:o,payload:f};let e=!0;return h(!0),y(null),o.findEligibleMethods(f).then(n=>{e&&u({type:p.SET_ELIGIBILITY,value:{eligiblePaymentMethods:n,payload:f}})}).catch(n=>{e&&y(n)}).finally(()=>{e&&h(!1)}),()=>{e=!1,v.current=null}},[o,f,u,y]);const b=!!l&&!S(s??void 0,f??void 0),I=!d&&(m||!l||b);return c?{eligiblePaymentMethods:l,isLoading:!1,error:new Error(`PayPal context error: ${c}`)}:{eligiblePaymentMethods:l,isLoading:I,error:d}}function Se({buyerCountry:e,currencyCode:n,shopperSessionId:r}){const{sdkInstance:t,loadingStatus:l}=P(),s=A(),[c,u]=a(null),[p,y]=w();i(()=>{t?y(null):l!==d.PENDING&&y(new Error("no sdk instance available"))},[t,y,l]),i(()=>{if(!t)return;const a=t.createPayPalMessages({buyerCountry:e,currencyCode:n,shopperSessionId:r});return u(a),()=>{u(null)}},[e,n,t,r]);const m=o(async e=>{if(!s.current)return;if(!c)return void y(new Error("PayPal Messages session not available"));const n=await c.fetchContent(e);if(null!==n)return n;y(new Error("Failed to fetch PayPal Messages content"))},[s,c,y]),h=o(e=>{if(s.current){if(c)return c.createLearnMore(e);y(new Error("PayPal Messages session not available"))}},[s,c,y]);return{error:p,isReady:Boolean(c),handleCreateLearnMore:h,handleFetchContent:m}}function be(){const{cardFieldsSession:e,setCardFieldsSessionType:n}=he(),[r,t]=a(null),[l,s]=w();i(()=>{n(T)},[n]);const c=o(async(n,r)=>{if(!e)return s(v("Submit error: CardFields session not available")),void t(null);try{const a=await n,o=await e.submit(a,r);t(o),s(null)}catch(e){s(v(e)),t(null)}},[e,s]);return{submit:c,submitResponse:r,error:l}}function Ie(){const{cardFieldsSession:e,setCardFieldsSessionType:n}=he(),[r,t]=a(null),[l,s]=w();i(()=>{n(N)},[n]);const c=o(async(n,r)=>{if(!e)return s(v("Submit error: CardFields session not available")),void t(null);try{const a=await n,o=await e.submit(a,r);t(o),s(null)}catch(e){s(v(e)),t(null)}},[e,s]);return{submit:c,submitResponse:r,error:l}}export{de as ApplePayOneTimePaymentButton,y as BRAINTREE_DISPATCH_ACTION,ne as BraintreePayPalBillingAgreementButton,te as BraintreePayPalCheckoutWithVaultButton,X as BraintreePayPalOneTimePaymentButton,oe as BraintreePayPalPayLaterButton,W as BraintreePayPalProvider,ye as GooglePayOneTimePaymentButton,p as INSTANCE_DISPATCH_ACTION,d as INSTANCE_LOADING_STATE,O as PayLaterOneTimePaymentButton,fe as PayPalCardCvvField,Pe as PayPalCardExpiryField,M as PayPalCardFieldsProvider,Ee as PayPalCardNumberField,G as PayPalCreditOneTimePaymentButton,L as PayPalCreditSavePaymentButton,_ as PayPalGuestPaymentButton,H as PayPalOneTimePaymentButton,z as PayPalProvider,le as PayPalSavePaymentButton,q as PayPalSubscriptionButton,ce as VenmoOneTimePaymentButton,ue as useApplePayOneTimePaymentSession,ve as useBraintreeEligibleMethods,Z as useBraintreePayPal,ee as useBraintreePayPalBillingAgreementSession,re as useBraintreePayPalCheckoutWithVaultSession,Q as useBraintreePayPalOneTimePaymentSession,ae as useBraintreePayPalPayLaterSession,Ce as useEligibleMethods,pe as useGooglePayOneTimePaymentSession,D as usePayLaterOneTimePaymentSession,P as usePayPal,me as usePayPalCardFields,be as usePayPalCardFieldsOneTimePaymentSession,Ie as usePayPalCardFieldsSavePaymentSession,R as usePayPalCreditOneTimePaymentSession,B as usePayPalCreditSavePaymentSession,U as usePayPalGuestPaymentSession,Se as usePayPalMessages,F as usePayPalOneTimePaymentSession,ie as usePayPalSavePaymentSession,V as usePayPalSubscriptionPaymentSession,se as useVenmoOneTimePaymentSession,m as validateBraintreeNamespace};