!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactStripe={},e.React)}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function r(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==n)return;var r,o,c=[],u=!0,i=!1;try{for(n=n.call(e);!(u=(r=n.next()).done)&&(c.push(r.value),!t||c.length!==t);u=!0);}catch(e){i=!0,o=e}finally{try{u||null==n.return||n.return()}finally{if(i)throw o}}return c}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:k;if(null===e||g(t=e)&&"function"==typeof t.elements&&"function"==typeof t.createToken&&"function"==typeof t.createPaymentMethod&&"function"==typeof t.confirmCardPayment)return e;throw new Error(n)},P=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;if(function(e){return g(e)&&"function"==typeof e.then}(e))return{tag:"async",stripePromise:Promise.resolve(e).then((function(e){return S(e,t)}))};var n=S(e,t);return null===n?{tag:"empty"}:{tag:"sync",stripe:n}},w=function(e){e&&e._registerWrapper&&e.registerAppInfo&&(e._registerWrapper({name:"react-stripe-js",version:"3.10.0"}),e.registerAppInfo({name:"react-stripe-js",version:"3.10.0",url:"https://stripe.com/docs/stripe-js/react"}))},O=t.createContext(null);O.displayName="ElementsContext";var j=function(e,t){if(!e)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(t," in an provider."));return e},x=function(e){var n=e.stripe,r=e.options,o=e.children,c=t.useMemo((function(){return P(n)}),[n]),u=i(t.useState((function(){return{stripe:"sync"===c.tag?c.stripe:null,elements:"sync"===c.tag?c.stripe.elements(r):null}})),2),a=u[0],s=u[1];t.useEffect((function(){var e=!0,t=function(e){s((function(t){return t.stripe?t:{stripe:e,elements:e.elements(r)}}))};return"async"!==c.tag||a.stripe?"sync"!==c.tag||a.stripe||t(c.stripe):c.stripePromise.then((function(n){n&&e&&t(n)})),function(){e=!1}}),[c,a,r]);var l=v(n);t.useEffect((function(){null!==l&&l!==n&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.")}),[l,n]);var p=v(r);return t.useEffect((function(){if(a.elements){var e=b(r,p,["clientSecret","fonts"]);e&&a.elements.update(e)}}),[r,p,a.elements]),t.useEffect((function(){w(a.stripe)}),[a.stripe]),t.createElement(O.Provider,{value:a},o)};x.propTypes={stripe:h.any,options:h.object};var A=function(e){var n=t.useContext(O);return j(n,e)},R=function(e){return(0,e.children)(A("mounts "))};R.propTypes={children:h.func.isRequired};var I=["on","session"],T=t.createContext(null);T.displayName="CheckoutSdkContext";var M=function(e,t){if(!e)throw new Error("Could not find CheckoutProvider context; You need to wrap the part of your app that ".concat(t," in an provider."));return e},N=t.createContext(null);N.displayName="CheckoutContext";var U=function(e){var n=e.stripe,r=e.options,o=e.children,c=t.useMemo((function(){return P(n,"Invalid prop `stripe` supplied to `CheckoutProvider`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.")}),[n]),a=i(t.useState(null),2),s=a[0],l=a[1],p=i(t.useState((function(){return{stripe:"sync"===c.tag?c.stripe:null,checkoutSdk:null}})),2),f=p[0],d=p[1],m=function(e,t){d((function(n){return n.stripe&&n.checkoutSdk?n:{stripe:e,checkoutSdk:t}}))},h=t.useRef(!1);t.useEffect((function(){var e=!0;return"async"!==c.tag||f.stripe?"sync"===c.tag&&c.stripe&&!h.current&&(h.current=!0,c.stripe.initCheckout(r).then((function(e){e&&(m(c.stripe,e),e.on("change",l))}))):c.stripePromise.then((function(t){t&&e&&!h.current&&(h.current=!0,t.initCheckout(r).then((function(e){e&&(m(t,e),e.on("change",l))})))})),function(){e=!1}}),[c,f,r,l]);var y=v(n);t.useEffect((function(){null!==y&&y!==n&&console.warn("Unsupported prop change on CheckoutProvider: You cannot change the `stripe` prop after setting it.")}),[y,n]);var g=v(r),C=v(f.checkoutSdk);t.useEffect((function(){var e,t,n,o;if(f.checkoutSdk){var c=Boolean(!C&&f.checkoutSdk),u=null==g||null===(e=g.elementsOptions)||void 0===e?void 0:e.appearance,i=null==r||null===(t=r.elementsOptions)||void 0===t?void 0:t.appearance,a=!E(i,u);i&&(a||c)&&f.checkoutSdk.changeAppearance(i);var s=null==g||null===(n=g.elementsOptions)||void 0===n?void 0:n.fonts,l=null==r||null===(o=r.elementsOptions)||void 0===o?void 0:o.fonts,p=!E(s,l);l&&(p||c)&&f.checkoutSdk.loadFonts(l)}}),[r,g,f.checkoutSdk,C]),t.useEffect((function(){w(f.stripe)}),[f.stripe]);var b=t.useMemo((function(){return function(e,t){if(!e)return null;e.on,e.session;var n=u(e,I);return t?Object.assign(t,n):Object.assign(e.session(),n)}(f.checkoutSdk,s)}),[f.checkoutSdk,s]);return f.checkoutSdk?t.createElement(T.Provider,{value:f},t.createElement(N.Provider,{value:b},o)):null};U.propTypes={stripe:h.any,options:h.shape({fetchClientSecret:h.func.isRequired,elementsOptions:h.object}).isRequired};var B=function(e){var n=t.useContext(T),r=t.useContext(O);if(n&&r)throw new Error("You cannot wrap the part of your app that ".concat(e," in both and providers."));return n?M(n,e):j(r,e)},Y=["mode"],_=function(e,n){var r,o="".concat((r=e).charAt(0).toUpperCase()+r.slice(1),"Element"),c=n?function(e){B("mounts <".concat(o,">"));var n=e.id,r=e.className;return t.createElement("div",{id:n,className:r})}:function(n){var r,c=n.id,a=n.className,s=n.options,l=void 0===s?{}:s,p=n.onBlur,f=n.onFocus,d=n.onReady,m=n.onChange,h=n.onEscape,g=n.onClick,C=n.onLoadError,E=n.onLoaderStart,k=n.onNetworksChange,S=n.onConfirm,P=n.onCancel,w=n.onShippingAddressChange,O=n.onShippingRateChange,j=n.onSavedPaymentMethodRemove,x=n.onSavedPaymentMethodUpdate,A=B("mounts <".concat(o,">")),R="elements"in A?A.elements:null,I="checkoutSdk"in A?A.checkoutSdk:null,T=i(t.useState(null),2),M=T[0],N=T[1],U=t.useRef(null),_=t.useRef(null);y(M,"blur",p),y(M,"focus",f),y(M,"escape",h),y(M,"click",g),y(M,"loaderror",C),y(M,"loaderstart",E),y(M,"networkschange",k),y(M,"confirm",S),y(M,"cancel",P),y(M,"shippingaddresschange",w),y(M,"shippingratechange",O),y(M,"savedpaymentmethodremove",j),y(M,"savedpaymentmethodupdate",x),y(M,"change",m),d&&(r="expressCheckout"===e?d:function(){d(M)}),y(M,"ready",r),t.useLayoutEffect((function(){if(null===U.current&&null!==_.current&&(R||I)){var t=null;if(I)switch(e){case"payment":t=I.createPaymentElement(l);break;case"address":if(!("mode"in l))throw new Error("You must supply options.mode. mode must be 'billing' or 'shipping'.");var n=l.mode,r=u(l,Y);if("shipping"===n)t=I.createShippingAddressElement(r);else{if("billing"!==n)throw new Error("Invalid options.mode. mode must be 'billing' or 'shipping'.");t=I.createBillingAddressElement(r)}break;case"expressCheckout":t=I.createExpressCheckoutElement(l);break;case"currencySelector":t=I.createCurrencySelectorElement();break;case"taxId":t=I.createTaxIdElement(l);break;default:throw new Error("Invalid Element type ".concat(o,". You must use either the , , , or ."))}else R&&(t=R.create(e,l));U.current=t,N(t),t&&t.mount(_.current)}}),[R,I,l]);var L=v(l);return t.useEffect((function(){if(U.current){var e=b(l,L,["paymentRequest"]);e&&"update"in U.current&&U.current.update(e)}}),[l,L]),t.useLayoutEffect((function(){return function(){if(U.current&&"function"==typeof U.current.destroy)try{U.current.destroy(),U.current=null}catch(e){}}}),[]),t.createElement("div",{id:c,className:a,ref:_})};return c.propTypes={id:h.string,className:h.string,onChange:h.func,onBlur:h.func,onFocus:h.func,onReady:h.func,onEscape:h.func,onClick:h.func,onLoadError:h.func,onLoaderStart:h.func,onNetworksChange:h.func,onConfirm:h.func,onCancel:h.func,onShippingAddressChange:h.func,onShippingRateChange:h.func,onSavedPaymentMethodRemove:h.func,onSavedPaymentMethodUpdate:h.func,options:h.object},c.displayName=o,c.__elementType=e,c},L="undefined"==typeof window,D=t.createContext(null);D.displayName="EmbeddedCheckoutProviderContext";var q=function(){var e=t.useContext(D);if(!e)throw new Error(" must be used within ");return e},W=L?function(e){var n=e.id,r=e.className;return q(),t.createElement("div",{id:n,className:r})}:function(e){var n=e.id,r=e.className,o=q().embeddedCheckout,c=t.useRef(!1),u=t.useRef(null);return t.useLayoutEffect((function(){return!c.current&&o&&null!==u.current&&(o.mount(u.current),c.current=!0),function(){if(c.current&&o)try{o.unmount(),c.current=!1}catch(e){}}}),[o]),t.createElement("div",{ref:u,id:n,className:r})},F=_("auBankAccount",L),H=_("card",L),V=_("cardNumber",L),$=_("cardExpiry",L),z=_("cardCvc",L),G=_("fpxBank",L),J=_("iban",L),K=_("idealBank",L),Q=_("p24Bank",L),X=_("epsBank",L),Z=_("payment",L),ee=_("expressCheckout",L),te=_("currencySelector",L),ne=_("paymentRequestButton",L),re=_("linkAuthentication",L),oe=_("address",L),ce=_("shippingAddress",L),ue=_("paymentMethodMessaging",L),ie=_("affirmMessage",L),ae=_("afterpayClearpayMessage",L),se=_("taxId",L);e.AddressElement=oe,e.AffirmMessageElement=ie,e.AfterpayClearpayMessageElement=ae,e.AuBankAccountElement=F,e.CardCvcElement=z,e.CardElement=H,e.CardExpiryElement=$,e.CardNumberElement=V,e.CheckoutProvider=U,e.CurrencySelectorElement=te,e.Elements=x,e.ElementsConsumer=R,e.EmbeddedCheckout=W,e.EmbeddedCheckoutProvider=function(e){var n=e.stripe,r=e.options,o=e.children,c=t.useMemo((function(){return P(n,"Invalid prop `stripe` supplied to `EmbeddedCheckoutProvider`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.")}),[n]),u=t.useRef(null),a=t.useRef(null),s=i(t.useState({embeddedCheckout:null}),2),l=s[0],p=s[1];t.useEffect((function(){if(!a.current&&!u.current){var e=function(e){a.current||u.current||(a.current=e,u.current=a.current.initEmbeddedCheckout(r).then((function(e){p({embeddedCheckout:e})})))};"async"!==c.tag||a.current||!r.clientSecret&&!r.fetchClientSecret?"sync"!==c.tag||a.current||!r.clientSecret&&!r.fetchClientSecret||e(c.stripe):c.stripePromise.then((function(t){t&&e(t)}))}}),[c,r,l,a]),t.useEffect((function(){return function(){l.embeddedCheckout?(u.current=null,l.embeddedCheckout.destroy()):u.current&&u.current.then((function(){u.current=null,l.embeddedCheckout&&l.embeddedCheckout.destroy()}))}}),[l.embeddedCheckout]),t.useEffect((function(){w(a)}),[a]);var f=v(n);t.useEffect((function(){null!==f&&f!==n&&console.warn("Unsupported prop change on EmbeddedCheckoutProvider: You cannot change the `stripe` prop after setting it.")}),[f,n]);var d=v(r);return t.useEffect((function(){null!=d&&(null!=r?(void 0===r.clientSecret&&void 0===r.fetchClientSecret&&console.warn("Invalid props passed to EmbeddedCheckoutProvider: You must provide one of either `options.fetchClientSecret` or `options.clientSecret`."),null!=d.clientSecret&&r.clientSecret!==d.clientSecret&&console.warn("Unsupported prop change on EmbeddedCheckoutProvider: You cannot change the client secret after setting it. Unmount and create a new instance of EmbeddedCheckoutProvider instead."),null!=d.fetchClientSecret&&r.fetchClientSecret!==d.fetchClientSecret&&console.warn("Unsupported prop change on EmbeddedCheckoutProvider: You cannot change fetchClientSecret after setting it. Unmount and create a new instance of EmbeddedCheckoutProvider instead."),null!=d.onComplete&&r.onComplete!==d.onComplete&&console.warn("Unsupported prop change on EmbeddedCheckoutProvider: You cannot change the onComplete option after setting it."),null!=d.onShippingDetailsChange&&r.onShippingDetailsChange!==d.onShippingDetailsChange&&console.warn("Unsupported prop change on EmbeddedCheckoutProvider: You cannot change the onShippingDetailsChange option after setting it."),null!=d.onLineItemsChange&&r.onLineItemsChange!==d.onLineItemsChange&&console.warn("Unsupported prop change on EmbeddedCheckoutProvider: You cannot change the onLineItemsChange option after setting it.")):console.warn("Unsupported prop change on EmbeddedCheckoutProvider: You cannot unset options after setting them."))}),[d,r]),t.createElement(D.Provider,{value:l},o)},e.EpsBankElement=X,e.ExpressCheckoutElement=ee,e.FpxBankElement=G,e.IbanElement=J,e.IdealBankElement=K,e.LinkAuthenticationElement=re,e.P24BankElement=Q,e.PaymentElement=Z,e.PaymentMethodMessagingElement=ue,e.PaymentRequestButtonElement=ne,e.ShippingAddressElement=ce,e.TaxIdElement=se,e.useCheckout=function(){!function(e){var n=t.useContext(T);M(n,e)}("calls useCheckout()");var e=t.useContext(N);if(!e)throw new Error("Could not find Checkout Context; You need to wrap the part of your app that calls useCheckout() in an provider.");return e},e.useElements=function(){return A("calls useElements()").elements},e.useStripe=function(){return B("calls useStripe()").stripe}}));