stripe-pwa-elements 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/factory-Cm6zUD7R.js +1206 -0
- package/dist/cjs/{factory-Cd2VI_N2.js → i18n-lBbOeQt4.js} +12 -1149
- package/dist/cjs/ion-icon_2.cjs.entry.js +725 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stripe-address-element.cjs.entry.js +5 -4
- package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
- package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +8 -93
- package/dist/cjs/stripe-currency-selector.cjs.entry.js +4 -3
- package/dist/cjs/stripe-elements.cjs.js +1 -1
- package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +24 -5
- package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +4 -3
- package/dist/cjs/stripe-payment-element.cjs.entry.js +12 -124
- package/dist/cjs/stripe-payment-element.helpers-CvAhIqLt.js +119 -0
- package/dist/cjs/stripe-payment-request-button.cjs.entry.js +2 -2
- package/dist/cjs/stripe-payment-sheet.cjs.entry.js +987 -0
- package/dist/collection/collection-manifest.json +2 -1
- package/dist/collection/components/stripe-address-element/stripe-address-element.js +2 -2
- package/dist/collection/components/stripe-card-element/stripe-card-element.js +3 -2
- package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
- package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +18 -0
- package/dist/collection/components/stripe-modal/stripe-modal.css +27 -1
- package/dist/collection/components/stripe-modal/stripe-modal.js +132 -1
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +4 -7
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +4 -4
- package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +3 -3
- package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +193 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +94 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +274 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +763 -0
- package/dist/collection/services/express-checkout-element-manager.js +36 -2
- package/dist/collection/services/link-authentication-element-manager.js +5 -0
- package/dist/collection/services/stripe-service.js +20 -6
- package/dist/collection/utils/focus.js +76 -0
- package/dist/collection/utils/i18n.js +12 -0
- package/dist/components/factory.js +1 -1
- package/dist/components/i18n.js +1 -0
- package/dist/components/stripe-address-element.js +1 -1
- package/dist/components/stripe-card-element-modal.js +1 -1
- package/dist/components/stripe-card-element2.js +1 -1
- package/dist/components/stripe-currency-selector.js +1 -1
- package/dist/components/stripe-express-checkout-element.js +1 -1
- package/dist/components/stripe-link-authentication-element.js +1 -1
- package/dist/components/stripe-modal2.js +1 -1
- package/dist/components/stripe-payment-element.helpers.js +1 -0
- package/dist/components/stripe-payment-element.js +1 -1
- package/dist/components/stripe-payment-request-button2.js +1 -1
- package/dist/components/stripe-payment-sheet.d.ts +11 -0
- package/dist/components/stripe-payment-sheet.js +1 -0
- package/dist/esm/factory-BaGv8K_i.js +1203 -0
- package/dist/esm/{factory-VTa1Gc94.js → i18n-CL5n3bOb.js} +13 -1149
- package/dist/esm/ion-icon_2.entry.js +722 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stripe-address-element.entry.js +2 -1
- package/dist/esm/stripe-card-element-modal.entry.js +3 -2
- package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +6 -90
- package/dist/esm/stripe-currency-selector.entry.js +2 -1
- package/dist/esm/stripe-elements.js +1 -1
- package/dist/esm/stripe-express-checkout-element.entry.js +20 -1
- package/dist/esm/stripe-link-authentication-element.entry.js +2 -1
- package/dist/esm/stripe-payment-element.entry.js +4 -116
- package/dist/esm/stripe-payment-element.helpers-Bu9RfxS4.js +114 -0
- package/dist/esm/stripe-payment-request-button.entry.js +2 -2
- package/dist/esm/stripe-payment-sheet.entry.js +985 -0
- package/dist/stripe-elements/p-2e41699e.entry.js +1 -0
- package/dist/stripe-elements/p-3fc4583a.entry.js +1 -0
- package/dist/stripe-elements/{p-ae0c336e.entry.js → p-4891edf0.entry.js} +1 -1
- package/dist/stripe-elements/p-7e826964.entry.js +1 -0
- package/dist/stripe-elements/p-BhKXGROE.js +1 -0
- package/dist/stripe-elements/p-CL5n3bOb.js +1 -0
- package/dist/stripe-elements/p-DlMEZwSe.js +1 -0
- package/dist/stripe-elements/p-a395a5d1.entry.js +1 -0
- package/dist/stripe-elements/p-b62c9dae.entry.js +1 -0
- package/dist/stripe-elements/p-b7c20e8e.entry.js +1 -0
- package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
- package/dist/stripe-elements/p-bec62526.entry.js +1 -0
- package/dist/stripe-elements/p-f5552c81.entry.js +1 -0
- package/dist/stripe-elements/stripe-elements.esm.js +1 -1
- package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +2 -1
- package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
- package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +5 -0
- package/dist/types/components/stripe-modal/stripe-modal.d.ts +43 -0
- package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +7 -2
- package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +1 -1
- package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +121 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +39 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +157 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +153 -0
- package/dist/types/components.d.ts +182 -10
- package/dist/types/index.d.ts +2 -0
- package/dist/types/services/interfaces.d.ts +3 -0
- package/dist/types/services/stripe-service.d.ts +7 -2
- package/dist/types/utils/focus.d.ts +15 -0
- package/package.json +7 -3
- package/readme.md +59 -6
- package/dist/cjs/ion-icon.cjs.entry.js +0 -431
- package/dist/components/utils.js +0 -1
- package/dist/esm/ion-icon.entry.js +0 -429
- package/dist/stripe-elements/p-1bd46766.entry.js +0 -1
- package/dist/stripe-elements/p-1c6e0a45.entry.js +0 -1
- package/dist/stripe-elements/p-3f42ca0c.entry.js +0 -1
- package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
- package/dist/stripe-elements/p-74de1556.entry.js +0 -1
- package/dist/stripe-elements/p-76e57d78.entry.js +0 -1
- package/dist/stripe-elements/p-840d499f.entry.js +0 -1
- package/dist/stripe-elements/p-CrjrbGJ3.js +0 -1
- package/dist/stripe-elements/p-cfd8e081.entry.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as t,proxyCustomElement as e,HTMLElement as s,createEvent as i,h as r}from"@stencil/core/internal/client";import{c as o}from"./
|
|
1
|
+
import{transformTag as t,proxyCustomElement as e,HTMLElement as s,createEvent as i,h as r}from"@stencil/core/internal/client";import{c as o,i as a}from"./i18n.js";import{s as n}from"./factory.js";const l=e(class extends s{async initStripe(t,e){if(await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async e=>{"success"===e&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.addressElementManager.setError(t),this}async getValue(){const t=this.addressElementManager.getElement();if(null==t)throw Error("Address element not initialized");return await t.getValue({format:"localized"})}updatePublishableKey(t){const e={};null!=this.stripeAccount&&""!==this.stripeAccount&&(e.stripeAccount=this.stripeAccount),this.initStripe(t,Object.keys(e).length>0?e:void 0)}updateStripeAccountId(t){const e=this.stripeService.state.publishableKey||this.publishableKey;null!=e&&""!==e&&this.initStripe(e,{stripeAccount:t})}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async formSubmitEventHandler(){const t=await this.getValue();this.formSubmit.emit({address:t})}componentWillRender(){null!=this.stripeService.state.publishableKey&&""!==this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}constructor(t){super(),!1!==t&&this.__registerHost(),this.stripeLoaded=i(this,"stripeLoaded",7),this.formSubmit=i(this,"formSubmit",7),this.mode="billing",this.sheetTitle="Billing address",this.buttonLabel="Save",this.progress="",this.applicationName="stripe-pwa-elements",this.showLabel=!1,this.stripeService=n.createStripeService(),this.addressElementManager=n.createAddressElementManager(this.stripeService)}componentWillLoad(){null!=this.publishableKey&&""!==this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}async initElement(){const t={mode:this.mode};null!=this.defaultCountry&&""!==this.defaultCountry&&(t.defaultValues={address:{country:this.defaultCountry}}),this.allowedCountries&&this.allowedCountries.length>0&&(t.allowedCountries=this.allowedCountries),await this.addressElementManager.initialize(this.el,t);const e=this.el.querySelector("#stripe-address-element-form");null!=e?(null!=this.formSubmitListener&&e.removeEventListener("submit",this.formSubmitListener),this.formSubmitListener=async t=>{if(t.preventDefault(),null!=this.addressElementManager.getElement()){this.progress="loading";try{const e=await this.getValue();null!=this.handleSubmit&&await this.handleSubmit(t,{address:e}),await this.formSubmitEventHandler(),null!=this.handleSubmit&&(this.progress="success")}catch(t){this.addressElementManager.setError(t instanceof Error?t.message:t+""),this.progress="failure"}}else console.error("Address element not initialized")},e.addEventListener("submit",this.formSubmitListener)):console.error("Form element #stripe-address-element-form not found")}componentDidLoad(){this.el.classList.add(o())}disconnectedCallback(){if(null!=this.formSubmitListener){const t=this.el.querySelector("#stripe-address-element-form");null!=t&&t.removeEventListener("submit",this.formSubmitListener),this.formSubmitListener=void 0}this.addressElementManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:e}=this.addressElementManager.getState();if("failure"===t)return r("p",null,a.t("Failed to load Stripe"));const s="loading"===this.progress;return r("div",{class:"stripe-payment-sheet-wrap"},r("form",{id:"stripe-address-element-form"},r("div",{class:"stripe-heading"},a.t(this.sheetTitle)),r("div",{class:"payment-info address visible"},r("div",{id:"address-element"})),r("div",{id:"address-errors",class:"stripe-element-errors"},e),r("div",{class:"submit-button-wrapper"},r("button",{type:"submit",disabled:s},a.t("loading"===this.progress?"Loading":this.buttonLabel)))))}get el(){return this}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}static get style(){return':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 #address-element{margin-top: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 .stripe-section-title{font-size:14px;font-weight:bold;color:var(--color-label);margin-bottom:8px}.stripe-payment-sheet-wrap .payment-info.address{margin-bottom:16px}.stripe-payment-sheet-wrap .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}.stripe-payment-sheet-wrap .submit-button-wrapper{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)}'}},[0,"stripe-address-element",{mode:[1],sheetTitle:[1,"sheet-title"],buttonLabel:[1,"button-label"],publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],showLabel:[4,"show-label"],defaultCountry:[1,"default-country"],allowedCountries:[16],handleSubmit:[1040],stripeDidLoaded:[1040],progress:[32],initStripe:[64],updateProgress:[64],setErrorMessage:[64],getValue:[64]},void 0,{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}]);function p(){"undefined"!=typeof customElements&&["stripe-address-element"].forEach((e=>{"stripe-address-element"===e&&(customElements.get(t(e))||customElements.define(t(e),l))}))}p();const d=l,h=p;export{d as StripeAddressElement,h as defineCustomElement}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as e,proxyCustomElement as t,HTMLElement as s,createEvent as i,h as n}from"@stencil/core/internal/client";import{d as r}from"./icon.js";import{d as o}from"./stripe-card-element2.js";import{d as a}from"./stripe-modal2.js";import{d as l}from"./stripe-payment-request-button2.js";const c=t(class extends s{constructor(e){super(),!1!==e&&this.__registerHost(),this.closed=i(this,"closed",7),this.showLabel=!1,this.shouldUseDefaultFormSubmitAction=!0,this.intentType="payment",this.showCloseButton=!0,this.zip=!0,this.open=!1}componentDidLoad(){this.el.querySelector("stripe-modal").addEventListener("close",(()=>{this.closed.emit()}))}async getStripeCardElementElement(){return this.el.querySelector("stripe-card-element")}async present(){return this.open=!0,new Promise(((e,t)=>{this.el.querySelector("stripe-card-element").addEventListener("formSubmit",(async t=>{e(t)})),this.el.addEventListener("closed",(()=>t()))}))}async updateProgress(e){return this.el.querySelector("stripe-card-element").updateProgress(e)}async destroy(){this.el.querySelector("stripe-card-element").remove(),this.el.remove()}async setPaymentRequestButton(e){const t=this.el.getElementsByTagName("stripe-card-element");if(t.length<1)return;const s=t[0];s&&(s.setAttribute("show-payment-request-button","true"),this.applicationName&&s.setAttribute("application-name",this.applicationName),s.setPaymentRequestOption(e))}render(){return n("stripe-modal",{key:"
|
|
1
|
+
import{transformTag as e,proxyCustomElement as t,HTMLElement as s,createEvent as i,h as n}from"@stencil/core/internal/client";import{d as r}from"./icon.js";import{d as o}from"./stripe-card-element2.js";import{d as a}from"./stripe-modal2.js";import{d as l}from"./stripe-payment-request-button2.js";const c=t(class extends s{constructor(e){super(),!1!==e&&this.__registerHost(),this.closed=i(this,"closed",7),this.showLabel=!1,this.shouldUseDefaultFormSubmitAction=!0,this.intentType="payment",this.showCloseButton=!0,this.zip=!0,this.open=!1}componentDidLoad(){this.el.querySelector("stripe-modal").addEventListener("close",(()=>{this.closed.emit()}))}async getStripeCardElementElement(){return this.el.querySelector("stripe-card-element")}async present(){return this.open=!0,new Promise(((e,t)=>{this.el.querySelector("stripe-card-element").addEventListener("formSubmit",(async t=>{e(t)})),this.el.addEventListener("closed",(()=>t()))}))}async updateProgress(e){return this.el.querySelector("stripe-card-element").updateProgress(e)}async destroy(){this.el.querySelector("stripe-card-element").remove(),this.el.remove()}async setPaymentRequestButton(e){const t=this.el.getElementsByTagName("stripe-card-element");if(t.length<1)return;const s=t[0];s&&(s.setAttribute("show-payment-request-button","true"),this.applicationName&&s.setAttribute("application-name",this.applicationName),s.setPaymentRequestOption(e))}render(){return n("stripe-modal",{key:"4904f57b562da9ce4fc348fb376f931cac707540",open:this.open,showCloseButton:this.showCloseButton},n("stripe-card-element",{key:"8707fa6e32ca82b700f53fc2a257b8af1cc7b45c",showLabel:this.showLabel,publishableKey:this.publishableKey,intentClientSecret:this.intentClientSecret,shouldUseDefaultFormSubmitAction:this.shouldUseDefaultFormSubmitAction,handleSubmit:this.handleSubmit,stripeDidLoaded:this.stripeDidLoaded,intentType:this.intentType,zip:this.zip,buttonLabel:this.buttonLabel,sheetTitle:this.sheetTitle,applicationName:this.applicationName}))}get el(){return this}static get style(){return"stripe-card-element-modal{display:block}"}},[0,"stripe-card-element-modal",{publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],showLabel:[4,"show-label"],sheetTitle:[1,"sheet-title"],buttonLabel:[1,"button-label"],intentClientSecret:[1,"intent-client-secret"],shouldUseDefaultFormSubmitAction:[4,"should-use-default-form-submit-action"],intentType:[1,"intent-type"],handleSubmit:[1040],stripeDidLoaded:[1040],showCloseButton:[4,"show-close-button"],zip:[4],open:[4],getStripeCardElementElement:[64],present:[64],updateProgress:[64],destroy:[64],setPaymentRequestButton:[64]}]);function m(){"undefined"!=typeof customElements&&["stripe-card-element-modal","ion-icon","stripe-card-element","stripe-modal","stripe-payment-request-button"].forEach((t=>{switch(t){case"stripe-card-element-modal":customElements.get(e(t))||customElements.define(e(t),c);break;case"ion-icon":customElements.get(e(t))||r();break;case"stripe-card-element":customElements.get(e(t))||o();break;case"stripe-modal":customElements.get(e(t))||a();break;case"stripe-payment-request-button":customElements.get(e(t))||l()}}))}m();const p=c,u=m;export{p as StripeCardElementModal,u as defineCustomElement}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as t,proxyCustomElement as e,HTMLElement as i,createEvent as s,h as n}from"@stencil/core/internal/client";import{c as r}from"./utils.js";import{s as o,i as l}from"./factory.js";import{S as a}from"./error.js";import{d as p}from"./stripe-payment-request-button2.js";const u=t=>{if(null!=t&&""!==t)return{stripeAccount:t}},d=e(class extends i{async initStripe(t,e){if(await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async e=>{"success"===e&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.cardElementManager.setError(t),this}updatePublishableKey(t){null!=t&&""!==t&&this.initStripe(t,u(this.stripeAccount))}updateStripeAccountId(t){const e=this.stripeService.state.publishableKey||this.publishableKey;null!=e&&""!==e&&this.initStripe(e,{stripeAccount:t})}async setPaymentRequestOption(t){return this.paymentRequestOption=t,this.createPaymentRequestButton(),this}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async formSubmitEventHandler(){const t=this.cardElementManager.getElements(),e=this.stripeService.getStripe();null!=t?this.formSubmit.emit({cardCVCElement:t.cardCVC,cardExpiryElement:t.cardExpiry,cardNumberElement:t.cardNumber,stripe:e}):console.error("Card elements not initialized")}async defaultFormSubmitResultHandler(t){this.defaultFormSubmitResult.emit(t)}componentWillRender(){const{publishableKey:t}=this.stripeService.state;null!=t&&""!==t&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(t,u(this.stripeService.state.stripeAccount)))}async defaultFormSubmitAction(t,{stripe:e,cardNumberElement:i,intentClientSecret:s}){t.preventDefault();try{const t=await((t,e,i,s)=>"payment"===this.intentType?t.confirmCardPayment(i,{payment_method:{card:s}}):t.confirmCardSetup(i,{payment_method:{card:s}}))(e,0,s,i);if(null!=t.error)throw new a(t.error);this.defaultFormSubmitResultHandler(t)}catch(t){throw console.error(t),this.defaultFormSubmitResultHandler(t),t}}constructor(t){super(),!1!==t&&this.__registerHost(),this.stripeLoaded=s(this,"stripeLoaded",7),this.formSubmit=s(this,"formSubmit",7),this.defaultFormSubmitResult=s(this,"defaultFormSubmitResult",7),this.paymentRequestButtonCreated=!1,this.intentType="payment",this.zip=!0,this.sheetTitle="Add your payment information",this.buttonLabel="Pay",this.progress="",this.zipCode="",this.applicationName="stripe-pwa-elements",this.showLabel=!1,this.shouldUseDefaultFormSubmitAction=!0,this.stripeService=o.createStripeService(),this.cardElementManager=o.createCardElementManager(this.stripeService)}componentWillLoad(){null!=this.publishableKey&&""!==this.publishableKey&&this.initStripe(this.publishableKey,u(this.stripeAccount))}async initElement(){await this.cardElementManager.initialize(this.el);const t=this.el.querySelector("#stripe-card-element");null!=t?t.addEventListener("submit",(async t=>{const e=this.cardElementManager.getElements(),i=this.stripeService.getStripe(),{intentClientSecret:s}=this;if(null==e||null==i)return void console.error("Stripe not properly initialized");const n={cardCVCElement:e.cardCVC,cardExpiryElement:e.cardExpiry,cardNumberElement:e.cardNumber,stripe:i,intentClientSecret:s,zipCode:this.zipCode};this.progress="loading";try{null!=this.handleSubmit?await this.handleSubmit(t,n):!0===this.shouldUseDefaultFormSubmitAction&&null!=s&&""!==s?await this.defaultFormSubmitAction(t,n):t.preventDefault(),await this.formSubmitEventHandler(),null==this.handleSubmit&&!0!==this.shouldUseDefaultFormSubmitAction||(this.progress="success")}catch(t){this.cardElementManager.setError(t.message),this.progress="failure"}})):console.error("Form element #stripe-card-element not found")}componentDidLoad(){this.el.classList.add(r())}componentDidRender(){this.showPaymentRequestButton&&this.paymentRequestOption&&!this.paymentRequestButtonCreated&&this.createPaymentRequestButton()}disconnectedCallback(){this.cardElementManager.unmount()}createPaymentRequestButton(){const{showPaymentRequestButton:t,paymentRequestOption:e}=this;if(this.paymentRequestButtonCreated)return null;if(!t||null==e)return null;if(null==document)return null;const i=this.el.querySelector("#stripe-payment-request-button");if(null==i)return console.error("Target element #stripe-payment-request-button not found"),null;if(null!=i.querySelector("stripe-payment-request-button"))return this.paymentRequestButtonCreated=!0,null;const s=document.createElement("stripe-payment-request-button");i.appendChild(s),customElements.whenDefined("stripe-payment-request-button").then((()=>(((t,e)=>{const{paymentRequestPaymentMethodHandler:i,paymentRequestShippingOptionChangeHandler:s,paymentRequestShippingAddressChangeHandler:n}=e;t.setPaymentRequestOption(e),null!=i&&t.setPaymentMethodEventHandler(i),null!=s&&t.setPaymentRequestShippingOptionEventHandler(s),null!=n&&t.setPaymentRequestShippingAddressEventHandler(n)})(s,e),s.initStripe(this.publishableKey)))),this.paymentRequestButtonCreated=!0}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:e}=this.cardElementManager.getState();if("failure"===t)return n("p",null,l.t("Failed to load Stripe"));const i="loading"===this.progress;return n("div",{class:"stripe-payment-sheet-wrap"},n("form",{id:"stripe-card-element"},n("div",{class:"stripe-heading"},l.t(this.sheetTitle)),n("div",{id:"stripe-payment-request-button"}),n("div",null,n("div",{class:"stripe-section-title"},l.t("Card information"))),n("div",{class:"payment-info card visible"},n("fieldset",{class:"stripe-input-box"},n("div",null,n("label",null,this.showLabel?n("lenged",null,l.t("Card Number")):null,n("div",{id:"card-number"}))),n("div",{class:"stripe-input-column",style:{display:"flex"}},n("label",{style:{width:"50%"}},this.showLabel?n("lenged",null,l.t("MM / YY")):null,n("div",{id:"card-expiry"})),n("label",{style:{width:"50%"}},this.showLabel?n("lenged",null,l.t("CVC")):null,n("div",{id:"card-cvc"}))))),n("div",{id:"card-errors",class:"stripe-element-errors"},e),this.zip?n("div",{style:{marginTop:"1.5rem"}},n("div",{class:"stripe-section-title"},l.t("Country or region"))):null,this.zip?n("div",{class:"payment-info card visible"},n("fieldset",{class:"stripe-input-box"},n("div",null,n("label",null,this.showLabel?n("lenged",null,l.t("Postal Code")):null,n("input",{id:"zip",name:"zip",type:"text",inputmode:"numeric",class:"StripeElement",style:{width:"100%"},placeholder:l.t("Postal Code"),value:this.zipCode,onInput:t=>{this.zipCode=t.target.value}}))))):null,n("div",{style:{marginTop:"32px"}},n("button",{type:"submit",disabled:i},l.t("loading"===this.progress?"Loading":this.buttonLabel)))))}get el(){return this}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}static get style(){return':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;display:flex;justify-content:center;align-items:center}.stripe-payment-sheet-wrap .StripeElement>.__PrivateStripeElement{width:100%}.stripe-payment-sheet-wrap .stripe-input-box{background-color:#fff;border-radius:6px;border:1px solid var(--color-input-border);overflow:hidden;filter:drop-shadow(0 0 2px var(--color-input-border-shadow))}.stripe-payment-sheet-wrap .stripe-input-box>*{border-bottom:1px solid var(--color-input-border)}.stripe-payment-sheet-wrap .stripe-input-box>*:last-child{border-bottom:none}.stripe-payment-sheet-wrap .stripe-input-column>*{border-right:1px solid var(--color-input-border)}.stripe-payment-sheet-wrap .stripe-input-column>*:last-child{border-right:none}.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 label{color:var(--color-label)}.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)}'}},[0,"stripe-card-element",{intentType:[1,"intent-type"],zip:[4],sheetTitle:[1,"sheet-title"],buttonLabel:[1,"button-label"],publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],showLabel:[4,"show-label"],intentClientSecret:[1,"intent-client-secret"],shouldUseDefaultFormSubmitAction:[4,"should-use-default-form-submit-action"],showPaymentRequestButton:[4,"show-payment-request-button"],handleSubmit:[1040],stripeDidLoaded:[1040],progress:[32],zipCode:[32],paymentRequestOption:[32],initStripe:[64],updateProgress:[64],setErrorMessage:[64],setPaymentRequestOption:[64]},void 0,{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}]);function c(){"undefined"!=typeof customElements&&["stripe-card-element","stripe-payment-request-button"].forEach((e=>{switch(e){case"stripe-card-element":customElements.get(t(e))||customElements.define(t(e),d);break;case"stripe-payment-request-button":customElements.get(t(e))||p()}}))}c();export{d as S,c as d}
|
|
1
|
+
import{transformTag as t,proxyCustomElement as e,HTMLElement as i,createEvent as s,h as n}from"@stencil/core/internal/client";import{c as r,i as o}from"./i18n.js";import{s as l}from"./factory.js";import{S as a}from"./error.js";import{d as p}from"./stripe-payment-request-button2.js";const u=t=>{if(null!=t&&""!==t)return{stripeAccount:t}},d=e(class extends i{async initStripe(t,e){if(await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async e=>{"success"===e&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.cardElementManager.setError(t),this}updatePublishableKey(t){null!=t&&""!==t&&this.initStripe(t,u(this.stripeAccount))}updateStripeAccountId(t){const e=this.stripeService.state.publishableKey||this.publishableKey;null!=e&&""!==e&&this.initStripe(e,{stripeAccount:t})}async setPaymentRequestOption(t){return this.paymentRequestOption=t,this.createPaymentRequestButton(),this}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async formSubmitEventHandler(){const t=this.cardElementManager.getElements(),e=this.stripeService.getStripe();null!=t?this.formSubmit.emit({cardCVCElement:t.cardCVC,cardExpiryElement:t.cardExpiry,cardNumberElement:t.cardNumber,stripe:e}):console.error("Card elements not initialized")}async defaultFormSubmitResultHandler(t){this.defaultFormSubmitResult.emit(t)}componentWillRender(){const{publishableKey:t}=this.stripeService.state;null!=t&&""!==t&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(t,u(this.stripeService.state.stripeAccount)))}async defaultFormSubmitAction(t,{stripe:e,cardNumberElement:i,intentClientSecret:s}){t.preventDefault();try{const t=await((t,e,i,s)=>"payment"===this.intentType?t.confirmCardPayment(i,{payment_method:{card:s}}):t.confirmCardSetup(i,{payment_method:{card:s}}))(e,0,s,i);if(null!=t.error)throw new a(t.error);this.defaultFormSubmitResultHandler(t)}catch(t){throw console.error(t),this.defaultFormSubmitResultHandler(t),t}}constructor(t){super(),!1!==t&&this.__registerHost(),this.stripeLoaded=s(this,"stripeLoaded",7),this.formSubmit=s(this,"formSubmit",7),this.defaultFormSubmitResult=s(this,"defaultFormSubmitResult",7),this.paymentRequestButtonCreated=!1,this.intentType="payment",this.zip=!0,this.sheetTitle="Add your payment information",this.buttonLabel="Pay",this.progress="",this.zipCode="",this.applicationName="stripe-pwa-elements",this.showLabel=!1,this.shouldUseDefaultFormSubmitAction=!0,this.stripeService=l.createStripeService(),this.cardElementManager=l.createCardElementManager(this.stripeService)}componentWillLoad(){null!=this.publishableKey&&""!==this.publishableKey&&this.initStripe(this.publishableKey,u(this.stripeAccount))}async initElement(){await this.cardElementManager.initialize(this.el);const t=this.el.querySelector("#stripe-card-element");null!=t?t.addEventListener("submit",(async t=>{const e=this.cardElementManager.getElements(),i=this.stripeService.getStripe(),{intentClientSecret:s}=this;if(null==e||null==i)return void console.error("Stripe not properly initialized");const n={cardCVCElement:e.cardCVC,cardExpiryElement:e.cardExpiry,cardNumberElement:e.cardNumber,stripe:i,intentClientSecret:s,zipCode:this.zipCode};this.progress="loading";try{null!=this.handleSubmit?await this.handleSubmit(t,n):!0===this.shouldUseDefaultFormSubmitAction&&null!=s&&""!==s?await this.defaultFormSubmitAction(t,n):t.preventDefault(),await this.formSubmitEventHandler(),null==this.handleSubmit&&!0!==this.shouldUseDefaultFormSubmitAction||(this.progress="success")}catch(t){this.cardElementManager.setError(t.message),this.progress="failure"}})):console.error("Form element #stripe-card-element not found")}componentDidLoad(){this.el.classList.add(r())}componentDidRender(){this.showPaymentRequestButton&&this.paymentRequestOption&&!this.paymentRequestButtonCreated&&this.createPaymentRequestButton()}disconnectedCallback(){this.cardElementManager.unmount()}createPaymentRequestButton(){const{showPaymentRequestButton:t,paymentRequestOption:e}=this;if(this.paymentRequestButtonCreated)return null;if(!t||null==e)return null;if(null==document)return null;const i=this.el.querySelector("#stripe-payment-request-button");if(null==i)return console.error("Target element #stripe-payment-request-button not found"),null;if(null!=i.querySelector("stripe-payment-request-button"))return this.paymentRequestButtonCreated=!0,null;const s=document.createElement("stripe-payment-request-button");i.appendChild(s),customElements.whenDefined("stripe-payment-request-button").then((()=>(((t,e)=>{const{paymentRequestPaymentMethodHandler:i,paymentRequestShippingOptionChangeHandler:s,paymentRequestShippingAddressChangeHandler:n}=e;t.setPaymentRequestOption(e),null!=i&&t.setPaymentMethodEventHandler(i),null!=s&&t.setPaymentRequestShippingOptionEventHandler(s),null!=n&&t.setPaymentRequestShippingAddressEventHandler(n)})(s,e),s.initStripe(this.publishableKey)))),this.paymentRequestButtonCreated=!0}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:e}=this.cardElementManager.getState();if("failure"===t)return n("p",null,o.t("Failed to load Stripe"));const i="loading"===this.progress;return n("div",{class:"stripe-payment-sheet-wrap"},n("form",{id:"stripe-card-element"},n("div",{class:"stripe-heading"},o.t(this.sheetTitle)),n("div",{id:"stripe-payment-request-button"}),n("div",null,n("div",{class:"stripe-section-title"},o.t("Card information"))),n("div",{class:"payment-info card visible"},n("fieldset",{class:"stripe-input-box"},n("div",null,n("label",null,this.showLabel?n("lenged",null,o.t("Card Number")):null,n("div",{id:"card-number"}))),n("div",{class:"stripe-input-column",style:{display:"flex"}},n("label",{style:{width:"50%"}},this.showLabel?n("lenged",null,o.t("MM / YY")):null,n("div",{id:"card-expiry"})),n("label",{style:{width:"50%"}},this.showLabel?n("lenged",null,o.t("CVC")):null,n("div",{id:"card-cvc"}))))),n("div",{id:"card-errors",class:"stripe-element-errors"},e),this.zip?n("div",{style:{marginTop:"1.5rem"}},n("div",{class:"stripe-section-title"},o.t("Country or region"))):null,this.zip?n("div",{class:"payment-info card visible"},n("fieldset",{class:"stripe-input-box"},n("div",null,n("label",null,this.showLabel?n("lenged",null,o.t("Postal Code")):null,n("input",{id:"zip",name:"zip",type:"text",inputmode:"numeric",class:"StripeElement",style:{width:"100%"},placeholder:o.t("Postal Code"),value:this.zipCode,onInput:t=>{this.zipCode=t.target.value}}))))):null,n("div",{style:{marginTop:"32px"}},n("button",{type:"submit",disabled:i},o.t("loading"===this.progress?"Loading":this.buttonLabel)))))}get el(){return this}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}static get style(){return':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;display:flex;justify-content:center;align-items:center}.stripe-payment-sheet-wrap .StripeElement>.__PrivateStripeElement{width:100%}.stripe-payment-sheet-wrap .stripe-input-box{background-color:#fff;border-radius:6px;border:1px solid var(--color-input-border);overflow:hidden;filter:drop-shadow(0 0 2px var(--color-input-border-shadow))}.stripe-payment-sheet-wrap .stripe-input-box>*{border-bottom:1px solid var(--color-input-border)}.stripe-payment-sheet-wrap .stripe-input-box>*:last-child{border-bottom:none}.stripe-payment-sheet-wrap .stripe-input-column>*{border-right:1px solid var(--color-input-border)}.stripe-payment-sheet-wrap .stripe-input-column>*:last-child{border-right:none}.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 label{color:var(--color-label)}.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)}'}},[0,"stripe-card-element",{intentType:[1,"intent-type"],zip:[4],sheetTitle:[1,"sheet-title"],buttonLabel:[1,"button-label"],publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],showLabel:[4,"show-label"],intentClientSecret:[1,"intent-client-secret"],shouldUseDefaultFormSubmitAction:[4,"should-use-default-form-submit-action"],showPaymentRequestButton:[4,"show-payment-request-button"],handleSubmit:[1040],stripeDidLoaded:[1040],progress:[32],zipCode:[32],paymentRequestOption:[32],initStripe:[64],updateProgress:[64],setErrorMessage:[64],setPaymentRequestOption:[64]},void 0,{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}]);function c(){"undefined"!=typeof customElements&&["stripe-card-element","stripe-payment-request-button"].forEach((e=>{switch(e){case"stripe-card-element":customElements.get(t(e))||customElements.define(t(e),d);break;case"stripe-payment-request-button":customElements.get(t(e))||p()}}))}c();export{d as S,c as d}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as t,proxyCustomElement as e,HTMLElement as s,createEvent as r,h as i}from"@stencil/core/internal/client";import{c}from"./
|
|
1
|
+
import{transformTag as t,proxyCustomElement as e,HTMLElement as s,createEvent as r,h as i}from"@stencil/core/internal/client";import{c,i as o}from"./i18n.js";import{s as n}from"./factory.js";const a=e(class extends s{updatePublishableKey(t){this.initStripe(t,{stripeAccount:this.stripeAccount})}updateStripeAccountId(t){const e=this.stripeService.state.publishableKey||this.publishableKey;e&&this.initStripe(e,{stripeAccount:t})}async initStripe(t,e){if(await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async e=>{"success"===e&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async setErrorMessage(t){return this.currencySelectorElementManager.setError(t),this}async getSelectedCurrency(){return this.currencySelectorElementManager.getState().selectedCurrency}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async currencyChangeEventHandler(t){const e={currency:t};this.currencyChange.emit(e),this.handleCurrencyChange&&await this.handleCurrencyChange(e)}componentWillRender(){this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}constructor(t){super(),!1!==t&&this.__registerHost(),this.stripeLoaded=r(this,"stripeLoaded",7),this.currencyChange=r(this,"currencyChange",7),this.applicationName="stripe-pwa-elements",this.stripeService=n.createStripeService(),this.currencySelectorElementManager=n.createCurrencySelectorElementManager(this.stripeService)}componentWillLoad(){this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}async initElement(){const t={};this.clientSecret&&(t.clientSecret=this.clientSecret),(await this.currencySelectorElementManager.initialize(this.el,t)).on("change",(t=>{var e;(null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.currency)&&this.currencyChangeEventHandler(t.value.currency)}))}componentDidLoad(){const t=c();t&&this.el.classList.add(t)}disconnectedCallback(){this.currencySelectorElementManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:e}=this.currencySelectorElementManager.getState();return"failure"===t?i("p",null,o.t("Failed to load Stripe")):i("div",{class:"stripe-currency-selector-wrap"},i("div",{id:"currency-selector"}),e?i("div",{id:"currency-selector-errors",class:"stripe-element-errors"},e):null)}get el(){return this}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}static get style(){return':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}:host{box-sizing:border-box}:host *: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}:host button{cursor:pointer}:host{display:block;width:100%}.stripe-currency-selector-wrap{width:100%;padding:0;margin:0}.stripe-currency-selector-wrap #currency-selector{width:100%;min-height:40px}.stripe-currency-selector-wrap #currency-selector-errors{margin-top:8px}'}},[0,"stripe-currency-selector",{publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],clientSecret:[1,"client-secret"],handleCurrencyChange:[1040],stripeDidLoaded:[1040],initStripe:[64],setErrorMessage:[64],getSelectedCurrency:[64]},void 0,{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}]);function l(){"undefined"!=typeof customElements&&["stripe-currency-selector"].forEach((e=>{"stripe-currency-selector"===e&&(customElements.get(t(e))||customElements.define(t(e),a))}))}l();const h=a,u=l;export{h as StripeCurrencySelector,u as defineCustomElement}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as t,proxyCustomElement as e,HTMLElement as s,createEvent as i,h as r}from"@stencil/core/internal/client";import{c as o}from"./
|
|
1
|
+
import{transformTag as t,proxyCustomElement as e,HTMLElement as s,createEvent as i,h as r}from"@stencil/core/internal/client";import{c as o,i as n}from"./i18n.js";import{s as c}from"./factory.js";import{S as a}from"./error.js";const l=e(class extends s{updatePublishableKey(t){const e={};e.stripeAccount=this.stripeService.state.stripeAccount;const s=Object.values(e).filter(Boolean).length>0;this.initStripe(t,s?e:void 0)}updateStripeAccountId(t){this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:t})}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.expressCheckoutManager.setError(t),this}async initStripe(t,e){if(await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName,clientSecret:this.clientSecret,elementsOptions:this.buildElementsOptions()}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async e=>{"success"===e&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}buildElementsOptions(){if(null!=this.currency&&""!==this.currency){if("setup"===this.intentType)return{mode:"setup",currency:this.currency};if(void 0!==this.amount)return{mode:"payment",amount:this.amount,currency:this.currency}}}async updateElementOptions(t){return this.expressCheckoutManager.update(t),this}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async defaultConfirmResultHandler(t){this.defaultConfirmResult.emit(t)}constructor(t){super(),!1!==t&&this.__registerHost(),this.stripeLoaded=i(this,"stripeLoaded",7),this.confirm=i(this,"confirm",7),this.expressCheckoutClick=i(this,"expressCheckoutClick",7),this.cancel=i(this,"cancel",7),this.defaultConfirmResult=i(this,"defaultConfirmResult",7),this.intentType="payment",this.applicationName="stripe-pwa-elements",this.shouldUseDefaultConfirmAction=!0,this.progress="",this.stripeService=c.createStripeService(),this.expressCheckoutManager=c.createExpressCheckoutElementManager(this.stripeService)}componentWillLoad(){null!=this.publishableKey&&""!==this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}componentWillUpdate(){null!=this.stripeService.state.publishableKey&&""!==this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}async defaultConfirmAction(t){try{this.progress="loading";const e=this.stripeService.getStripe(),{intentType:s,clientSecret:i}=this;if(null==e)throw Error("Stripe not initialized");if(null==i||""===i)throw Error("Client secret is required");const r=await(()=>"payment"===s?e.confirmPayment({elements:this.stripeService.getElements(),clientSecret:i,confirmParams:{return_url:`${window.location.origin}${window.location.pathname}`},redirect:"if_required"}):e.confirmSetup({elements:this.stripeService.getElements(),clientSecret:i,confirmParams:{return_url:`${window.location.origin}${window.location.pathname}`},redirect:"if_required"}))();if(null!=r.error)throw new a(r.error);t.complete("success"),this.progress="success",this.defaultConfirmResultHandler(r)}catch(e){console.error(e),t.complete("fail"),this.expressCheckoutManager.setError(e.message),this.progress="failure",this.defaultConfirmResultHandler(e)}}async initElement(){const t={mode:"payment"===this.intentType?"payment":"setup"};if(void 0!==this.amount&&(t.amount=this.amount),null!=this.currency&&""!==this.currency&&(t.currency=this.currency),null!=this.buttonHeight&&""!==this.buttonHeight)if("string"==typeof this.buttonHeight){const e=parseInt(this.buttonHeight.replace("px",""),10);isNaN(e)||(t.buttonHeight=e)}else t.buttonHeight=this.buttonHeight;await this.expressCheckoutManager.initialize(this.el,t,{onConfirm:async t=>{this.confirm.emit(t),this.shouldUseDefaultConfirmAction&&null!=this.clientSecret&&""!==this.clientSecret&&await this.defaultConfirmAction(t)},onClick:t=>{this.expressCheckoutClick.emit(t)},onCancel:()=>{this.cancel.emit(),this.progress=""}})}componentDidLoad(){this.el.classList.add(o())}disconnectedCallback(){this.expressCheckoutManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:e,isReady:s}=this.expressCheckoutManager.getState();return"failure"===t?r("p",null,n.t("Failed to load Stripe")):"loading"===t?r("p",null,n.t("Loading")):r("div",{class:"stripe-express-checkout-wrap"},r("div",{id:"express-checkout-element"}),e&&r("div",{id:"express-checkout-errors",class:"stripe-element-errors"},e),!s&&"success"===t&&r("div",{class:"stripe-express-checkout-loading"},n.t("Loading")))}get el(){return this}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}static get style(){return":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-express-checkout-wrap{width:100%;max-width:500px;margin:0 auto;padding:1rem 0}.stripe-express-checkout-wrap #express-checkout-element{margin-bottom:1rem}.stripe-express-checkout-wrap .stripe-element-errors{color:var(--stripe-error-color, #fa755a);font-size:14px;margin-top:0.5rem;padding:0.5rem;background-color:var(--stripe-error-bg, #fff5f5);border:1px solid var(--stripe-error-border, #fdd);border-radius:6px}.stripe-express-checkout-wrap .stripe-express-checkout-loading{text-align:center;padding:1rem;color:var(--stripe-loading-color, #6772e5);font-size:14px}"}},[0,"stripe-express-checkout-element",{intentType:[1,"intent-type"],publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],clientSecret:[1,"client-secret"],amount:[2],currency:[1],buttonHeight:[1,"button-height"],shouldUseDefaultConfirmAction:[4,"should-use-default-confirm-action"],stripeDidLoaded:[1040],progress:[32],updateProgress:[64],setErrorMessage:[64],initStripe:[64],updateElementOptions:[64]},void 0,{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}]);function h(){"undefined"!=typeof customElements&&["stripe-express-checkout-element"].forEach((e=>{"stripe-express-checkout-element"===e&&(customElements.get(t(e))||customElements.define(t(e),l))}))}h();const p=l,u=h;export{p as StripeExpressCheckoutElement,u as defineCustomElement}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as t,proxyCustomElement as i,HTMLElement as e,createEvent as n,h as s}from"@stencil/core/internal/client";import{c as a}from"./
|
|
1
|
+
import{transformTag as t,proxyCustomElement as i,HTMLElement as e,createEvent as n,h as s}from"@stencil/core/internal/client";import{c as a,i as r}from"./i18n.js";import{s as o}from"./factory.js";const c=i(class extends e{updatePublishableKey(t){const i={};this.stripeAccount&&(i.stripeAccount=this.stripeAccount),this.initStripe(t,Object.keys(i).length?i:void 0)}updateStripeAccountId(t){const i=this.stripeService.state.publishableKey||this.publishableKey;i&&this.initStripe(i,{stripeAccount:t})}async initStripe(t,i){if(await this.stripeService.initialize(t,{stripeAccount:null==i?void 0:i.stripeAccount,applicationName:this.applicationName}),"success"===this.stripeService.state.loadStripeStatus)await this.initElement(),this.stripeLoadedEventHandler();else{const t=this.stripeService.onChange("loadStripeStatus",(async i=>{"success"===i&&(await this.initElement(),this.stripeLoadedEventHandler(),t())}))}}async updateProgress(t){return this.progress=t,this}async setErrorMessage(t){return this.linkAuthenticationElementManager.setError(t),this}async getEmail(){return this.linkAuthenticationElementManager.getState().email}stripeLoadedEventHandler(){const t=this.stripeService.getStripe();if(!t)return void console.error("Stripe instance is not available");const i={stripe:t};this.stripeDidLoaded&&this.stripeDidLoaded(i),this.stripeLoaded.emit(i)}linkAuthenticationChangeEventHandler(t){const i=this.linkAuthenticationElementManager.getElement(),e=this.stripeService.getStripe();if(!i||!e)return void console.error("Link Authentication Element not initialized");const n={stripe:e,linkAuthenticationElement:i,email:t};this.handleChange&&this.handleChange(n),this.linkAuthenticationChange.emit(n)}componentWillRender(){this.stripeService.state.publishableKey&&(["success","loading"].includes(this.stripeService.state.loadStripeStatus)||this.initStripe(this.stripeService.state.publishableKey,{stripeAccount:this.stripeService.state.stripeAccount}))}constructor(t){super(),!1!==t&&this.__registerHost(),this.stripeLoaded=n(this,"stripeLoaded",7),this.linkAuthenticationChange=n(this,"linkAuthenticationChange",7),this.applicationName="stripe-pwa-elements",this.progress="",this.stripeService=o.createStripeService(),this.linkAuthenticationElementManager=o.createLinkAuthenticationElementManager(this.stripeService)}componentWillLoad(){this.publishableKey&&this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount})}async initElement(){const t={};this.defaultEmail&&(t.defaultValues={email:this.defaultEmail}),await this.linkAuthenticationElementManager.initialize(this.el,Object.keys(t).length?t:void 0),this.linkAuthenticationElementManager.onChange("email",(t=>{this.linkAuthenticationChangeEventHandler(t)}))}componentDidLoad(){const t=a();t&&this.el.classList.add(t)}disconnectedCallback(){this.linkAuthenticationElementManager.unmount()}render(){const{loadStripeStatus:t}=this.stripeService.state,{errorMessage:i}=this.linkAuthenticationElementManager.getState();return"failure"===t?s("p",null,r.t("Failed to load Stripe")):s("div",{class:"stripe-link-authentication-wrap"},s("div",{class:"stripe-link-authentication-container"},s("div",{id:"link-authentication-element"}),s("div",{id:"link-authentication-errors",class:"stripe-element-errors"},i)))}get el(){return this}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}}static get style(){return':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-link-authentication-wrap{box-sizing:border-box}.stripe-link-authentication-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-link-authentication-wrap button{cursor:pointer}.stripe-link-authentication-wrap{display:block;width:100%;background:#fff;padding:16px}.stripe-link-authentication-wrap .stripe-link-authentication-container #link-authentication-element .StripeElement{padding:8px 16px;min-height:64px;border-radius:6px;display:flex;justify-content:center;align-items:center}.stripe-link-authentication-wrap .stripe-link-authentication-container #link-authentication-element .StripeElement>.__PrivateStripeElement{width:100%}.stripe-link-authentication-wrap .stripe-link-authentication-container .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}'}},[0,"stripe-link-authentication-element",{publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],defaultEmail:[1,"default-email"],handleChange:[1040],stripeDidLoaded:[1040],progress:[32],initStripe:[64],updateProgress:[64],setErrorMessage:[64],getEmail:[64]},void 0,{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}]}]);function l(){"undefined"!=typeof customElements&&["stripe-link-authentication-element"].forEach((i=>{"stripe-link-authentication-element"===i&&(customElements.get(t(i))||customElements.define(t(i),c))}))}l();const h=c,p=l;export{h as StripeLinkAuthenticationElement,p as defineCustomElement}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as e,proxyCustomElement as o,HTMLElement as a,createEvent as t,h as i,Host as n}from"@stencil/core/internal/client";import{c}from"./utils.js";import{d as l}from"./icon.js";const d=o(class extends a{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.close=t(this,"close",7),this.showCloseButton=!0,this.open=!1,this.renderedOpen=!1}onOpenChange(e){e?this.openModalAnimation():(this.renderedOpen=!1,this.close.emit())}async toggleModal(){this.open?await this.closeModal():await this.openModal()}async openModal(){this.open=!0}async closeModal(){this.open=!1}componentDidLoad(){const e=c();e&&this.el.classList.add(e),this.open&&this.openModalAnimation()}openModalAnimation(){if(!this.el.shadowRoot)return void(this.renderedOpen=!0);const e=this.el.shadowRoot.querySelector(".modal-child");e.classList.add("loading"),e.style.willChange="transform",e.addEventListener("transitionend",(()=>{e.style.willChange="auto",e.classList.remove("loading")}),{once:!0}),requestAnimationFrame((()=>{this.renderedOpen=this.open}))}render(){const{renderedOpen:e,showCloseButton:o}=this;return i(n,{key:"38fb86acf7cf5887a426c67b1a1271f7fae7048c"},i("div",{key:"f751d92c327ee2e564edfcd4d18f4dca43c20c37",class:"modal-row"+(e?" open":""),onClick:()=>this.closeModal()},i("div",{key:"11519ccd44a5069df3247c530a2c1e114eab7aef",class:"modal-child",onClick:e=>e.stopPropagation()},o?i("div",{class:"modal-close-button-wrap"},i("ion-icon",{name:"close",size:"large",class:"modal-close-button",onClick:()=>this.closeModal()})):null,i("div",{key:"a41f7f263b488b5bbc2a999cbabf6b9e407bca85",class:"modal-loading"},i("svg",{key:"0b3b25cb2812bc4d837fb4b7e6af4a5f42f0247e",version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 2400 2400"},i("g",{key:"10a9f9ec59699e6d2988b9c65cd02da1754fd760","stroke-width":"200","stroke-linecap":"round",stroke:"currentColor",fill:"none",id:"spinner"},i("line",{key:"ed271fa584b930ceed5397c271b31e0d48c72f72",x1:"1200",y1:"600",x2:"1200",y2:"100"}),i("line",{key:"3cf855a84f3ab58b914b7aeb784fbc5b95d8ae94",opacity:"0.5",x1:"1200",y1:"2300",x2:"1200",y2:"1800"}),i("line",{key:"2cce4b62a276399235509e94f47a63acf9c69a0f",opacity:"0.917",x1:"900",y1:"680.4",x2:"650",y2:"247.4"}),i("line",{key:"64c175ef068591417b043f7630a44d34eae7cb59",opacity:"0.417",x1:"1750",y1:"2152.6",x2:"1500",y2:"1719.6"}),i("line",{key:"0856a654e3aa756dfb1e9fc316b8b379fa9d5a4e",opacity:"0.833",x1:"680.4",y1:"900",x2:"247.4",y2:"650"}),i("line",{key:"c60f1f8495df9b8cdcc8941255d08c01a0e1c02f",opacity:"0.333",x1:"2152.6",y1:"1750",x2:"1719.6",y2:"1500"}),i("line",{key:"204bc2a7765e43b86f91c3fb9b1e72a3a39bb323",opacity:"0.75",x1:"600",y1:"1200",x2:"100",y2:"1200"}),i("line",{key:"7584b272f9efd7f746c1bcc5c8a5576098b02381",opacity:"0.25",x1:"2300",y1:"1200",x2:"1800",y2:"1200"}),i("line",{key:"7a053e9eb5f0da3fbf6fb7c9680bf73073bb126d",opacity:"0.667",x1:"680.4",y1:"1500",x2:"247.4",y2:"1750"}),i("line",{key:"f8b817095143d739589e45c99b03c7afbdfc8293",opacity:"0.167",x1:"2152.6",y1:"650",x2:"1719.6",y2:"900"}),i("line",{key:"aae0e36dbdfff44196f9758c8a5ed2337139ebe0",opacity:"0.583",x1:"900",y1:"1719.6",x2:"650",y2:"2152.6"}),i("line",{key:"3a257b30cb289f29ba386ccca7519bcdc22c3786",opacity:"0.083",x1:"1750",y1:"247.4",x2:"1500",y2:"680.4"}),i("animateTransform",{key:"c6b8e73025589403dd3d08f84b02eb824763d056",attributeName:"transform",attributeType:"XML",type:"rotate",keyTimes:"0;0.08333;0.16667;0.25;0.33333;0.41667;0.5;0.58333;0.66667;0.75;0.83333;0.91667",values:"0 1199 1199;30 1199 1199;60 1199 1199;90 1199 1199;120 1199 1199;150 1199 1199;180 1199 1199;210 1199 1199;240 1199 1199;270 1199 1199;300 1199 1199;330 1199 1199",dur:"0.83333s",begin:"0s",repeatCount:"indefinite",calcMode:"discrete"})))),i("div",{key:"da5ef8031e5b826d854a065d8172389cdd84fbf0",class:"modal-content"},i("slot",{key:"fbe97a3a4d5489de5ae6f49342c58d537b317842"})))))}get el(){return this}static get watchers(){return{open:[{onOpenChange:0}]}}static get style(){return':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}:host{box-sizing:border-box}:host *: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}:host button{cursor:pointer}:host{display:block}.modal-row{opacity:0;pointer-events:none;will-change:transform}.modal-row.open{opacity:1;pointer-events:auto;position:fixed;top:0;left:0;width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:1ch;background:rgba(0, 0, 0, 0.3)}.modal-row .modal-child{transform:translateY(100%);transition:transform 420ms ease;position:relative}.modal-row .modal-child .modal-loading{display:none;position:absolute;top:160px;left:50%;transform:translateX(-50%);width:24px;height:24px}.modal-row .modal-child.loading .modal-loading{display:flex;justify-content:center;align-items:center}.modal-row .modal-child.loading .modal-loading svg{width:24px;height:24px}.modal-row .modal-child.loading .modal-content{visibility:hidden}.modal-row.open .modal-child{transform:translateY(0%)}.modal-child{padding:16px 8px 24px;background-color:#fff;width:100%}.modal-close-button-wrap{padding-left:8px}.modal-close-button-wrap .modal-close-button{width:32px;display:block;fill:var(--color-label);cursor:pointer}'}},[257,"stripe-modal",{showCloseButton:[4,"show-close-button"],open:[1028],renderedOpen:[32],toggleModal:[64],openModal:[64],closeModal:[64]},void 0,{open:[{onOpenChange:0}]}]);function s(){"undefined"!=typeof customElements&&["stripe-modal","ion-icon"].forEach((o=>{switch(o){case"stripe-modal":customElements.get(e(o))||customElements.define(e(o),d);break;case"ion-icon":customElements.get(e(o))||l()}}))}s();export{d as S,s as d}
|
|
1
|
+
import{transformTag as o,proxyCustomElement as t,HTMLElement as e,createEvent as i,h as n,Host as a}from"@stencil/core/internal/client";import{c as s,i as d}from"./i18n.js";import{d as l}from"./icon.js";const r=["a[href]","area[href]","button:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])","textarea:not([disabled])","iframe","audio[controls]","video[controls]","summary",'[contenteditable]:not([contenteditable="false"])',"[tabindex]"].join(","),c=o=>{if(!o.matches(r))return!1;const t=o.getAttribute("tabindex");if(null!==t&&Number(t)<0)return!1;if(o.hasAttribute("hidden")||null!==o.closest("[inert]"))return!1;const{checkVisibility:e}=o;return!("function"==typeof e&&!e.call(o,{visibilityProperty:!0}))},h=o=>{const t=[],e=o=>{for(const i of(o=>{if(o instanceof Element&&"SLOT"===o.tagName){const t=o,e="function"==typeof t.assignedElements?t.assignedElements({flatten:!0}):[];return e.length>0?e:Array.from(t.children)}return o instanceof Element&&null!=o.shadowRoot?Array.from(o.shadowRoot.children):Array.from(o.children)})(o))c(i)&&t.push(i),e(i)};return e(o),t},u=(o=document)=>{var t,e;let i=null!==(t=o.activeElement)&&void 0!==t?t:null;for(;null!=(null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.activeElement);)i=i.shadowRoot.activeElement;return i},b=t(class extends e{constructor(o){super(),!1!==o&&this.__registerHost(),this.__attachShadow(),this.close=i(this,"close",7),this.showCloseButton=!0,this.open=!1,this.renderedOpen=!1,this.returnFocusElement=null,this.shouldFocusOnRender=!1,this.lastFocusedInside=null,this.handleKeyDown=o=>{this.open&&"Escape"===o.key&&(o.isComposing||229===o.keyCode||o.defaultPrevented||(o.preventDefault(),o.stopPropagation(),this.closeModal()))},this.handleFocusIn=o=>{var t,e;const i=null!==(e=null===(t=o.composedPath)||void 0===t?void 0:t.call(o)[0])&&void 0!==e?e:o.target;void 0===(null==i?void 0:i.classList)||i.classList.contains("focus-guard")||(this.lastFocusedInside=i)},this.handleStartGuardFocus=o=>{this.cameFromFocusableInside(o)?this.focusLastElement():this.focusFirstElement()},this.handleEndGuardFocus=o=>{this.isInsideModal(this.getFocusOrigin(o))?this.focusFirstElement():this.focusLastElement()}}onOpenChange(o){o?(this.rememberFocus(),this.openModalAnimation()):(this.renderedOpen=!1,this.shouldFocusOnRender=!1,this.lastFocusedInside=null,this.close.emit(),this.restoreFocus())}async toggleModal(){this.open?await this.closeModal():await this.openModal()}async openModal(){this.open=!0}async closeModal(){this.open=!1}componentDidLoad(){const o=s();o&&this.el.classList.add(o),this.open&&(this.rememberFocus(),this.openModalAnimation())}componentDidRender(){this.shouldFocusOnRender&&this.renderedOpen&&(this.shouldFocusOnRender=!1,this.focusFirstElement())}rememberFocus(){var o;if("undefined"==typeof document)return;const t=u(document);null===t||t===document.body||this.el.contains(t)||!0===(null===(o=this.el.shadowRoot)||void 0===o?void 0:o.contains(t))||(this.returnFocusElement=t)}restoreFocus(){const o=this.returnFocusElement;this.returnFocusElement=null,null!=o&&o.isConnected&&"function"==typeof o.focus&&o.focus()}getTabbableElements(){return void 0===this.dialogElement?[]:h(this.dialogElement).filter((o=>!o.classList.contains("focus-guard")))}isInsideModal(o){var t;return null!==o&&(this.el.contains(o)||!0===(null===(t=this.dialogElement)||void 0===t?void 0:t.contains(o)))}getFocusOrigin(o){var t;return null!==(t=o.relatedTarget)&&void 0!==t?t:this.lastFocusedInside}cameFromFocusableInside(o){const t=this.getFocusOrigin(o);return t!==this.dialogElement&&this.isInsideModal(t)}focusContentAfterLoading(){var o;if(!this.open||void 0===this.contentElement)return;const t=u(document);(null===t||t===document.body||t===this.dialogElement||t===this.closeButtonElement)&&(null===(o=h(this.contentElement)[0])||void 0===o||o.focus())}focusFirstElement(){var o;const[t]=this.getTabbableElements();null===(o=null!=t?t:this.dialogElement)||void 0===o||o.focus()}focusLastElement(){var o,t;const e=this.getTabbableElements();null===(t=null!==(o=e[e.length-1])&&void 0!==o?o:this.dialogElement)||void 0===t||t.focus()}openModalAnimation(){if(this.shouldFocusOnRender=!0,!this.el.shadowRoot)return void(this.renderedOpen=!0);const o=this.el.shadowRoot.querySelector(".modal-child");o.scrollTop=0,o.classList.add("loading"),o.style.willChange="transform",o.addEventListener("transitionend",(()=>{o.style.willChange="auto",o.classList.remove("loading"),this.focusContentAfterLoading()}),{once:!0}),requestAnimationFrame((()=>{this.renderedOpen=this.open}))}render(){const{renderedOpen:o,showCloseButton:t}=this,e=o?0:-1;return n(a,{key:"55e0d63b18df165313ea3dd8b8f17aa0e0d0a253",role:o?"dialog":void 0,"aria-modal":o?"true":void 0,onKeyDown:this.handleKeyDown,onFocusin:this.handleFocusIn},n("div",{key:"adb0b493c0ae525f275025c03e1b8f02b04de1af",class:"modal-row"+(o?" open":""),onClick:()=>this.closeModal()},n("div",{key:"478bdad2ad481bfc2d8ffcf552788292fa93daed",class:"modal-child",tabindex:"-1",ref:o=>this.dialogElement=o,onClick:o=>o.stopPropagation()},n("div",{key:"8cc68ecefa37ec1db65f6c910d1da40f9144e722",class:"focus-guard",tabindex:e,onFocus:this.handleStartGuardFocus}),t?n("div",{class:"modal-close-button-wrap"},n("button",{type:"button",class:"modal-close-button","aria-label":d.t("Close"),ref:o=>this.closeButtonElement=o,onClick:()=>this.closeModal()},n("ion-icon",{name:"close",size:"large","aria-hidden":"true"}))):null,n("div",{key:"26271a75906a72e9944599f98da007bfebc2e348",class:"modal-loading"},n("svg",{key:"bc6b1267e2f3b6b1dd7209db55be717fddf9acd4",version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 2400 2400"},n("g",{key:"00ed54798ac376ed71f87a088fad2519cb1262dc","stroke-width":"200","stroke-linecap":"round",stroke:"currentColor",fill:"none",id:"spinner"},n("line",{key:"98242d65eb9470430bd5cc656cbb479232782746",x1:"1200",y1:"600",x2:"1200",y2:"100"}),n("line",{key:"2e2f0538a6d048465ef5f8a3d5ed1932f6c59270",opacity:"0.5",x1:"1200",y1:"2300",x2:"1200",y2:"1800"}),n("line",{key:"11f850b0e7dc0d259f35f56aab17068d4d25ca95",opacity:"0.917",x1:"900",y1:"680.4",x2:"650",y2:"247.4"}),n("line",{key:"14c3226b5d2741902f428a208966adf016c1bb7e",opacity:"0.417",x1:"1750",y1:"2152.6",x2:"1500",y2:"1719.6"}),n("line",{key:"d41da322484b62c1db1df72b9bd1bcc0dbb85a2c",opacity:"0.833",x1:"680.4",y1:"900",x2:"247.4",y2:"650"}),n("line",{key:"246dcdd4a011775dc8fea8a05cfcfc429d5bd03c",opacity:"0.333",x1:"2152.6",y1:"1750",x2:"1719.6",y2:"1500"}),n("line",{key:"f0a2d217a33a8caa6995a30d840002cb8c076e8d",opacity:"0.75",x1:"600",y1:"1200",x2:"100",y2:"1200"}),n("line",{key:"7552fb2c04f85c54b8bcc2235a32690e4489177f",opacity:"0.25",x1:"2300",y1:"1200",x2:"1800",y2:"1200"}),n("line",{key:"7b5a62164a0ef759b057f9100c7c5af834c9f6b7",opacity:"0.667",x1:"680.4",y1:"1500",x2:"247.4",y2:"1750"}),n("line",{key:"d36af9d23059da4ca91147084e47ba94e19f5ada",opacity:"0.167",x1:"2152.6",y1:"650",x2:"1719.6",y2:"900"}),n("line",{key:"f8eed2a97d817b68e0b29f5b5037d34d46a79a46",opacity:"0.583",x1:"900",y1:"1719.6",x2:"650",y2:"2152.6"}),n("line",{key:"1641d577b703e213157bc553966e434a40ba7158",opacity:"0.083",x1:"1750",y1:"247.4",x2:"1500",y2:"680.4"}),n("animateTransform",{key:"60fb2d30c248db1b4195d6015dc96225a15e4010",attributeName:"transform",attributeType:"XML",type:"rotate",keyTimes:"0;0.08333;0.16667;0.25;0.33333;0.41667;0.5;0.58333;0.66667;0.75;0.83333;0.91667",values:"0 1199 1199;30 1199 1199;60 1199 1199;90 1199 1199;120 1199 1199;150 1199 1199;180 1199 1199;210 1199 1199;240 1199 1199;270 1199 1199;300 1199 1199;330 1199 1199",dur:"0.83333s",begin:"0s",repeatCount:"indefinite",calcMode:"discrete"})))),n("div",{key:"27d3b71da43e5935dff3eff2e1bc507a24261b70",class:"modal-content",ref:o=>this.contentElement=o},n("slot",{key:"641408238d3969b830d1f3e9398be6f05bc1f65b"})),n("div",{key:"c6178542b98a99d6a50b74270adc273671d5cc19",class:"focus-guard",tabindex:e,onFocus:this.handleEndGuardFocus}))))}get el(){return this}static get watchers(){return{open:[{onOpenChange:0}]}}static get style(){return':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}:host{box-sizing:border-box}:host *: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}:host button{cursor:pointer}:host{display:block}.modal-row{opacity:0;pointer-events:none;will-change:transform;visibility:hidden}.modal-row.open{opacity:1;pointer-events:auto;visibility:visible;position:fixed;top:0;left:0;width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:1ch;background:rgba(0, 0, 0, 0.3)}.modal-row .modal-child{transform:translateY(100%);transition:transform 420ms ease;position:relative}.modal-row .modal-child .modal-loading{display:none;position:absolute;top:160px;left:50%;transform:translateX(-50%);width:24px;height:24px}.modal-row .modal-child.loading .modal-loading{display:flex;justify-content:center;align-items:center}.modal-row .modal-child.loading .modal-loading svg{width:24px;height:24px}.modal-row .modal-child.loading .modal-content{visibility:hidden}.modal-row.open .modal-child{transform:translateY(0%)}.modal-child{padding:16px 8px 24px;background-color:#fff;width:100%;max-height:100vh;max-height:100dvh;overflow-y:auto;overscroll-behavior:contain}.modal-close-button-wrap{padding-left:8px}.modal-close-button-wrap .modal-close-button{display:block;width:32px;cursor:pointer;border-radius:4px}.modal-close-button-wrap .modal-close-button:focus-visible{outline:2px solid var(--color-label, #000);outline-offset:2px}.modal-close-button-wrap .modal-close-button ion-icon{width:32px;display:block;fill:var(--color-label)}.modal-child:focus{outline:none}.focus-guard{position:absolute;width:1px;height:1px;overflow:hidden}'}},[257,"stripe-modal",{showCloseButton:[4,"show-close-button"],open:[1028],renderedOpen:[32],toggleModal:[64],openModal:[64],closeModal:[64]},void 0,{open:[{onOpenChange:0}]}]);function f(){"undefined"!=typeof customElements&&["stripe-modal","ion-icon"].forEach((t=>{switch(t){case"stripe-modal":customElements.get(o(t))||customElements.define(o(t),b);break;case"ion-icon":customElements.get(o(t))||l()}}))}f();export{b as S,f as d}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{S as e}from"./error.js";const r=e=>{const{progress:r,isCheckoutSession:t,loadStripeStatus:i,intentClientSecret:n}=e;return"loading"===r||!(t?"success"===i:null!=n&&""!==n)},t=async(r,t,i,n,o)=>{const s=await("payment"===i?r.confirmPayment({elements:t,confirmParams:Object.assign({return_url:n},o),redirect:"if_required"}):r.confirmSetup({elements:t,confirmParams:Object.assign({return_url:n},o),redirect:"if_required"}));if(s.error)throw new e(s.error);return s},i=async(r,t)=>{var i;const n=await r.loadActions();if("error"===n.type)throw new e({type:"api_error",code:n.error.code||"checkout_session_error",message:n.error.message});const{actions:o}=n,s=await o.confirm({returnUrl:t,redirect:"if_required"});if("error"===s.type){const r={type:"card_error",code:s.error.code||"payment_failed",message:s.error.message,decline_code:"paymentFailed"===s.error.code?null===(i=s.error.paymentFailed)||void 0===i?void 0:i.declineCode:void 0};throw new e(r)}return s},n=e=>{const{stripe:r,isCheckoutSession:t,checkout:i,checkoutSessionClientSecret:n,elements:o,intentClientSecret:s}=e,c={stripe:r};return t?null==i?{error:"Checkout not properly initialized"}:(c.checkout=i,c.checkoutSessionClientSecret=n,{props:c}):null==o?{error:"Elements not properly initialized"}:(c.elements=o,c.intentClientSecret=s,{props:c})};export{i as a,n as b,t as c,r as i}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as t,proxyCustomElement as e,HTMLElement as i,createEvent as s,h as n}from"@stencil/core/internal/client";import{c as r}from"./utils.js";import{s as o,i as a}from"./factory.js";import{S as c}from"./error.js";const l=t=>{const{stripe:e,isCheckoutSession:i,checkout:s,checkoutSessionClientSecret:n,elements:r,intentClientSecret:o}=t,a={stripe:e};return i?null==s?{error:"Checkout not properly initialized"}:(a.checkout=s,a.checkoutSessionClientSecret=n,{props:a}):null==r?{error:"Elements not properly initialized"}:(a.elements=r,a.intentClientSecret=o,{props:a})},h=e(class extends i{async initStripe(t,e){const i=++this.initGeneration;await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName,clientSecret:this.intentClientSecret}),await this.mountWhenLoaded(i)}async initStripeWithCheckoutSession(t,e,i){const s=++this.initGeneration;await this.stripeService.initializeWithCheckoutSession(t,e,{stripeAccount:null==i?void 0:i.stripeAccount,applicationName:this.applicationName,elementsOptions:null==i?void 0:i.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 e={};e.stripeAccount=this.stripeService.state.stripeAccount;const i=Object.values(e).filter((t=>null!=t&&""!==t)).length>0;this.hasCheckoutSessionClientSecret()?this.initStripeWithCheckoutSession(t,this.checkoutSessionClientSecret,{stripeAccount:e.stripeAccount}):this.initStripe(t,i?e: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:e}=this.stripeService.state;null!=t&&""!==t&&await this.initStripe(t,{stripeAccount:e})}async updateCheckoutSessionClientSecret(t){null!=this.publishableKey&&""!==this.publishableKey&&null!=t&&""!==t&&await this.initStripeWithCheckoutSession(this.publishableKey,t,{stripeAccount:this.stripeAccount})}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async formSubmitEventHandler(){const t=this.stripeService.getStripe(),e=!0===this.stripeService.state.isCheckoutSession;if(null==t)return void console.error("Stripe not properly initialized");const i=l({stripe:t,isCheckoutSession:e,checkout:this.stripeService.getCheckout(),checkoutSessionClientSecret:this.checkoutSessionClientSecret,elements:this.stripeService.getElements(),intentClientSecret:this.intentClientSecret});"error"in i?console.error(i.error):this.formSubmit.emit(i.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:e,elements:i}){t.preventDefault();try{const t=window.location.href,s=await(async(t,e,i,s)=>{const n=await("payment"===i?t.confirmPayment({elements:e,confirmParams:{return_url:s},redirect:"if_required"}):t.confirmSetup({elements:e,confirmParams:{return_url:s},redirect:"if_required"}));if(n.error)throw new c(n.error);return n})(e,i,this.intentType,t);this.defaultFormSubmitResultHandler(s)}catch(t){throw console.error(t),this.defaultFormSubmitResultHandler(t),t}}async checkoutSessionFormSubmitAction(t,e){t.preventDefault();try{const t=window.location.href,i=await(async(t,e)=>{var i;const s=await t.loadActions();if("error"===s.type)throw new c({type:"api_error",code:s.error.code||"checkout_session_error",message:s.error.message});const{actions:n}=s,r=await n.confirm({returnUrl:e,redirect:"if_required"});if("error"===r.type){const t={type:"card_error",code:r.error.code||"payment_failed",message:r.error.message,decline_code:"paymentFailed"===r.error.code?null===(i=r.error.paymentFailed)||void 0===i?void 0:i.declineCode:void 0};throw new c(t)}return r})(e,t);this.checkoutSessionConfirmResultHandler(i)}catch(t){throw console.error(t),this.checkoutSessionConfirmResultHandler(t instanceof Error?t:Error(t+"")),t}}constructor(t){super(),!1!==t&&this.__registerHost(),this.stripeLoaded=s(this,"stripeLoaded",7),this.formSubmit=s(this,"formSubmit",7),this.defaultFormSubmitResult=s(this,"defaultFormSubmitResult",7),this.checkoutSessionConfirmResult=s(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 e=this.stripeService.onChange("loadStripeStatus",(async i=>{t===this.initGeneration?"success"===i&&(await this.initElement(),t===this.initGeneration?(this.stripeLoadedEventHandler(),e()):e()):e()}))}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 e=this.stripeService.getStripe(),i=!0===this.stripeService.state.isCheckoutSession;if(null==e)return void console.error("Stripe not properly initialized");const s=l({stripe:e,isCheckoutSession:i,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?i&&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){this.paymentElementManager.setError(t instanceof Error?t.message:t+""),this.progress="failure"}},t.addEventListener("submit",this._submitHandler)):console.error("Form element #stripe-payment-element not found")}componentDidLoad(){this.el.classList.add(r())}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:e}=this.stripeService.state,{errorMessage:i}=this.paymentElementManager.getState();if("failure"===t)return n("p",null,a.t("Failed to load Stripe"));const s=(t=>{const{progress:e,isCheckoutSession:i,loadStripeStatus:s,intentClientSecret:n}=t;return"loading"===e||!(i?"success"===s:null!=n&&""!==n)})({progress:this.progress,isCheckoutSession:!0===e,loadStripeStatus:t,intentClientSecret:this.intentClientSecret});return n("div",{class:"stripe-payment-sheet-wrap"},n("form",{id:"stripe-payment-element"},n("div",{class:"stripe-heading"},a.t(this.sheetTitle)),n("div",null,n("div",{class:"stripe-section-title"},a.t("Payment information"))),n("div",{class:"payment-info visible"},n("div",{id:"payment-element"})),n("div",{id:"payment-errors",class:"stripe-element-errors"},i),n("div",{style:{marginTop:"32px"}},n("button",{type:"submit",disabled:s},a.t("loading"===this.progress?"Loading":this.buttonLabel)))))}get el(){return this}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}],intentClientSecret:[{updateIntentClientSecret:0}],checkoutSessionClientSecret:[{updateCheckoutSessionClientSecret:0}]}}static get style(){return':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)}'}},[0,"stripe-payment-element",{intentType:[1,"intent-type"],sheetTitle:[1,"sheet-title"],buttonLabel:[1,"button-label"],publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],intentClientSecret:[1,"intent-client-secret"],checkoutSessionClientSecret:[1,"checkout-session-client-secret"],shouldUseDefaultFormSubmitAction:[4,"should-use-default-form-submit-action"],handleSubmit:[1040],stripeDidLoaded:[1040],progress:[32],initStripe:[64],initStripeWithCheckoutSession:[64],updateProgress:[64],setErrorMessage:[64]},void 0,{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}],intentClientSecret:[{updateIntentClientSecret:0}],checkoutSessionClientSecret:[{updateCheckoutSessionClientSecret:0}]}]);function p(){"undefined"!=typeof customElements&&["stripe-payment-element"].forEach((e=>{"stripe-payment-element"===e&&(customElements.get(t(e))||customElements.define(t(e),h))}))}p();const u=h,d=p;export{u as StripePaymentElement,d as defineCustomElement}
|
|
1
|
+
import{transformTag as t,proxyCustomElement as e,HTMLElement as i,createEvent as s,h as n}from"@stencil/core/internal/client";import{c as o,i as r}from"./i18n.js";import{s as a}from"./factory.js";import{b as l,c,a as h,i as p}from"./stripe-payment-element.helpers.js";const u=e(class extends i{async initStripe(t,e){const i=++this.initGeneration;await this.stripeService.initialize(t,{stripeAccount:null==e?void 0:e.stripeAccount,applicationName:this.applicationName,clientSecret:this.intentClientSecret}),await this.mountWhenLoaded(i)}async initStripeWithCheckoutSession(t,e,i){const s=++this.initGeneration;await this.stripeService.initializeWithCheckoutSession(t,e,{stripeAccount:null==i?void 0:i.stripeAccount,applicationName:this.applicationName,elementsOptions:null==i?void 0:i.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 e={};e.stripeAccount=this.stripeService.state.stripeAccount;const i=Object.values(e).filter((t=>null!=t&&""!==t)).length>0;this.hasCheckoutSessionClientSecret()?this.initStripeWithCheckoutSession(t,this.checkoutSessionClientSecret,{stripeAccount:e.stripeAccount}):this.initStripe(t,i?e: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:e}=this.stripeService.state;null!=t&&""!==t&&await this.initStripe(t,{stripeAccount:e})}async updateCheckoutSessionClientSecret(t){null!=this.publishableKey&&""!==this.publishableKey&&null!=t&&""!==t&&await this.initStripeWithCheckoutSession(this.publishableKey,t,{stripeAccount:this.stripeAccount})}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async formSubmitEventHandler(){const t=this.stripeService.getStripe(),e=!0===this.stripeService.state.isCheckoutSession;if(null==t)return void console.error("Stripe not properly initialized");const i=l({stripe:t,isCheckoutSession:e,checkout:this.stripeService.getCheckout(),checkoutSessionClientSecret:this.checkoutSessionClientSecret,elements:this.stripeService.getElements(),intentClientSecret:this.intentClientSecret});"error"in i?console.error(i.error):this.formSubmit.emit(i.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:e,elements:i}){t.preventDefault();try{const t=window.location.href,s=await c(e,i,this.intentType,t);this.defaultFormSubmitResultHandler(s)}catch(t){throw console.error(t),this.defaultFormSubmitResultHandler(t),t}}async checkoutSessionFormSubmitAction(t,e){t.preventDefault();try{const t=window.location.href,i=await h(e,t);this.checkoutSessionConfirmResultHandler(i)}catch(t){throw console.error(t),this.checkoutSessionConfirmResultHandler(t instanceof Error?t:Error(t+"")),t}}constructor(t){super(),!1!==t&&this.__registerHost(),this.stripeLoaded=s(this,"stripeLoaded",7),this.formSubmit=s(this,"formSubmit",7),this.defaultFormSubmitResult=s(this,"defaultFormSubmitResult",7),this.checkoutSessionConfirmResult=s(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=a.createStripeService(),this.paymentElementManager=a.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 e=this.stripeService.onChange("loadStripeStatus",(async i=>{t===this.initGeneration?"success"===i&&(await this.initElement(),t===this.initGeneration?(this.stripeLoadedEventHandler(),e()):e()):e()}))}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 e=this.stripeService.getStripe(),i=!0===this.stripeService.state.isCheckoutSession;if(null==e)return void console.error("Stripe not properly initialized");const s=l({stripe:e,isCheckoutSession:i,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?i&&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){this.paymentElementManager.setError(t instanceof Error?t.message:t+""),this.progress="failure"}},t.addEventListener("submit",this._submitHandler)):console.error("Form element #stripe-payment-element not found")}componentDidLoad(){this.el.classList.add(o())}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:e}=this.stripeService.state,{errorMessage:i}=this.paymentElementManager.getState();if("failure"===t)return n("p",null,r.t("Failed to load Stripe"));const s=p({progress:this.progress,isCheckoutSession:!0===e,loadStripeStatus:t,intentClientSecret:this.intentClientSecret});return n("div",{class:"stripe-payment-sheet-wrap"},n("form",{id:"stripe-payment-element"},n("div",{class:"stripe-heading"},r.t(this.sheetTitle)),n("div",null,n("div",{class:"stripe-section-title"},r.t("Payment information"))),n("div",{class:"payment-info visible"},n("div",{id:"payment-element"})),n("div",{id:"payment-errors",class:"stripe-element-errors"},i),n("div",{style:{marginTop:"32px"}},n("button",{type:"submit",disabled:s},r.t("loading"===this.progress?"Loading":this.buttonLabel)))))}get el(){return this}static get watchers(){return{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}],intentClientSecret:[{updateIntentClientSecret:0}],checkoutSessionClientSecret:[{updateCheckoutSessionClientSecret:0}]}}static get style(){return':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)}'}},[0,"stripe-payment-element",{intentType:[1,"intent-type"],sheetTitle:[1,"sheet-title"],buttonLabel:[1,"button-label"],publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],intentClientSecret:[1,"intent-client-secret"],checkoutSessionClientSecret:[1,"checkout-session-client-secret"],shouldUseDefaultFormSubmitAction:[4,"should-use-default-form-submit-action"],handleSubmit:[1040],stripeDidLoaded:[1040],progress:[32],initStripe:[64],initStripeWithCheckoutSession:[64],updateProgress:[64],setErrorMessage:[64]},void 0,{publishableKey:[{updatePublishableKey:0}],stripeAccount:[{updateStripeAccountId:0}],intentClientSecret:[{updateIntentClientSecret:0}],checkoutSessionClientSecret:[{updateCheckoutSessionClientSecret:0}]}]);function d(){"undefined"!=typeof customElements&&["stripe-payment-element"].forEach((e=>{"stripe-payment-element"===e&&(customElements.get(t(e))||customElements.define(t(e),u))}))}d();const m=u,b=d;export{m as StripePaymentElement,b as defineCustomElement}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transformTag as e,proxyCustomElement as t,HTMLElement as s,createEvent as i,h as n,Host as a}from"@stencil/core/internal/client";import{l as o}from"./index2.js";const r=t(class extends s{constructor(e){super(),!1!==e&&this.__registerHost(),this.stripeLoaded=i(this,"stripeLoaded",7),this.loadStripeStatus="",this.applicationName="stripe-pwa-elements"}async isAvailable(e){if(void 0===this.publishableKey)throw new Error("You should set publishableKey before calling this method.");const t=(await o(this.publishableKey,{stripeAccount:this.stripeAccount})).paymentRequest({country:"US",currency:"usd",total:{label:"Demo total",amount:1099},disableWallets:["applePay","googlePay","browserCard"].filter((t=>t!==e))}),s=await t.canMakePayment();if(!s||"applePay"===e&&!s[e]||"googlePay"===e&&!s[e])throw new Error(`This device cannot use ${e}.`)}async setPaymentMethodEventHandler(e){this.paymentMethodEventHandler=e}async setPaymentRequestShippingOptionEventHandler(e){this.shippingOptionEventHandler=e}async setPaymentRequestShippingAddressEventHandler(e){this.shippingAddressEventHandler=e}stripeLoadedEventHandler(){const e={stripe:this.stripe};this.stripeDidLoaded&&this.stripeDidLoaded(e),this.stripeLoaded.emit(e)}componentWillLoad(){void 0!==this.publishableKey&&void 0!==this.paymentRequestOption?this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount}):this.loadStripeStatus="failure"}connectedCallback(){console.warn("[stripe-pwa-elements] <stripe-payment-request-button> is deprecated. stripe.paymentRequest() is being removed in Stripe.js 9.x (deprecated 2025-09-30 / removed 2026-03-25). Please migrate to <stripe-express-checkout-element>, which supports Apple Pay, Google Pay, Link, PayPal, and more. Migration guide: https://
|
|
1
|
+
import{transformTag as e,proxyCustomElement as t,HTMLElement as s,createEvent as i,h as n,Host as a}from"@stencil/core/internal/client";import{l as o}from"./index2.js";const r=t(class extends s{constructor(e){super(),!1!==e&&this.__registerHost(),this.stripeLoaded=i(this,"stripeLoaded",7),this.loadStripeStatus="",this.applicationName="stripe-pwa-elements"}async isAvailable(e){if(void 0===this.publishableKey)throw new Error("You should set publishableKey before calling this method.");const t=(await o(this.publishableKey,{stripeAccount:this.stripeAccount})).paymentRequest({country:"US",currency:"usd",total:{label:"Demo total",amount:1099},disableWallets:["applePay","googlePay","browserCard"].filter((t=>t!==e))}),s=await t.canMakePayment();if(!s||"applePay"===e&&!s[e]||"googlePay"===e&&!s[e])throw new Error(`This device cannot use ${e}.`)}async setPaymentMethodEventHandler(e){this.paymentMethodEventHandler=e}async setPaymentRequestShippingOptionEventHandler(e){this.shippingOptionEventHandler=e}async setPaymentRequestShippingAddressEventHandler(e){this.shippingAddressEventHandler=e}stripeLoadedEventHandler(){const e={stripe:this.stripe};this.stripeDidLoaded&&this.stripeDidLoaded(e),this.stripeLoaded.emit(e)}componentWillLoad(){void 0!==this.publishableKey&&void 0!==this.paymentRequestOption?this.initStripe(this.publishableKey,{stripeAccount:this.stripeAccount}):this.loadStripeStatus="failure"}connectedCallback(){console.warn("[stripe-pwa-elements] <stripe-payment-request-button> is deprecated. stripe.paymentRequest() is being removed in Stripe.js 9.x (deprecated 2025-09-30 / removed 2026-03-25). Please migrate to <stripe-express-checkout-element>, which supports Apple Pay, Google Pay, Link, PayPal, and more. Migration guide: https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/guides/migrate-payment-request-button-to-express-checkout/")}async setPaymentRequestOption(e){return this.paymentRequestOption=e,this}async initStripe(e,t){this.loadStripeStatus="loading",o(e,{stripeAccount:null==t?void 0:t.stripeAccount}).then((e=>{this.loadStripeStatus="success",e.registerAppInfo({name:this.applicationName}),this.stripe=e})).catch((e=>{console.log(e),this.loadStripeStatus="failure"})).then((()=>{if(this.stripe)return this.initElement(0==!(null==t?void 0:t.showButton))})).then((()=>{this.stripe&&this.stripeLoadedEventHandler()}))}async initElement(e=!0){const t=this.stripe.paymentRequest(this.paymentRequestOption);if(!await t.canMakePayment())throw new Error("Payment Request is not supported.");if(this.paymentMethodEventHandler&&t.on("paymentmethod",(e=>{this.paymentMethodEventHandler(e,this.stripe)})),this.shippingOptionEventHandler&&t.on("shippingoptionchange",(e=>{this.shippingOptionEventHandler(e,this.stripe)})),this.shippingAddressEventHandler&&t.on("shippingaddresschange",(e=>{this.shippingAddressEventHandler(e,this.stripe)})),e){this.paymentRequestElement&&this.paymentRequestElement.unmount();const e=this.stripe.elements().create("paymentRequestButton",{paymentRequest:t});this.paymentRequestElement=e;const s=this.el.querySelector("#payment-request-button");e.mount(s),this.el.querySelector("#payment-request").classList.add("visible")}else t.show()}disconnectedCallback(){this.paymentRequestElement&&(this.paymentRequestElement.unmount(),this.paymentRequestElement=void 0),this.stripe=void 0}render(){return n(a,{key:"644a4b729c72e87b42df5e1b43262d3195e7ebc6"},n("div",{key:"aff26789868bbec0f1f6abc463fb14d7f3e73c1b",id:"payment-request"},n("div",{key:"074a25f3c5b2575696ddaeacf2715935212964a5",id:"payment-request-button"})),n("slot",{key:"5173400bd63ab201f02934cea4edcab4bb7eed9c"}))}get el(){return this}static get style(){return":host{display:block}"}},[260,"stripe-payment-request-button",{paymentMethodEventHandler:[16],shippingOptionEventHandler:[16],shippingAddressEventHandler:[16],publishableKey:[1,"publishable-key"],stripeAccount:[1,"stripe-account"],applicationName:[1,"application-name"],stripeDidLoaded:[1040],loadStripeStatus:[32],stripe:[32],paymentRequestOption:[32],isAvailable:[64],setPaymentMethodEventHandler:[64],setPaymentRequestShippingOptionEventHandler:[64],setPaymentRequestShippingAddressEventHandler:[64],setPaymentRequestOption:[64],initStripe:[64]}]);function p(){"undefined"!=typeof customElements&&["stripe-payment-request-button"].forEach((t=>{"stripe-payment-request-button"===t&&(customElements.get(e(t))||customElements.define(e(t),r))}))}p();export{r as S,p as d}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Components, JSX } from "../types/components";
|
|
2
|
+
|
|
3
|
+
interface StripePaymentSheet extends Components.StripePaymentSheet, HTMLElement {}
|
|
4
|
+
export const StripePaymentSheet: {
|
|
5
|
+
prototype: StripePaymentSheet;
|
|
6
|
+
new (): StripePaymentSheet;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Used to define this component and all nested components recursively.
|
|
10
|
+
*/
|
|
11
|
+
export const defineCustomElement: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{transformTag as e,proxyCustomElement as t,HTMLElement as i,createEvent as n,h as s,Host as a}from"@stencil/core/internal/client";import{c as r,i as o}from"./i18n.js";import{s as l,f as c}from"./factory.js";import{c as d}from"./stripe-payment-element.helpers.js";import{S as h}from"./error.js";import{d as p}from"./icon.js";import{d as u}from"./stripe-modal2.js";const m={phase:"idle",generation:0,pendingPresent:!1,openRequested:!1},f=[[/^pi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/,"payment"],[/^seti_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/,"setup"]],y=e=>({state:e,effects:[]}),b=(e,t)=>e.pendingPresent?{state:Object.assign(Object.assign({},e),{pendingPresent:!1}),effects:[{type:"resolvePresent",result:t}]}:y(e),v=e=>{const t=b(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]}},g=(e,t,i)=>{if(""===t)return y(e);if("confirming"===e.phase)return y(Object.assign(Object.assign({},e),{deferredSecret:{clientSecret:t,source:i}}));const n="presented"===e.phase?v(e):y(e),s=e.generation+1,a=((e,t)=>"checkoutSession"===t?"checkoutSession":(e=>{const t=f.find((([t])=>t.test(e)));return null==t?void 0:t[1]})(e))(t,i);if(null==a){const e=b(Object.assign(Object.assign({},n.state),{phase:"loadFailed",generation:s,intentKind:void 0,openRequested:!1}),"paymentSheetFailed");return{state:e.state,effects:[...n.effects,{type:"emit",event:"paymentSheetFailedToLoad"},...e.effects]}}return{state:Object.assign(Object.assign({},n.state),{phase:"loading",generation:s,intentKind:a}),effects:[...n.effects,{type:"load",generation:s,clientSecret:t,intentKind:a}]}},w=e=>{const{deferredSecret:t}=e.state;if(null==t)return e;const i=g(Object.assign(Object.assign({},e.state),{deferredSecret:void 0}),t.clientSecret,t.source);return{state:i.state,effects:[...e.effects,...i.effects]}},S=(e,t)=>"confirming"===e.phase&&e.generation===t;var j=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(i[n[s]]=e[n[s]])}return i};const O=["merchantDisplayName","paymentMethodLayout","defaultBillingDetails","returnURL","style","billingDetailsCollectionConfiguration","shippingDetails","enableApplePay","enableGooglePay"],k={horizontal:"tabs",vertical:"accordion",automatic:"auto"},C={alwaysLight:"stripe",alwaysDark:"night"},x=e=>Object.fromEntries(Object.entries(e).filter((([,e])=>void 0!==e))),_=e=>{const{postalCode:t}=e,i=j(e,["postalCode"]);return x(Object.assign(Object.assign({},i),{postal_code:t}))},D=e=>null==e?void 0:e?"auto":"never",P=e=>{if(null==e)return{};const{merchantDisplayName:t,paymentMethodLayout:i,defaultBillingDetails:n,billingDetailsCollectionConfiguration:s,enableApplePay:a,enableGooglePay:r}=e,o={},l=(e=>{if(null==e)return;const{email:t,name:i,phone:n,address:s}=e,a=x({email:"never"===t||"always"===t?"never":void 0,name:"never"===i?"never":void 0,phone:"never"===n||"always"===n&&"full"===s?"never":void 0,address:"never"===s||"full"===s?"never":void 0});return 0===Object.keys(a).length?void 0:a})(s),c=x({applePay:D(a),googlePay:D(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=k[i]),null!=n){const{address:e}=n,t=j(n,["address"]),i=x(t);null!=e&&(i.address=_(e)),o.defaultValues={billingDetails:i}}return o},F=e=>{if(null!=e)return{theme:C[e]}},q=e=>{const{name:t,phone:i,address:n}=e,s=null==n?void 0:n.country;return x({name:t,phone:i,address:null==s||""===s?void 0:Object.assign(Object.assign({},_(n)),{country:s})})},E=e=>null==e||""===e,R=(e,t)=>Error(`<stripe-payment-sheet>: billingDetailsCollectionConfiguration.${e} is 'never', so defaultBillingDetails.${t} is required`),A=e=>Object.assign(Error(e),{type:"validation_error",sheetValidation:!0}),L=["card_error","validation_error","api_connection_error","rate_limit_error","api_error"],z=e=>{const t=F(null==e?void 0:e.style);return null==t?void 0:{appearance:t}},N=(e,t)=>{if(null!=e&&"open"!==e.type)throw new h({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.`})},B=e=>null==e||""===e?void 0:e,K=t(class extends i{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(e){super(),!1!==e&&this.__registerHost(),this.paymentSheetLoaded=n(this,"paymentSheetLoaded",7),this.paymentSheetFailedToLoad=n(this,"paymentSheetFailedToLoad",7),this.paymentSheetCompleted=n(this,"paymentSheetCompleted",7),this.paymentSheetCanceled=n(this,"paymentSheetCanceled",7),this.paymentSheetFailed=n(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=m,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=l.createStripeService(),this.paymentElementManager=l.createPaymentElementManager(this.stripeService),this.billingAddressElementManager=l.createAddressElementManager(this.stripeService),this.shippingAddressElementManager=l.createAddressElementManager(this.stripeService),this.emailElementManager=l.createLinkAuthenticationElementManager(this.stripeService)}componentWillLoad(){this.open&&this.dispatch({type:"openRequested"}),this.startLoading()}componentDidLoad(){this.el.classList.add(r())}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=B(this.publishableKey);if(null==t)return;const i=B(this.checkoutSessionClientSecret),n=B(this.intentClientSecret),[s,a]=null!=i?[i,"checkoutSession"]:[n,"intent"];return null!=s?{key:JSON.stringify([t,null!==(e=B(this.stripeAccount))&&void 0!==e?e:null,a,s]),clientSecret:s,source:a}:void 0}dispatch(e){const{state:t,effects:i}=((e,t)=>{switch(t.type){case"secretChanged":return g(e,t.clientSecret,t.source);case"loadSucceeded":{if(t.generation!==e.generation||"loading"!==e.phase)return y(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 y(e);const i=b(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 y(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 y(Object.assign(Object.assign({},e),{pendingPresent:!0,openRequested:!0}));case"presented":case"confirming":return y(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"}]}:y("idle"===e.phase||"loading"===e.phase?Object.assign(Object.assign({},e),{openRequested:!0}):e);case"closeRequested":if("presented"===e.phase){const t=v(e);return{state:Object.assign(Object.assign({},t.state),{phase:"ready"}),effects:t.effects}}return"idle"!==e.phase&&"loading"!==e.phase||!e.openRequested?y(e):v(e);case"submitted":return"presented"!==e.phase||null==e.intentKind?y(e):{state:Object.assign(Object.assign({},e),{phase:"confirming"}),effects:[{type:"confirm",generation:e.generation,intentKind:e.intentKind}]};case"confirmSucceeded":{if(!S(e,t.generation))return y(e);const i=b(Object.assign(Object.assign({},e),{phase:"completed"}),"paymentSheetCompleted");return w({state:i.state,effects:[{type:"hide"},{type:"emit",event:"paymentSheetCompleted"},...i.effects]})}case"confirmDeclined":return S(e,t.generation)?w({state:Object.assign(Object.assign({},e),{phase:"presented"}),effects:[{type:"showError",message:t.message}]}):y(e);case"confirmFailed":{if(!S(e,t.generation))return y(e);const i=b(Object.assign(Object.assign({},e),{phase:"errored"}),"paymentSheetFailed");return w({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 n;this.warnUnsupportedOptions(i);const s=()=>e!==this.sheet.generation;try{const a=((e,t)=>{var i,n,s,a,r,o,l;const c=null!==(i=null==e?void 0:e.billingDetailsCollectionConfiguration)&&void 0!==i?i:{},d=null!==(n=null==e?void 0:e.defaultBillingDetails)&&void 0!==n?n:{},h={};if(["email","name","phone"].forEach((e=>{if("never"===c[e]){if(E(d[e]))throw R(e,e);h[e]=d[e]}})),"never"===c.address){const e=d.address;if(null==e||E(e.country))throw R("address","address.country");h.address={line1:null!==(s=e.line1)&&void 0!==s?s:"",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:q(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=E(d.email)?{}:{defaultValues:{email:d.email}});const m=null==e?void 0:e.shippingDetails;if(null!=m&&"payment"===t){const e={mode:"shipping",defaultValues:q(m)};E(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}),s())return;if("success"!==this.stripeService.state.loadStripeStatus)throw Error("Failed to load Stripe.js");const r=F(null===(n=this.options)||void 0===n?void 0:n.style);if(null!=r&&(await this.stripeService.getElements().update({appearance:r}),s()))return;if(!await this.mountExtraElements(a,s))return;await this.paymentElementManager.initialize(this.el,P(this.options)),this.dispatch({type:"loadSucceeded",generation:e})}catch(t){if(s())return;this.lastError=t,this.dispatch({type:"loadFailed",generation:e})}}async mountExtraElements(e,t){this.collection=e;const{emailElement:i,shippingAddressElement:n,billingAddressElement:s}=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:n&&(e=>this.shippingAddressElementManager.initialize(e,n))},{manager:this.billingAddressElementManager,selector:".stripe-payment-sheet-billing-address",mount:s&&(e=>this.billingAddressElementManager.initialize(e,s))}];for(const{manager:e,selector:i,mount:n}of a){if(null==n){e.unmount();continue}const s=await c(this.el,i);if(t())return!1;if(await n(s),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,n=null!=t.emailElement?this.emailElementManager.getState():void 0,s=((e,t)=>{var i,n;const s={};if(null!=e.billingAddressElement){const i=t.billingAddress;if(null==i||!i.complete)throw A("Please complete your billing address.");s.name=i.value.name,s.address=i.value.address,e.collectPhoneFromAddress&&(s.phone=i.value.phone)}if(null!=e.emailElement){const a=null!==(i=t.email)&&void 0!==i?i:null===(n=e.emailElement.defaultValues)||void 0===n?void 0:n.email;if(E(a))throw A("Please enter your email address.");if(!1===t.emailComplete||null==t.emailComplete&&!(e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))(a))throw A("Please enter a valid email address.");s.email=a}return Object.assign(s,e.fixedBillingDetails),0===Object.keys(s).length?void 0:s})(t,{billingAddress:i,email:null==n?void 0:n.email,emailComplete:null==n?void 0:n.complete});return null==s?void 0:{payment_method_data:{billing_details:s}}}confirm(e,t){return this.runConfirm(e,(async()=>{var e,i;const n=this.stripeService.getElements(),{error:s}=await n.submit();if(null!=s)throw s;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 d(this.stripeService.getStripe(),n,t,a,r)}))}async runConfirm(e,t){var i;try{this.lastResult=await t(),this.dispatch({type:"confirmSucceeded",generation:e})}catch(t){const n=null!==(i=t.message)&&void 0!==i?i:t+"",s=(e=>!0===(null==e?void 0:e.sheetValidation))(t)?o.t(n):n;if((e=>{const t=null==e?void 0:e.type;return"string"==typeof t&&L.includes(t)})(t))return void this.dispatch({type:"confirmDeclined",generation:e,message:s});this.lastError=t,this.dispatch({type:"confirmFailed",generation:e,message:s})}}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:z(this.options)}),e!==this.sheet.generation)return;if("success"!==this.stripeService.state.loadStripeStatus)throw Error("Failed to load Stripe.js");await this.paymentElementManager.initialize(this.el,(e=>{const{layout:t}=P(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 n=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 Error("Checkout Session is not initialized");return(async(e,t,i)=>{const n=await e.loadActions();if("error"===n.type)throw new h({type:"api_error",code:"checkout_session_error",message:n.error.message});const{actions:s}=n,a=()=>{var e,t;return null===(t=null===(e=s.getSession)||void 0===e?void 0:e.call(s))||void 0===t?void 0:t.status};N(a());const r=await s.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(N(a(),t),"paymentFailed"===e)throw new h({type:"card_error",code:e,message:t});throw new h({type:"api_error",code:"checkout_session_error",message:t})}return r})(i,n,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&&!O.includes(e))).map((([e])=>e)),n=e.billingDetailsCollectionConfiguration;return"always"===(null==n?void 0:n.name)&&i.push("billingDetailsCollectionConfiguration.name"),"always"===(null==n?void 0:n.phone)&&"full"!==n.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,n=["name","phone","address"].filter((e=>null!=(null==i?void 0:i[e]))).map((e=>"defaultBillingDetails."+e));return null!=t&&n.push("merchantDisplayName"),["billingDetailsCollectionConfiguration","shippingDetails","enableApplePay","enableGooglePay"].filter((t=>void 0!==e[t])).forEach((e=>n.push(e))),n.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,i;const{phase:n}=this.sheet,r="confirming"===n;return s(a,{key:"e6b2c3cb168039eb428eaaee1dce598f534c18e7"},s("stripe-modal",{key:"ef1515b07cca402c4db8818e2e94ca80e4d954c2",open:this.visible,showCloseButton:!r,onClose:this.handleModalClose},s("div",{key:"9252fa1653b206d211756c94325c73a8ec482a37",class:"stripe-payment-sheet-wrap"},s("form",{key:"904a54f2439e0356c2cbf9227326efe446aa08ce",id:"stripe-payment-sheet",onSubmit:this.handleSubmit},s("div",{key:"103d81e3c56cfba1c421e1bf140a49e2b392c6b5",class:"stripe-heading"},o.t(this.sheetTitle)),s("div",{key:"cda58a48db7b04af1981407b7100def815404e35",class:"payment-info visible"},s("div",{key:"cbe248666aa4807c25d492df1ab1de017bc78e2c",class:"stripe-payment-sheet-email"},null!=(null===(e=this.collection)||void 0===e?void 0:e.emailElement)&&s("div",{key:"b0210c6cce85d1affaa83e3fa30785158c9bab98",id:"link-authentication-element"})),s("div",{key:"2420956298e5b36c63f3fbea6b4e32429b7ace27",class:"stripe-payment-sheet-shipping-address"},null!=(null===(t=this.collection)||void 0===t?void 0:t.shippingAddressElement)&&s("div",{key:"ae41335a42c59598e1addbfdea0a13342c026456",id:"address-element"})),s("div",{key:"3196844c9396c40548a3c632733565027df3cea7",class:"stripe-payment-sheet-billing-address"},null!=(null===(i=this.collection)||void 0===i?void 0:i.billingAddressElement)&&s("div",{key:"269a99368975db70722fc181a1c099859f23d3d6",id:"address-element"})),s("div",{key:"2a63173a607501ff08ac072956cdbe462a4400c1",id:"payment-element"})),s("div",{key:"7a72a86097aca2af6491c56b52258286ef820283",class:"stripe-element-errors",role:"alert"},this.errorMessage),s("div",{key:"10f05d5ecfa53cde350f00acffd86e232e370fe7",class:"stripe-submit"},s("button",{key:"a7ad3e538b94403bd8c71b31bd405c1b0c59543c",type:"submit",disabled:"presented"!==n},o.t(r?"Loading":this.buttonLabel)))))))}get el(){return this}static get watchers(){return{publishableKey:[{handleSecretChange:0}],intentClientSecret:[{handleSecretChange:0}],checkoutSessionClientSecret:[{handleSecretChange:0}],stripeAccount:[{handleSecretChange:0}],open:[{handleOpenChange:0}]}}static get style(){return':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)}'}},[0,"stripe-payment-sheet",{publishableKey:[1,"publishable-key"],intentClientSecret:[1,"intent-client-secret"],checkoutSessionClientSecret:[1,"checkout-session-client-secret"],stripeAccount:[1,"stripe-account"],open:[1540],sheetTitle:[1,"sheet-title"],buttonLabel:[1,"button-label"],applicationName:[1,"application-name"],options:[16],sheet:[32],visible:[32],errorMessage:[32],collection:[32],present:[64]},void 0,{publishableKey:[{handleSecretChange:0}],intentClientSecret:[{handleSecretChange:0}],checkoutSessionClientSecret:[{handleSecretChange:0}],stripeAccount:[{handleSecretChange:0}],open:[{handleOpenChange:0}]}]);function T(){"undefined"!=typeof customElements&&["stripe-payment-sheet","ion-icon","stripe-modal"].forEach((t=>{switch(t){case"stripe-payment-sheet":customElements.get(e(t))||customElements.define(e(t),K);break;case"ion-icon":customElements.get(e(t))||p();break;case"stripe-modal":customElements.get(e(t))||u()}}))}T();const $=K,V=T;export{$ as StripePaymentSheet,V as defineCustomElement}
|