stripe-pwa-elements 4.0.5 → 4.1.0

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.
Files changed (55) hide show
  1. package/dist/cjs/{factory-xOoxnMhx.js → factory-yd5HDEZn.js} +1 -0
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/stripe-address-element.cjs.entry.js +1 -1
  4. package/dist/cjs/stripe-card-element.cjs.entry.js +1 -1
  5. package/dist/cjs/stripe-currency-selector.cjs.entry.js +1 -1
  6. package/dist/cjs/stripe-elements.cjs.js +1 -1
  7. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +1 -1
  8. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +1 -1
  9. package/dist/cjs/stripe-payment-element.cjs.entry.js +18 -7
  10. package/dist/cjs/stripe-payment-element.helpers-D1JnhTa-.js +182 -0
  11. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +72 -57
  12. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +9 -32
  13. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +87 -5
  14. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +60 -48
  15. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +5 -2
  16. package/dist/collection/services/stripe-service.js +1 -0
  17. package/dist/collection/utils/checkout-confirm.js +84 -0
  18. package/dist/components/factory.js +1 -1
  19. package/dist/components/stripe-payment-element.helpers.js +1 -1
  20. package/dist/components/stripe-payment-element.js +1 -1
  21. package/dist/components/stripe-payment-sheet.js +1 -1
  22. package/dist/esm/{factory-CsurRVcp.js → factory-B_WxdnxM.js} +1 -0
  23. package/dist/esm/loader.js +1 -1
  24. package/dist/esm/stripe-address-element.entry.js +1 -1
  25. package/dist/esm/stripe-card-element.entry.js +1 -1
  26. package/dist/esm/stripe-currency-selector.entry.js +1 -1
  27. package/dist/esm/stripe-elements.js +1 -1
  28. package/dist/esm/stripe-express-checkout-element.entry.js +1 -1
  29. package/dist/esm/stripe-link-authentication-element.entry.js +1 -1
  30. package/dist/esm/stripe-payment-element.entry.js +18 -7
  31. package/dist/esm/stripe-payment-element.helpers-PuWxhMNR.js +176 -0
  32. package/dist/esm/stripe-payment-sheet.entry.js +72 -57
  33. package/dist/stripe-elements/{p-949a8bba.entry.js → p-2e2bf0fe.entry.js} +1 -1
  34. package/dist/stripe-elements/{p-b0f9ebba.entry.js → p-32a2d5a4.entry.js} +1 -1
  35. package/dist/stripe-elements/{p-edbbe060.entry.js → p-84d45b48.entry.js} +1 -1
  36. package/dist/stripe-elements/{p-a2d11152.entry.js → p-a266da6f.entry.js} +1 -1
  37. package/dist/stripe-elements/p-c4a0e310.entry.js +1 -0
  38. package/dist/stripe-elements/{p-50e495e3.entry.js → p-e660d76a.entry.js} +1 -1
  39. package/dist/stripe-elements/p-eeebfbbf.entry.js +1 -0
  40. package/dist/stripe-elements/p-n0XJSLU3.js +1 -0
  41. package/dist/stripe-elements/p-wrjrFokg.js +1 -0
  42. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  43. package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +33 -0
  44. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +8 -2
  45. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +19 -11
  46. package/dist/types/components.d.ts +34 -2
  47. package/dist/types/services/interfaces.d.ts +3 -1
  48. package/dist/types/utils/checkout-confirm.d.ts +35 -0
  49. package/package.json +1 -1
  50. package/dist/cjs/stripe-payment-element.helpers-lafmSRmb.js +0 -121
  51. package/dist/esm/stripe-payment-element.helpers-CklK5RlF.js +0 -116
  52. package/dist/stripe-elements/p-855d1aee.entry.js +0 -1
  53. package/dist/stripe-elements/p-B2G-wquO.js +0 -1
  54. package/dist/stripe-elements/p-BoZLkOAy.js +0 -1
  55. package/dist/stripe-elements/p-a45268d4.entry.js +0 -1
@@ -1,116 +0,0 @@
1
- import { S as StripeAPIError } from './error-XRfh5Wrs.js';
2
-
3
- /**
4
- * Determine whether the submit button should be disabled.
5
- * For Checkout Session mode: the checkout is ready once Stripe finished loading.
6
- * For Payment Intent / Setup Intent mode: an intent client secret must be present.
7
- * The button stays disabled after a successful payment as well: the intent or
8
- * checkout is already confirmed and cannot be submitted again.
9
- * @param params progress / loading state and the current mode information
10
- * @returns true when the submit button should be disabled
11
- */
12
- const isSubmitButtonDisabled = (params) => {
13
- const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
14
- const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
15
- return progress === 'loading' || progress === 'success' || !hasValidSecret;
16
- };
17
- /**
18
- * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
19
- * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
20
- * @param stripe the loaded Stripe.js instance
21
- * @param elements the Stripe Elements instance bound to the payment element
22
- * @param intentType the configured intent type
23
- * @param returnUrl the URL Stripe should redirect back to when required
24
- * @param extraConfirmParams optional params merged into `confirmParams` (for example `payment_method_data.billing_details`)
25
- * @returns the confirmation result
26
- * @throws StripeAPIError when Stripe returns an error
27
- */
28
- const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl, extraConfirmParams) => {
29
- const result = await (() => {
30
- if (intentType === 'payment') {
31
- return stripe.confirmPayment({
32
- elements,
33
- confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
34
- redirect: 'if_required',
35
- });
36
- }
37
- return stripe.confirmSetup({
38
- elements,
39
- confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
40
- redirect: 'if_required',
41
- });
42
- })();
43
- if (result.error) {
44
- throw new StripeAPIError(result.error);
45
- }
46
- return result;
47
- };
48
- /**
49
- * Confirm a Checkout Session payment using the checkout actions.
50
- * @param checkout the Stripe Checkout instance
51
- * @param returnUrl the URL Stripe should redirect back to when required
52
- * @returns the confirmation result
53
- * @throws StripeAPIError when loading actions or confirming fails
54
- */
55
- const confirmCheckoutSession = async (checkout, returnUrl) => {
56
- var _a;
57
- // Load actions from the checkout session
58
- const loadActionsResult = await checkout.loadActions();
59
- if (loadActionsResult.type === 'error') {
60
- // Create a StripeError-compatible object from the Checkout Session error
61
- const stripeError = {
62
- type: 'api_error',
63
- code: loadActionsResult.error.code || 'checkout_session_error',
64
- message: loadActionsResult.error.message,
65
- };
66
- throw new StripeAPIError(stripeError);
67
- }
68
- const { actions } = loadActionsResult;
69
- // Confirm the payment using checkout session actions
70
- const result = await actions.confirm({
71
- returnUrl,
72
- redirect: 'if_required',
73
- });
74
- if (result.type === 'error') {
75
- // Create a StripeError-compatible object from the confirm error
76
- const stripeError = {
77
- type: 'card_error',
78
- code: result.error.code || 'payment_failed',
79
- message: result.error.message,
80
- decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
81
- };
82
- throw new StripeAPIError(stripeError);
83
- }
84
- return result;
85
- };
86
- /**
87
- * Resolve the mode-specific properties for a submit event.
88
- * Picks the Checkout or Elements payload depending on the active mode and
89
- * reports a descriptive error string when the required instance is missing.
90
- * @param params the resolved Stripe instances and client secrets for the current mode
91
- * @returns the submit event props, or an error message when an instance is missing
92
- */
93
- const buildSubmitEventProps = (params) => {
94
- const { stripe, isCheckoutSession, checkout, checkoutSessionClientSecret, elements, intentClientSecret } = params;
95
- const props = {
96
- stripe,
97
- };
98
- if (isCheckoutSession) {
99
- // Checkout Session mode
100
- if (checkout == null) {
101
- return { error: 'Checkout not properly initialized' };
102
- }
103
- props.checkout = checkout;
104
- props.checkoutSessionClientSecret = checkoutSessionClientSecret;
105
- return { props };
106
- }
107
- // Payment Intent / Setup Intent mode
108
- if (elements == null) {
109
- return { error: 'Elements not properly initialized' };
110
- }
111
- props.elements = elements;
112
- props.intentClientSecret = intentClientSecret;
113
- return { props };
114
- };
115
-
116
- export { confirmCheckoutSession as a, buildSubmitEventProps as b, confirmPaymentOrSetup as c, isSubmitButtonDisabled as i };
@@ -1 +0,0 @@
1
- import{r as t,a as i,h as e,g as s}from"./p-C6bbmyga.js";import{c as n,i as r}from"./p-HWdALSvT.js";import{s as o}from"./p-B2G-wquO.js";import{b as a,c as h,a as c,i as l}from"./p-BoZLkOAy.js";import"./p-CBXaOfXU.js";import"./p-XRfh5Wrs.js";const p=class{async initStripe(t,i){const e=++this.initGeneration;await this.stripeService.initialize(t,{stripeAccount:null==i?void 0:i.stripeAccount,applicationName:this.applicationName,clientSecret:this.intentClientSecret}),await this.mountWhenLoaded(e)}async initStripeWithCheckoutSession(t,i,e){const s=++this.initGeneration;await this.stripeService.initializeWithCheckoutSession(t,i,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName,elementsOptions:null==e?void 0:e.elementsOptions}),await this.mountWhenLoaded(s)}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.paymentElementManager.setError(t),this}updatePublishableKey(t){const i={};i.stripeAccount=this.stripeService.state.stripeAccount;const e=Object.values(i).filter((t=>null!=t&&""!==t)).length>0;this.hasCheckoutSessionClientSecret()?this.initStripeWithCheckoutSession(t,this.checkoutSessionClientSecret,{stripeAccount:i.stripeAccount}):this.initStripe(t,e?i:void 0)}updateStripeAccountId(t){this.hasCheckoutSessionClientSecret()?this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey,this.checkoutSessionClientSecret,{stripeAccount:t}):this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:t})}async updateIntentClientSecret(){if(null!=this.checkoutSessionClientSecret&&""!==this.checkoutSessionClientSecret)return;const{publishableKey:t,stripeAccount:i}=this.stripeService.state;null!=t&&""!==t&&(await this.initStripe(t,{stripeAccount:i}),"success"===this.progress&&(this.progress=""))}async updateCheckoutSessionClientSecret(t){null!=this.publishableKey&&""!==this.publishableKey&&null!=t&&""!==t&&(await this.initStripeWithCheckoutSession(this.publishableKey,t,{stripeAccount:this.stripeAccount}),"success"===this.progress&&(this.progress=""))}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async formSubmitEventHandler(){const t=this.stripeService.getStripe(),i=!0===this.stripeService.state.isCheckoutSession;if(null==t)return void console.error("Stripe not properly initialized");const e=a({stripe:t,isCheckoutSession:i,checkout:this.stripeService.getCheckout(),checkoutSessionClientSecret:this.checkoutSessionClientSecret,elements:this.stripeService.getElements(),intentClientSecret:this.intentClientSecret});"error"in e?console.error(e.error):this.formSubmit.emit(e.props)}async defaultFormSubmitResultHandler(t){this.defaultFormSubmitResult.emit(t)}async checkoutSessionConfirmResultHandler(t){this.checkoutSessionConfirmResult.emit(t)}componentWillRender(){const{publishableKey:t}=this.stripeService.state;null!=t&&""!==t&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||(null==this.checkoutSessionClientSecret||""===this.checkoutSessionClientSecret?this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}):this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey,this.checkoutSessionClientSecret,{stripeAccount:this.stripeService.state.stripeAccount})))}async defaultFormSubmitAction(t,{stripe:i,elements:e}){t.preventDefault();try{const t=window.location.href,s=await h(i,e,this.intentType,t);this.defaultFormSubmitResultHandler(s)}catch(t){throw console.error(t),this.defaultFormSubmitResultHandler(t),t}}async checkoutSessionFormSubmitAction(t,i){t.preventDefault();try{const t=window.location.href,e=await c(i,t);this.checkoutSessionConfirmResultHandler(e)}catch(t){throw console.error(t),this.checkoutSessionConfirmResultHandler(t instanceof Error?t:new Error(String(t))),t}}constructor(e){t(this,e),this.stripeLoaded=i(this,"stripeLoaded",7),this.formSubmit=i(this,"formSubmit",7),this.defaultFormSubmitResult=i(this,"defaultFormSubmitResult",7),this.checkoutSessionConfirmResult=i(this,"checkoutSessionConfirmResult",7),this.initGeneration=0,this.intentType="payment",this.sheetTitle="Add your payment information",this.buttonLabel="Pay",this.progress="",this.applicationName="stripe-pwa-elements",this.shouldUseDefaultFormSubmitAction=!0,this.stripeService=o.createStripeService(),this.paymentElementManager=o.createPaymentElementManager(this.stripeService)}componentWillLoad(){this.startStripe()}async mountWhenLoaded(t){if(t!==this.initGeneration)return;if("success"===this.stripeService.state.loadStripeStatus){if(await this.initElement(),t!==this.initGeneration)return;return void this.stripeLoadedEventHandler()}const i=this.stripeService.onChange("loadStripeStatus",(async e=>{t===this.initGeneration?"success"===e&&(await this.initElement(),t===this.initGeneration?(this.stripeLoadedEventHandler(),i()):i()):i()}))}hasCheckoutSessionClientSecret(){return null!=this.checkoutSessionClientSecret&&""!==this.checkoutSessionClientSecret}startStripe(){null!=this.publishableKey&&""!==this.publishableKey&&(null==this.checkoutSessionClientSecret||""===this.checkoutSessionClientSecret?this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount}):this.initStripeWithCheckoutSession(this.publishableKey,this.checkoutSessionClientSecret,{stripeAccount:this.stripeAccount}))}async initElement(){await this.paymentElementManager.initialize(this.el);const t=this.el.querySelector("#stripe-payment-element");null!=t?(null!=this._submitHandler&&t.removeEventListener("submit",this._submitHandler),this._submitHandler=async t=>{const i=this.stripeService.getStripe(),e=!0===this.stripeService.state.isCheckoutSession;if(null==i)return void console.error("Stripe not properly initialized");const s=a({stripe:i,isCheckoutSession:e,checkout:this.stripeService.getCheckout(),checkoutSessionClientSecret:this.checkoutSessionClientSecret,elements:this.stripeService.getElements(),intentClientSecret:this.intentClientSecret});if("error"in s)return void console.error(s.error);const n=s.props;this.progress="loading";try{null!=this.handleSubmit?await this.handleSubmit(t,n):!0===this.shouldUseDefaultFormSubmitAction?e&&null!=n.checkout?await this.checkoutSessionFormSubmitAction(t,n.checkout):null!=this.intentClientSecret&&""!==this.intentClientSecret?await this.defaultFormSubmitAction(t,n):t.preventDefault():t.preventDefault(),await this.formSubmitEventHandler(),null==this.handleSubmit&&!0!==this.shouldUseDefaultFormSubmitAction||(this.progress="success")}catch(t){const i=t instanceof Error?t.message:String(t);this.paymentElementManager.setError(i),this.progress="failure"}},t.addEventListener("submit",this._submitHandler)):console.error("Form element #stripe-payment-element not found")}componentDidLoad(){this.el.classList.add(n())}disconnectedCallback(){if(this.paymentElementManager.unmount(),null!=this._submitHandler){const t=this.el.querySelector("#stripe-payment-element");null!=t&&t.removeEventListener("submit",this._submitHandler)}}render(){const{loadStripeStatus:t,isCheckoutSession:i}=this.stripeService.state,{errorMessage:s}=this.paymentElementManager.getState();if("failure"===t)return e("p",null,r.t("Failed to load Stripe"));const n=l({progress:this.progress,isCheckoutSession:!0===i,loadStripeStatus:t,intentClientSecret:this.intentClientSecret});return e("div",{class:"stripe-payment-sheet-wrap"},e("form",{id:"stripe-payment-element"},e("div",{class:"stripe-heading"},r.t(this.sheetTitle)),e("div",null,e("div",{class:"stripe-section-title"},r.t("Payment information"))),e("div",{class:"payment-info visible"},e("div",{id:"payment-element"})),e("div",{id:"payment-errors",class:"stripe-element-errors"},s),e("div",{style:{marginTop:"32px"}},e("button",{type:"submit",disabled:n},r.t("loading"===this.progress?"Loading":this.buttonLabel)))))}get el(){return s(this)}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}],intentClientSecret:[{updateIntentClientSecret:0}],checkoutSessionClientSecret:[{updateCheckoutSessionClientSecret:0}]}}};p.style=':root{--color-label:#565656;--color-placeholder:#acacac;--color-heading-text:#333;--color-text-error:#ef4444;--color-input-border:#e4e4e6;--color-input-border-shadow:rgba(228, 228, 230, 0.6);--color-button-text:rgba(255, 255, 255, 0.95);--color-button-text-disabled:rgba(255, 255, 255, 0.4);--color-primary:#0074d4}.stripe-payment-sheet-wrap{box-sizing:border-box}.stripe-payment-sheet-wrap *:where(:not(iframe,canvas,img,svg,video):not(svg *)){all:unset;display:revert;background:none;border:none;font-family:"Roboto", sans-serif;box-sizing:border-box}.stripe-payment-sheet-wrap button{cursor:pointer}.stripe-payment-sheet-wrap{display:block;width:100%;background:#fff;padding:32px 16px}.stripe-payment-sheet-wrap .StripeElement{padding:8px 16px;min-height:64px;border-radius:6px;display:flex;justify-content:center;align-items:center}.stripe-payment-sheet-wrap .StripeElement>.__PrivateStripeElement{width:100%}.stripe-payment-sheet-wrap .stripe-heading{font-size:24px;font-weight:bold;color:var(--color-heading-text);margin-bottom:24px}.stripe-payment-sheet-wrap .stripe-section-title{font-size:14px;font-weight:bold;color:var(--color-label);margin-bottom:8px}.stripe-payment-sheet-wrap .payment-info{margin-top:8px}.stripe-payment-sheet-wrap .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}.stripe-payment-sheet-wrap button{display:block;color:var(--color-button-text);background-color:var(--color-primary);width:100%;text-align:center;padding:16px 16px;font-size:18px;border-radius:6px;min-height:42px}.stripe-payment-sheet-wrap button:disabled{color:var(--color-button-text-disabled)}';export{p as stripe_payment_element}
@@ -1 +0,0 @@
1
- import{S as t}from"./p-C6bbmyga.js";import{l as e}from"./p-CBXaOfXU.js";import{i}from"./p-HWdALSvT.js";const r=(()=>{let t;return(...e)=>{t&&clearTimeout(t),t=setTimeout((()=>{t=0,(t=>{for(let e of t.keys()){const i=t.get(e).filter((t=>{const e=t.deref();return e&&(!("isConnected"in(i=e))||i.isConnected);var i}));t.set(e,i)}})(...e)}),2e3)}})(),s=t.forceUpdate,n=t.getRenderingRef,o=(t,e)=>{const i=t.indexOf(e);i>=0&&(t[i]=t[t.length-1],t.length--)},l=(t,e)=>{const i=((t,e=(t,e)=>t!==e)=>{const i=()=>{return("function"==typeof(e=t)?e():e)??{};var e},r=i();let s=new Map(Object.entries(r));const n="undefined"!=typeof Proxy,l=n?null:{},a={dispose:[],get:[],set:[],reset:[]},c=new Map,h=()=>{s=new Map(Object.entries(i())),n||m(),a.reset.forEach((t=>t()))},u=t=>(a.get.forEach((e=>e(t))),s.get(t)),d=(t,i)=>{const r=s.get(t);e(i,r,t)&&(s.set(t,i),n||g(t),a.set.forEach((e=>e(t,i,r))))},v=n?new Proxy(r,{get:(t,e)=>u(e),ownKeys:()=>Array.from(s.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(t,e)=>s.has(e),set:(t,e,i)=>(d(e,i),!0)}):(m(),l),p=(t,e)=>(a[t].push(e),()=>{o(a[t],e)});function g(t){!n&&l&&(Object.prototype.hasOwnProperty.call(l,t)||Object.defineProperty(l,t,{configurable:!0,enumerable:!0,get:()=>u(t),set(e){d(t,e)}}))}function m(){if(n||!l)return;const t=new Set(s.keys());for(const e of Object.keys(l))t.has(e)||delete l[e];for(const e of t)g(e)}return{state:v,get:u,set:d,on:p,onChange:(t,e)=>{const r=(i,r)=>{i===t&&e(r)},s=()=>{const r=i();e(r[t])},n=p("set",r),o=p("reset",s);return c.set(e,{setHandler:r,resetHandler:s,propName:t}),()=>{n(),o(),c.delete(e)}},use:(...t)=>{const e=t.reduce(((t,e)=>(e.set&&t.push(p("set",e.set)),e.get&&t.push(p("get",e.get)),e.reset&&t.push(p("reset",e.reset)),e.dispose&&t.push(p("dispose",e.dispose)),t)),[]);return()=>e.forEach((t=>t()))},dispose:()=>{a.dispose.forEach((t=>t())),h()},reset:h,forceUpdate:t=>{const e=s.get(t);a.set.forEach((i=>i(t,e,e)))},removeListener:(t,e)=>{const i=c.get(e);i&&i.propName===t&&(o(a.set,i.setHandler),o(a.reset,i.resetHandler),c.delete(e))}}})(t,e);return i.use((()=>{if("function"!=typeof n||"function"!=typeof s)return{};const t=s,e=n,i=new Map;return{dispose:()=>i.clear(),get:t=>{const r=e();r&&((t,e,i)=>{let r=t.get(e);r||(r=[],t.set(e,r)),r.some((t=>t.deref()===i))||r.push(new WeakRef(i))})(i,t,r)},set:e=>{const s=i.get(e);if(s){const r=s.filter((e=>{const i=e.deref();return!!i&&t(i)}));i.set(e,r)}r(i)},reset:()=>{i.forEach((e=>{e.forEach((e=>{const i=e.deref();i&&t(i)}))})),r(i)}}})()),i};class a{constructor(){this.store=l({loadStripeStatus:"",applicationName:"stripe-pwa-elements",isCheckoutSession:!1}),this.initGeneration=0,this.changeListeners=new Map}get state(){return this.store.state}onChange(t,e){const i=this.store.onChange(t,e);return this.changeListeners.has(t)||this.changeListeners.set(t,[]),this.changeListeners.get(t).push(i),i}async initialize(t,i){const r=null!=(null==i?void 0:i.elementsOptions)?JSON.stringify(i.elementsOptions):void 0,s=null!=this.store.state.stripe&&!this.store.state.isCheckoutSession&&this.store.state.publishableKey===t&&this.store.state.stripeAccount===(null==i?void 0:i.stripeAccount)&&this.intentClientSecret===(null==i?void 0:i.clientSecret)&&this.elementsOptionsKey===r;if(this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!1,this.intentClientSecret=null==i?void 0:i.clientSecret,this.elementsOptionsKey=r,null!=(null==i?void 0:i.stripeAccount)&&""!==(null==i?void 0:i.stripeAccount)&&(this.store.state.stripeAccount=i.stripeAccount),null!=(null==i?void 0:i.applicationName)&&""!==(null==i?void 0:i.applicationName)&&(this.store.state.applicationName=i.applicationName),s)return;const n=++this.initGeneration;this.store.state.loadStripeStatus="loading";try{const r=await e(t,{stripeAccount:null==i?void 0:i.stripeAccount});if(n!==this.initGeneration)return;r.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=r,this.store.state.elements=null!=(null==i?void 0:i.clientSecret)&&""!==i.clientSecret?r.elements({clientSecret:i.clientSecret}):null!=(null==i?void 0:i.elementsOptions)?r.elements(i.elementsOptions):r.elements(),this.store.state.checkout=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to load Stripe.js:",t),this.store.state.loadStripeStatus="failure"}}async initializeWithCheckoutSession(t,i,r){const s=++this.initGeneration;this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!0,null!=(null==r?void 0:r.stripeAccount)&&""!==(null==r?void 0:r.stripeAccount)&&(this.store.state.stripeAccount=r.stripeAccount),null!=(null==r?void 0:r.applicationName)&&""!==(null==r?void 0:r.applicationName)&&(this.store.state.applicationName=r.applicationName),this.store.state.loadStripeStatus="loading";try{const n=await e(t,{stripeAccount:null==r?void 0:r.stripeAccount});if(s!==this.initGeneration)return;n.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=n;const o=n.initCheckoutElementsSdk({clientSecret:i,elementsOptions:null==r?void 0:r.elementsOptions});this.store.state.checkout=o,this.store.state.elements=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to initialize Stripe Checkout:",t),this.store.state.loadStripeStatus="failure"}}getStripe(){return this.store.state.stripe}getElements(){return this.store.state.elements}getCheckout(){return this.store.state.checkout}reset(){this.store.reset()}dispose(){this.changeListeners.forEach((t=>{t.forEach((t=>t()))})),this.changeListeners.clear(),this.store.dispose()}}function c(t,e,i=5e3){return new Promise(((r,s)=>{const n=t.querySelector(e);if(null!=n)return r(n);const o=setTimeout((()=>{l.disconnect(),s(new Error(`Element "${e}" not found within ${i}ms`))}),i),l=new MutationObserver((()=>{const i=t.querySelector(e);null!=i&&(clearTimeout(o),l.disconnect(),r(i))}));l.observe(t,{childList:!0,subtree:!0})}))}new a;class h{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",errorSource:void 0})}getState(){return this.store.state}async initialize(t){const e=this.stripeService.getElements();if(null==e)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.cardElements&&this.unmount();const r=e.create("cardNumber",{placeholder:i.t("Card Number")}),s=await c(t,"#card-number");r.mount(s),r.on("change",this.handleCardError("cardNumber"));const n=e.create("cardExpiry"),o=await c(t,"#card-expiry");n.mount(o),n.on("change",this.handleCardError("cardExpiry"));const l=e.create("cardCvc"),a=await c(t,"#card-cvc");return l.mount(a),l.on("change",this.handleCardError("cardCvc")),this.cardElements={cardNumber:r,cardExpiry:n,cardCVC:l},this.cardElements}getElements(){return this.cardElements}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage",""),this.store.set("errorSource",void 0)}unmount(){var t,e,i;null!=this.cardElements&&(null===(t=this.cardElements.cardNumber)||void 0===t||t.unmount(),null===(e=this.cardElements.cardExpiry)||void 0===e||e.unmount(),null===(i=this.cardElements.cardCVC)||void 0===i||i.unmount(),this.cardElements=void 0)}handleCardError(t){return({error:e})=>{if(e)return this.store.set("errorMessage",e.message),void this.store.set("errorSource",t);this.store.state.errorSource===t&&(this.store.set("errorMessage",""),this.store.set("errorSource",void 0))}}}class u{constructor(t){this.stripeService=t,this.store=l({errorMessage:""})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.state.isCheckoutSession;if(null!=this.paymentElement&&this.unmount(),i){const t=this.stripeService.getCheckout();if(null==t)throw new Error("StripeService not initialized with Checkout Session. Call StripeService.initializeWithCheckoutSession() first.");this.paymentElement=t.createPaymentElement(e)}else{const t=this.stripeService.getElements();if(null==t)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");this.paymentElement=t.create("payment",e||{})}const r=await c(t,"#payment-element");return this.paymentElement.mount(r),this.paymentElement}getElement(){return this.paymentElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.paymentElement&&(this.paymentElement.unmount(),this.paymentElement=void 0)}}class d{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isComplete:!1})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.addressElement&&this.unmount(),this.addressElement=i.create("address",e||{mode:"billing"});const r=await c(t,"#address-element");return this.addressElement.mount(r),this.addressElement.on("change",(t=>{this.store.set("errorMessage",""),this.store.set("isComplete",t.complete)})),this.addressElement}getElement(){return this.addressElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.addressElement&&(this.addressElement.unmount(),this.addressElement=void 0)}}class v{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",email:void 0,complete:void 0})}getState(){return this.store.state}onChange(t,e){return this.store.onChange(t,e)}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.linkAuthenticationElement&&this.unmount(),this.store.set("email",void 0),this.store.set("complete",void 0);const r=i.create("linkAuthentication",e),s=await c(t,"#link-authentication-element");return r.mount(s),r.on("change",(t=>{var e;this.store.set("email",null===(e=t.value)||void 0===e?void 0:e.email),this.store.set("complete",t.complete)})),this.linkAuthenticationElement=r,this.linkAuthenticationElement}getElement(){return this.linkAuthenticationElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.linkAuthenticationElement&&(this.linkAuthenticationElement.unmount(),this.linkAuthenticationElement=void 0)}}class p{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",selectedCurrency:void 0})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.currencySelectorElement&&this.unmount();const r=await c(t,"#currency-selector");return this.currencySelectorElement=i.create("currencySelector",e||{}),this.currencySelectorElement.mount(r),this.currencySelectorElement.on("change",(t=>{var e;this.store.set("errorMessage",""),(null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.currency)&&this.store.set("selectedCurrency",t.value.currency)})),this.currencySelectorElement}getElement(){return this.currencySelectorElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.currencySelectorElement&&(this.currencySelectorElement.unmount(),this.currencySelectorElement=void 0)}}var g=function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(i[r[s]]=t[r[s]])}return i};class m{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isReady:!1})}getState(){return this.store.state}async initialize(t,e,i){const r=this.stripeService.getElements();if(null==r)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.expressCheckoutElement&&this.unmount();const s=g(e,["mode","amount","currency"]),n=Object.assign({},s);if(n.buttonHeight&&"string"==typeof n.buttonHeight){const t=parseInt(n.buttonHeight.replace("px",""),10);isNaN(t)||(n.buttonHeight=t)}const o=r.create("expressCheckout",n),l=await c(t,"#express-checkout-element");return null!=(null==i?void 0:i.onConfirm)&&o.on("confirm",i.onConfirm),null!=(null==i?void 0:i.onClick)&&o.on("click",i.onClick),null!=(null==i?void 0:i.onCancel)&&o.on("cancel",i.onCancel),null!=(null==i?void 0:i.onShippingAddressChange)&&o.on("shippingaddresschange",i.onShippingAddressChange),null!=(null==i?void 0:i.onShippingRateChange)&&o.on("shippingratechange",i.onShippingRateChange),o.on("ready",(()=>{this.store.set("isReady",!0)})),o.mount(l),this.expressCheckoutElement=o,this.expressCheckoutElement}getElement(){return this.expressCheckoutElement}update(t){var e;if(null==this.expressCheckoutElement)return void console.warn("Express Checkout Element not initialized. Cannot update options.");const{mode:i,amount:r,currency:s}=t,n=g(t,["mode","amount","currency"]),o={};void 0!==i&&(o.mode=i),void 0!==r&&(o.amount=r),void 0!==s&&(o.currency=s),Object.keys(o).length>0&&(null===(e=this.stripeService.getElements())||void 0===e||e.update(o));const l=Object.assign({},n);if(l.buttonHeight&&"string"==typeof l.buttonHeight){const t=parseInt(l.buttonHeight.replace("px",""),10);isNaN(t)||(l.buttonHeight=t)}0!==Object.keys(l).length&&this.expressCheckoutElement.update(l)}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.expressCheckoutElement&&(this.expressCheckoutElement.unmount(),this.expressCheckoutElement=void 0,this.store.set("isReady",!1))}}const f=new class{createStripeService(){return new a}createCardElementManager(t){return new h(t)}createPaymentElementManager(t){return new u(t)}createAddressElementManager(t){return new d(t)}createLinkAuthenticationElementManager(t){return new v(t)}createCurrencySelectorElementManager(t){return new p(t)}createExpressCheckoutElementManager(t){return new m(t)}};export{c as f,f as s}
@@ -1 +0,0 @@
1
- import{S as e}from"./p-XRfh5Wrs.js";const r=e=>{const{progress:r,isCheckoutSession:t,loadStripeStatus:s,intentClientSecret:i}=e;return"loading"===r||"success"===r||!(t?"success"===s:null!=i&&""!==i)},t=async(r,t,s,i,n)=>{const o=await("payment"===s?r.confirmPayment({elements:t,confirmParams:Object.assign({return_url:i},n),redirect:"if_required"}):r.confirmSetup({elements:t,confirmParams:Object.assign({return_url:i},n),redirect:"if_required"}));if(o.error)throw new e(o.error);return o},s=async(r,t)=>{var s;const i=await r.loadActions();if("error"===i.type)throw new e({type:"api_error",code:i.error.code||"checkout_session_error",message:i.error.message});const{actions:n}=i,o=await n.confirm({returnUrl:t,redirect:"if_required"});if("error"===o.type){const r={type:"card_error",code:o.error.code||"payment_failed",message:o.error.message,decline_code:"paymentFailed"===o.error.code?null===(s=o.error.paymentFailed)||void 0===s?void 0:s.declineCode:void 0};throw new e(r)}return o},i=e=>{const{stripe:r,isCheckoutSession:t,checkout:s,checkoutSessionClientSecret:i,elements:n,intentClientSecret:o}=e,c={stripe:r};return t?null==s?{error:"Checkout not properly initialized"}:(c.checkout=s,c.checkoutSessionClientSecret=i,{props:c}):null==n?{error:"Elements not properly initialized"}:(c.elements=n,c.intentClientSecret=o,{props:c})};export{s as a,i as b,t as c,r as i}
@@ -1 +0,0 @@
1
- import{r as e,a as t,h as i,d as s,g as n}from"./p-C6bbmyga.js";import{c as a,i as r}from"./p-HWdALSvT.js";import{s as o,f as l}from"./p-B2G-wquO.js";import{c}from"./p-BoZLkOAy.js";import{S as d}from"./p-XRfh5Wrs.js";import"./p-CBXaOfXU.js";const h={phase:"idle",generation:0,pendingPresent:!1,openRequested:!1},p=[[/^pi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/,"payment"],[/^seti_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/,"setup"]],u=e=>({state:e,effects:[]}),m=(e,t)=>e.pendingPresent?{state:Object.assign(Object.assign({},e),{pendingPresent:!1}),effects:[{type:"resolvePresent",result:t}]}:u(e),f=e=>{const t=m(Object.assign(Object.assign({},e),{openRequested:!1}),"paymentSheetCanceled");return{state:t.state,effects:[..."presented"===e.phase||"confirming"===e.phase?[{type:"hide"}]:[],{type:"emit",event:"paymentSheetCanceled"},...t.effects]}},y=(e,t,i)=>{if(""===t)return u(e);if("confirming"===e.phase)return u(Object.assign(Object.assign({},e),{deferredSecret:{clientSecret:t,source:i}}));const s="presented"===e.phase?f(e):u(e),n=e.generation+1,a=((e,t)=>"checkoutSession"===t?"checkoutSession":(e=>{const t=p.find((([t])=>t.test(e)));return null==t?void 0:t[1]})(e))(t,i);if(null==a){const e=m(Object.assign(Object.assign({},s.state),{phase:"loadFailed",generation:n,intentKind:void 0,openRequested:!1}),"paymentSheetFailed");return{state:e.state,effects:[...s.effects,{type:"emit",event:"paymentSheetFailedToLoad"},...e.effects]}}return{state:Object.assign(Object.assign({},s.state),{phase:"loading",generation:n,intentKind:a}),effects:[...s.effects,{type:"load",generation:n,clientSecret:t,intentKind:a}]}},b=e=>{const{deferredSecret:t}=e.state;if(null==t)return e;const i=y(Object.assign(Object.assign({},e.state),{deferredSecret:void 0}),t.clientSecret,t.source);return{state:i.state,effects:[...e.effects,...i.effects]}},v=(e,t)=>"confirming"===e.phase&&e.generation===t;var g=function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,s[n])&&(i[s[n]]=e[s[n]])}return i};const w=["merchantDisplayName","paymentMethodLayout","defaultBillingDetails","returnURL","style","billingDetailsCollectionConfiguration","shippingDetails","enableApplePay","enableGooglePay"],O={horizontal:"tabs",vertical:"accordion",automatic:"auto"},j={alwaysLight:"stripe",alwaysDark:"night"},S=e=>Object.fromEntries(Object.entries(e).filter((([,e])=>void 0!==e))),k=e=>{const{postalCode:t}=e,i=g(e,["postalCode"]);return S(Object.assign(Object.assign({},i),{postal_code:t}))},C=e=>null==e?void 0:e?"auto":"never",_=e=>{if(null==e)return{};const{merchantDisplayName:t,paymentMethodLayout:i,defaultBillingDetails:s,billingDetailsCollectionConfiguration:n,enableApplePay:a,enableGooglePay:r}=e,o={},l=(e=>{if(null==e)return;const{email:t,name:i,phone:s,address:n}=e,a=S({email:"never"===t||"always"===t?"never":void 0,name:"never"===i?"never":void 0,phone:"never"===s||"always"===s&&"full"===n?"never":void 0,address:"never"===n||"full"===n?"never":void 0});return 0===Object.keys(a).length?void 0:a})(n),c=S({applePay:C(a),googlePay:C(r)});if(null!=l&&(o.fields={billingDetails:l}),Object.keys(c).length>0&&(o.wallets=c),null!=t&&(o.business={name:t}),null!=i&&(o.layout=O[i]),null!=s){const{address:e}=s,t=g(s,["address"]),i=S(t);null!=e&&(i.address=k(e)),o.defaultValues={billingDetails:i}}return o},x=e=>{if(null!=e)return{theme:j[e]}},D=e=>{const{name:t,phone:i,address:s}=e,n=null==s?void 0:s.country;return S({name:t,phone:i,address:null==n||""===n?void 0:Object.assign(Object.assign({},k(s)),{country:n})})},P=e=>null==e||""===e,F=(e,t)=>new Error(`<stripe-payment-sheet>: billingDetailsCollectionConfiguration.${e} is 'never', so defaultBillingDetails.${t} is required`),q=e=>Object.assign(new Error(e),{type:"validation_error",sheetValidation:!0}),R=["card_error","validation_error","api_connection_error","rate_limit_error","api_error"],A=e=>{const t=x(null==e?void 0:e.style);return null==t?void 0:{appearance:t}},L=(e,t)=>{if(null!=e&&"open"!==e.type)throw new d({type:"invalid_request_error",code:`checkout_session_${e.type}`,message:null!=t?t:`The Checkout Session is ${e.type} and can no longer be paid.`})},E=e=>null==e||""===e?void 0:e,z=class{async present(){null==this.presentPromise&&(this.presentPromise=new Promise((e=>{this.resolvePresent=e})));const e=this.presentPromise;return this.dispatch({type:"presentRequested"}),e}handleSecretChange(){this.startLoading()}handleOpenChange(e){this.dispatch({type:e?"openRequested":"closeRequested"})}constructor(i){e(this,i),this.paymentSheetLoaded=t(this,"paymentSheetLoaded",7),this.paymentSheetFailedToLoad=t(this,"paymentSheetFailedToLoad",7),this.paymentSheetCompleted=t(this,"paymentSheetCompleted",7),this.paymentSheetCanceled=t(this,"paymentSheetCanceled",7),this.paymentSheetFailed=t(this,"paymentSheetFailed",7),this.warnedUnsupportedOptions=!1,this.warnedCheckoutIgnoredOptions=!1,this.open=!1,this.sheetTitle="Add your payment information",this.buttonLabel="Pay",this.applicationName="stripe-pwa-elements",this.sheet=h,this.visible=!1,this.errorMessage="",this.handleSubmit=e=>{e.preventDefault(),this.errorMessage="",this.dispatch({type:"submitted"})},this.handleModalClose=()=>{var e;this.dispatch({type:"closeRequested"}),this.visible&&(null===(e=this.el.querySelector("stripe-modal"))||void 0===e||e.openModal())},this.stripeService=o.createStripeService(),this.paymentElementManager=o.createPaymentElementManager(this.stripeService),this.billingAddressElementManager=o.createAddressElementManager(this.stripeService),this.shippingAddressElementManager=o.createAddressElementManager(this.stripeService),this.emailElementManager=o.createLinkAuthenticationElementManager(this.stripeService)}componentWillLoad(){this.open&&this.dispatch({type:"openRequested"}),this.startLoading()}componentDidLoad(){this.el.classList.add(a())}disconnectedCallback(){this.paymentElementManager.unmount(),this.unmountExtraElements()}unmountExtraElements(){this.billingAddressElementManager.unmount(),this.shippingAddressElementManager.unmount(),this.emailElementManager.unmount()}startLoading(){const e=this.loadTarget();null!=e&&e.key!==this.lastLoadKey&&(this.lastLoadKey=e.key,this.dispatch({type:"secretChanged",clientSecret:e.clientSecret,source:e.source}))}loadTarget(){var e;const t=E(this.publishableKey);if(null==t)return;const i=E(this.checkoutSessionClientSecret),s=E(this.intentClientSecret),[n,a]=null!=i?[i,"checkoutSession"]:[s,"intent"];return null!=n?{key:JSON.stringify([t,null!==(e=E(this.stripeAccount))&&void 0!==e?e:null,a,n]),clientSecret:n,source:a}:void 0}dispatch(e){const{state:t,effects:i}=((e,t)=>{switch(t.type){case"secretChanged":return y(e,t.clientSecret,t.source);case"loadSucceeded":{if(t.generation!==e.generation||"loading"!==e.phase)return u(e);const i=e.openRequested;return{state:Object.assign(Object.assign({},e),{phase:i?"presented":"ready",openRequested:!1}),effects:[{type:"emit",event:"paymentSheetLoaded"},...i?[{type:"show"}]:[]]}}case"loadFailed":{if(t.generation!==e.generation||"loading"!==e.phase)return u(e);const i=m(Object.assign(Object.assign({},e),{phase:"loadFailed",openRequested:!1}),"paymentSheetFailed");return{state:i.state,effects:[{type:"emit",event:"paymentSheetFailedToLoad"},...i.effects]}}case"presentRequested":if(e.pendingPresent)return u(e);switch(e.phase){case"ready":return{state:Object.assign(Object.assign({},e),{phase:"presented",pendingPresent:!0}),effects:[{type:"show"}]};case"idle":case"loading":return u(Object.assign(Object.assign({},e),{pendingPresent:!0,openRequested:!0}));case"presented":case"confirming":return u(Object.assign(Object.assign({},e),{pendingPresent:!0}));default:return{state:e,effects:[{type:"resolvePresent",result:"paymentSheetFailed"}]}}case"openRequested":return"ready"===e.phase?{state:Object.assign(Object.assign({},e),{phase:"presented"}),effects:[{type:"show"}]}:u("idle"===e.phase||"loading"===e.phase?Object.assign(Object.assign({},e),{openRequested:!0}):e);case"closeRequested":if("presented"===e.phase){const t=f(e);return{state:Object.assign(Object.assign({},t.state),{phase:"ready"}),effects:t.effects}}return"idle"!==e.phase&&"loading"!==e.phase||!e.openRequested?u(e):f(e);case"submitted":return"presented"!==e.phase||null==e.intentKind?u(e):{state:Object.assign(Object.assign({},e),{phase:"confirming"}),effects:[{type:"confirm",generation:e.generation,intentKind:e.intentKind}]};case"confirmSucceeded":{if(!v(e,t.generation))return u(e);const i=m(Object.assign(Object.assign({},e),{phase:"completed"}),"paymentSheetCompleted");return b({state:i.state,effects:[{type:"hide"},{type:"emit",event:"paymentSheetCompleted"},...i.effects]})}case"confirmDeclined":return v(e,t.generation)?b({state:Object.assign(Object.assign({},e),{phase:"presented"}),effects:[{type:"showError",message:t.message}]}):u(e);case"confirmFailed":{if(!v(e,t.generation))return u(e);const i=m(Object.assign(Object.assign({},e),{phase:"errored"}),"paymentSheetFailed");return b({state:i.state,effects:[{type:"hide"},{type:"emit",event:"paymentSheetFailed"},...i.effects]})}}})(this.sheet,e);this.sheet=t,i.forEach((e=>this.perform(e)))}perform(e){var t;switch(e.type){case"load":"checkoutSession"===e.intentKind?this.loadCheckoutSession(e.generation,e.clientSecret):this.load(e.generation,e.clientSecret,e.intentKind);break;case"show":this.visible=!0,this.open=!0;break;case"hide":this.visible=!1,this.open=!1;break;case"confirm":"checkoutSession"===e.intentKind?this.confirmCheckoutSession(e.generation):this.confirm(e.generation,e.intentKind);break;case"showError":this.errorMessage=e.message;break;case"emit":this.emit(e.event);break;case"resolvePresent":null===(t=this.resolvePresent)||void 0===t||t.call(this,{paymentResult:e.result}),this.presentPromise=void 0,this.resolvePresent=void 0}}async load(e,t,i){var s;this.warnUnsupportedOptions(i);const n=()=>e!==this.sheet.generation;try{const a=((e,t)=>{var i,s,n,a,r,o,l;const c=null!==(i=null==e?void 0:e.billingDetailsCollectionConfiguration)&&void 0!==i?i:{},d=null!==(s=null==e?void 0:e.defaultBillingDetails)&&void 0!==s?s:{},h={};if(["email","name","phone"].forEach((e=>{if("never"===c[e]){if(P(d[e]))throw F(e,e);h[e]=d[e]}})),"never"===c.address){const e=d.address;if(null==e||P(e.country))throw F("address","address.country");h.address={line1:null!==(n=e.line1)&&void 0!==n?n:"",line2:null!==(a=e.line2)&&void 0!==a?a:"",city:null!==(r=e.city)&&void 0!==r?r:"",state:null!==(o=e.state)&&void 0!==o?o:"",postal_code:null!==(l=e.postalCode)&&void 0!==l?l:"",country:e.country}}const p="full"===c.address&&"always"===c.phone,u={fixedBillingDetails:h,collectPhoneFromAddress:p};if("full"===c.address){const e={mode:"billing",defaultValues:D(d)};p?(e.fields={phone:"always"},e.validation={phone:{required:"always"}}):"never"===c.phone&&(e.fields={phone:"never"}),u.billingAddressElement=e}"always"===c.email&&(u.emailElement=P(d.email)?{}:{defaultValues:{email:d.email}});const m=null==e?void 0:e.shippingDetails;if(null!=m&&"payment"===t){const e={mode:"shipping",defaultValues:D(m)};P(m.phone)||(e.fields={phone:"always"}),u.shippingAddressElement=e}return u})(this.options,i);if(await this.stripeService.initialize(this.publishableKey,{stripeAccount:this.stripeAccount,applicationName:this.applicationName,clientSecret:t}),n())return;if("success"!==this.stripeService.state.loadStripeStatus)throw new Error("Failed to load Stripe.js");const r=x(null===(s=this.options)||void 0===s?void 0:s.style);if(null!=r&&(await this.stripeService.getElements().update({appearance:r}),n()))return;if(!await this.mountExtraElements(a,n))return;await this.paymentElementManager.initialize(this.el,_(this.options)),this.dispatch({type:"loadSucceeded",generation:e})}catch(t){if(n())return;this.lastError=t,this.dispatch({type:"loadFailed",generation:e})}}async mountExtraElements(e,t){this.collection=e;const{emailElement:i,shippingAddressElement:s,billingAddressElement:n}=e,a=[{manager:this.emailElementManager,selector:".stripe-payment-sheet-email",mount:i&&(e=>this.emailElementManager.initialize(e,i))},{manager:this.shippingAddressElementManager,selector:".stripe-payment-sheet-shipping-address",mount:s&&(e=>this.shippingAddressElementManager.initialize(e,s))},{manager:this.billingAddressElementManager,selector:".stripe-payment-sheet-billing-address",mount:n&&(e=>this.billingAddressElementManager.initialize(e,n))}];for(const{manager:e,selector:i,mount:s}of a){if(null==s){e.unmount();continue}const n=await l(this.el,i);if(t())return!1;if(await s(n),t())return!1}return!0}async confirmParams(){var e;const t=this.collection;if(null==t)return;const i=null!=t.billingAddressElement?await(null===(e=this.billingAddressElementManager.getElement())||void 0===e?void 0:e.getValue()):void 0,s=null!=t.emailElement?this.emailElementManager.getState():void 0,n=((e,t)=>{var i,s;const n={};if(null!=e.billingAddressElement){const i=t.billingAddress;if(null==i||!i.complete)throw q("Please complete your billing address.");n.name=i.value.name,n.address=i.value.address,e.collectPhoneFromAddress&&(n.phone=i.value.phone)}if(null!=e.emailElement){const a=null!==(i=t.email)&&void 0!==i?i:null===(s=e.emailElement.defaultValues)||void 0===s?void 0:s.email;if(P(a))throw q("Please enter your email address.");if(!1===t.emailComplete||null==t.emailComplete&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a))throw q("Please enter a valid email address.");n.email=a}return Object.assign(n,e.fixedBillingDetails),0===Object.keys(n).length?void 0:n})(t,{billingAddress:i,email:null==s?void 0:s.email,emailComplete:null==s?void 0:s.complete});return null==n?void 0:{payment_method_data:{billing_details:n}}}confirm(e,t){return this.runConfirm(e,(async()=>{var e,i;const s=this.stripeService.getElements(),{error:n}=await s.submit();if(null!=n)throw n;const a=null!==(i=null===(e=this.options)||void 0===e?void 0:e.returnURL)&&void 0!==i?i:window.location.href,r=await this.confirmParams();return c(this.stripeService.getStripe(),s,t,a,r)}))}async runConfirm(e,t){var i,s;try{this.lastResult=await t(),this.dispatch({type:"confirmSucceeded",generation:e})}catch(t){const n=null!==(i=t.message)&&void 0!==i?i:String(t),a=!0===(null==(s=t)?void 0:s.sheetValidation)?r.t(n):n;if((e=>{const t=null==e?void 0:e.type;return"string"==typeof t&&R.includes(t)})(t))return void this.dispatch({type:"confirmDeclined",generation:e,message:a});this.lastError=t,this.dispatch({type:"confirmFailed",generation:e,message:a})}}async loadCheckoutSession(e,t){this.warnUnsupportedOptions("checkoutSession"),this.warnCheckoutIgnoredOptions(),this.collection=void 0,this.unmountExtraElements();try{if(await this.stripeService.initializeWithCheckoutSession(this.publishableKey,t,{stripeAccount:this.stripeAccount,applicationName:this.applicationName,elementsOptions:A(this.options)}),e!==this.sheet.generation)return;if("success"!==this.stripeService.state.loadStripeStatus)throw new Error("Failed to load Stripe.js");await this.paymentElementManager.initialize(this.el,(e=>{const{layout:t}=_(e);return null==t?{}:{layout:t}})(this.options)),this.dispatch({type:"loadSucceeded",generation:e})}catch(t){if(e!==this.sheet.generation)return;this.lastError=t,this.dispatch({type:"loadFailed",generation:e})}}confirmCheckoutSession(e){var t,i;const s=null!==(i=null===(t=this.options)||void 0===t?void 0:t.returnURL)&&void 0!==i?i:window.location.href;return this.runConfirm(e,(async()=>{var e,t;const i=this.stripeService.getCheckout();if(null==i)throw new Error("Checkout Session is not initialized");return(async(e,t,i)=>{const s=await e.loadActions();if("error"===s.type)throw new d({type:"api_error",code:"checkout_session_error",message:s.error.message});const{actions:n}=s,a=()=>{var e,t;return null===(t=null===(e=n.getSession)||void 0===e?void 0:e.call(n))||void 0===t?void 0:t.status};L(a());const r=await n.confirm(Object.assign({returnUrl:t,redirect:"if_required"},null!=i&&""!==i?{email:i}:{}));if("error"===r.type){const{code:e,message:t}=r.error;if(L(a(),t),"paymentFailed"===e)throw new d({type:"card_error",code:e,message:t});throw new d({type:"api_error",code:"checkout_session_error",message:t})}return r})(i,s,null===(t=null===(e=this.options)||void 0===e?void 0:e.defaultBillingDetails)||void 0===t?void 0:t.email)}))}emit(e){switch(e){case"paymentSheetLoaded":this.paymentSheetLoaded.emit({stripe:this.stripeService.getStripe()});break;case"paymentSheetFailedToLoad":this.paymentSheetFailedToLoad.emit(this.lastError);break;case"paymentSheetCompleted":this.paymentSheetCompleted.emit(this.lastResult);break;case"paymentSheetCanceled":this.paymentSheetCanceled.emit();break;case"paymentSheetFailed":this.paymentSheetFailed.emit(this.lastError)}}warnUnsupportedOptions(e){const t=((e,t)=>{if(null==e)return[];const i=Object.entries(e).filter((([e,t])=>void 0!==t&&!w.includes(e))).map((([e])=>e)),s=e.billingDetailsCollectionConfiguration;return"always"===(null==s?void 0:s.name)&&i.push("billingDetailsCollectionConfiguration.name"),"always"===(null==s?void 0:s.phone)&&"full"!==s.address&&i.push("billingDetailsCollectionConfiguration.phone"),null!=e.shippingDetails&&"setup"===t&&i.push("shippingDetails"),i.sort()})(this.options,e);this.warnedUnsupportedOptions||0===t.length||(this.warnedUnsupportedOptions=!0,console.warn(`<stripe-payment-sheet>: these options have no effect on the web yet: ${t.join(", ")}`))}warnCheckoutIgnoredOptions(){const e=(e=>{if(null==e)return[];const{merchantDisplayName:t,defaultBillingDetails:i}=e,s=["name","phone","address"].filter((e=>null!=(null==i?void 0:i[e]))).map((e=>`defaultBillingDetails.${e}`));return null!=t&&s.push("merchantDisplayName"),["billingDetailsCollectionConfiguration","shippingDetails","enableApplePay","enableGooglePay"].filter((t=>void 0!==e[t])).forEach((e=>s.push(e))),s.sort()})(this.options);this.warnedCheckoutIgnoredOptions||0===e.length||(this.warnedCheckoutIgnoredOptions=!0,console.warn(`<stripe-payment-sheet>: these options have no effect with a Checkout Session: ${e.join(", ")}`))}render(){var e,t,n;const{phase:a}=this.sheet,o="confirming"===a;return i(s,{key:"e6b2c3cb168039eb428eaaee1dce598f534c18e7"},i("stripe-modal",{key:"ef1515b07cca402c4db8818e2e94ca80e4d954c2",open:this.visible,showCloseButton:!o,onClose:this.handleModalClose},i("div",{key:"9252fa1653b206d211756c94325c73a8ec482a37",class:"stripe-payment-sheet-wrap"},i("form",{key:"904a54f2439e0356c2cbf9227326efe446aa08ce",id:"stripe-payment-sheet",onSubmit:this.handleSubmit},i("div",{key:"103d81e3c56cfba1c421e1bf140a49e2b392c6b5",class:"stripe-heading"},r.t(this.sheetTitle)),i("div",{key:"cda58a48db7b04af1981407b7100def815404e35",class:"payment-info visible"},i("div",{key:"cbe248666aa4807c25d492df1ab1de017bc78e2c",class:"stripe-payment-sheet-email"},null!=(null===(e=this.collection)||void 0===e?void 0:e.emailElement)&&i("div",{key:"b0210c6cce85d1affaa83e3fa30785158c9bab98",id:"link-authentication-element"})),i("div",{key:"2420956298e5b36c63f3fbea6b4e32429b7ace27",class:"stripe-payment-sheet-shipping-address"},null!=(null===(t=this.collection)||void 0===t?void 0:t.shippingAddressElement)&&i("div",{key:"ae41335a42c59598e1addbfdea0a13342c026456",id:"address-element"})),i("div",{key:"3196844c9396c40548a3c632733565027df3cea7",class:"stripe-payment-sheet-billing-address"},null!=(null===(n=this.collection)||void 0===n?void 0:n.billingAddressElement)&&i("div",{key:"269a99368975db70722fc181a1c099859f23d3d6",id:"address-element"})),i("div",{key:"2a63173a607501ff08ac072956cdbe462a4400c1",id:"payment-element"})),i("div",{key:"7a72a86097aca2af6491c56b52258286ef820283",class:"stripe-element-errors",role:"alert"},this.errorMessage),i("div",{key:"10f05d5ecfa53cde350f00acffd86e232e370fe7",class:"stripe-submit"},i("button",{key:"a7ad3e538b94403bd8c71b31bd405c1b0c59543c",type:"submit",disabled:"presented"!==a},r.t(o?"Loading":this.buttonLabel)))))))}get el(){return n(this)}static get watchers(){return{publishableKey:[{handleSecretChange:0}],intentClientSecret:[{handleSecretChange:0}],checkoutSessionClientSecret:[{handleSecretChange:0}],stripeAccount:[{handleSecretChange:0}],open:[{handleOpenChange:0}]}}};z.style=':root{--color-label:#565656;--color-placeholder:#acacac;--color-heading-text:#333;--color-text-error:#ef4444;--color-input-border:#e4e4e6;--color-input-border-shadow:rgba(228, 228, 230, 0.6);--color-button-text:rgba(255, 255, 255, 0.95);--color-button-text-disabled:rgba(255, 255, 255, 0.4);--color-primary:#0074d4}stripe-payment-sheet{display:contents}.stripe-payment-sheet-wrap{box-sizing:border-box}.stripe-payment-sheet-wrap *:where(:not(iframe,canvas,img,svg,video):not(svg *)){all:unset;display:revert;background:none;border:none;font-family:"Roboto", sans-serif;box-sizing:border-box}.stripe-payment-sheet-wrap button{cursor:pointer}.stripe-payment-sheet-wrap{display:block;width:100%;background:#fff;padding:32px 16px}.stripe-payment-sheet-wrap .stripe-heading{font-size:24px;font-weight:bold;color:var(--color-heading-text);margin-bottom:24px}.stripe-payment-sheet-wrap .payment-info{margin-top:8px}.stripe-payment-sheet-wrap .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}.stripe-payment-sheet-wrap .stripe-submit{margin-top:32px}.stripe-payment-sheet-wrap button{display:block;color:var(--color-button-text);background-color:var(--color-primary);width:100%;text-align:center;padding:16px 16px;font-size:18px;border-radius:6px;min-height:42px}.stripe-payment-sheet-wrap button:disabled{color:var(--color-button-text-disabled)}';export{z as stripe_payment_sheet}