stripe-pwa-elements 4.0.5 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{factory-xOoxnMhx.js → factory-yd5HDEZn.js} +1 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stripe-address-element.cjs.entry.js +1 -1
- package/dist/cjs/stripe-card-element.cjs.entry.js +1 -1
- package/dist/cjs/stripe-currency-selector.cjs.entry.js +1 -1
- package/dist/cjs/stripe-elements.cjs.js +1 -1
- package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +1 -1
- package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +1 -1
- package/dist/cjs/stripe-payment-element.cjs.entry.js +18 -7
- package/dist/cjs/stripe-payment-element.helpers-D1JnhTa-.js +182 -0
- package/dist/cjs/stripe-payment-sheet.cjs.entry.js +72 -57
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +9 -32
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +87 -5
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +60 -48
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +5 -2
- package/dist/collection/services/stripe-service.js +1 -0
- package/dist/collection/utils/checkout-confirm.js +84 -0
- package/dist/components/factory.js +1 -1
- package/dist/components/stripe-payment-element.helpers.js +1 -1
- package/dist/components/stripe-payment-element.js +1 -1
- package/dist/components/stripe-payment-sheet.js +1 -1
- package/dist/esm/{factory-CsurRVcp.js → factory-B_WxdnxM.js} +1 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stripe-address-element.entry.js +1 -1
- package/dist/esm/stripe-card-element.entry.js +1 -1
- package/dist/esm/stripe-currency-selector.entry.js +1 -1
- package/dist/esm/stripe-elements.js +1 -1
- package/dist/esm/stripe-express-checkout-element.entry.js +1 -1
- package/dist/esm/stripe-link-authentication-element.entry.js +1 -1
- package/dist/esm/stripe-payment-element.entry.js +18 -7
- package/dist/esm/stripe-payment-element.helpers-PuWxhMNR.js +176 -0
- package/dist/esm/stripe-payment-sheet.entry.js +72 -57
- package/dist/stripe-elements/{p-949a8bba.entry.js → p-2e2bf0fe.entry.js} +1 -1
- package/dist/stripe-elements/{p-b0f9ebba.entry.js → p-32a2d5a4.entry.js} +1 -1
- package/dist/stripe-elements/{p-edbbe060.entry.js → p-84d45b48.entry.js} +1 -1
- package/dist/stripe-elements/{p-a2d11152.entry.js → p-a266da6f.entry.js} +1 -1
- package/dist/stripe-elements/p-c4a0e310.entry.js +1 -0
- package/dist/stripe-elements/{p-50e495e3.entry.js → p-e660d76a.entry.js} +1 -1
- package/dist/stripe-elements/p-eeebfbbf.entry.js +1 -0
- package/dist/stripe-elements/p-n0XJSLU3.js +1 -0
- package/dist/stripe-elements/p-wrjrFokg.js +1 -0
- package/dist/stripe-elements/stripe-elements.esm.js +1 -1
- package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +33 -0
- package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +8 -2
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +19 -11
- package/dist/types/components.d.ts +34 -2
- package/dist/types/services/interfaces.d.ts +3 -1
- package/dist/types/utils/checkout-confirm.d.ts +35 -0
- package/package.json +1 -1
- package/dist/cjs/stripe-payment-element.helpers-lafmSRmb.js +0 -121
- package/dist/esm/stripe-payment-element.helpers-CklK5RlF.js +0 -116
- package/dist/stripe-elements/p-855d1aee.entry.js +0 -1
- package/dist/stripe-elements/p-B2G-wquO.js +0 -1
- package/dist/stripe-elements/p-BoZLkOAy.js +0 -1
- package/dist/stripe-elements/p-a45268d4.entry.js +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { StripeAPIError } from "./error";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a confirm failure means the session was created with `return_url`, which rejects `returnUrl`.
|
|
4
|
+
* Stripe raises this before any payment processing, so retrying without `returnUrl` is safe.
|
|
5
|
+
* `actions.confirm()` reports it both as a thrown `IntegrationError` and as an error result depending on the SDK version.
|
|
6
|
+
* @param error - Error thrown by `actions.confirm()` or the error of its result
|
|
7
|
+
*/
|
|
8
|
+
export const isCheckoutReturnUrlConflict = (error) => {
|
|
9
|
+
const message = error instanceof Error ? error.message : error === null || error === void 0 ? void 0 : error.message;
|
|
10
|
+
return typeof message === 'string' && message.includes('cannot provide `returnUrl`');
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Throw when the session can no longer be paid. Stripe documents an `expired` session as "No further processing will occur",
|
|
14
|
+
* and a `complete` one is already paid or being paid, so confirming again cannot succeed.
|
|
15
|
+
* @param status - `session.status` from `getSession()`; undefined when it cannot be read
|
|
16
|
+
* @param message - Message of the confirm error, if any
|
|
17
|
+
* @throws StripeAPIError of type `invalid_request_error` (unrecoverable), with the code `checkout_session_expired` or `checkout_session_complete`
|
|
18
|
+
*/
|
|
19
|
+
export const assertCheckoutSessionOpen = (status, message) => {
|
|
20
|
+
if (status == null || status.type === 'open') {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
throw new StripeAPIError({
|
|
24
|
+
type: 'invalid_request_error',
|
|
25
|
+
code: `checkout_session_${status.type}`,
|
|
26
|
+
message: message !== null && message !== void 0 ? message : `The Checkout Session is ${status.type} and can no longer be paid.`,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Confirm a Checkout Session through the checkout actions.
|
|
31
|
+
*
|
|
32
|
+
* Stripe requires exactly one of `returnUrl` (confirm argument) or the session's `return_url`, and the client
|
|
33
|
+
* cannot tell which one a session has (`getSession()` does not expose it). So the first attempt passes
|
|
34
|
+
* `returnUrl`, and when Stripe rejects it because the session already has `return_url`, the confirmation is
|
|
35
|
+
* retried without `returnUrl` (Stripe then redirects to the session's `return_url` automatically).
|
|
36
|
+
*
|
|
37
|
+
* Errors are thrown as `StripeAPIError`:
|
|
38
|
+
* - session `expired` or `complete` (before confirming or after a failed confirm): `invalid_request_error`
|
|
39
|
+
* - `paymentFailed` on an open session (a decline): `card_error`
|
|
40
|
+
* - any other confirm error on an open session, or a failure to load the actions: `api_error`
|
|
41
|
+
* @param checkout - The Checkout instance from `initCheckoutElementsSdk`
|
|
42
|
+
* @param returnUrl - Where Stripe redirects after a redirect-based payment method, when the session has no `return_url`
|
|
43
|
+
* @param email - Customer email; needed when the session was created without `customer_email` or `customer`
|
|
44
|
+
* @returns The confirmation result
|
|
45
|
+
* @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
|
|
46
|
+
*/
|
|
47
|
+
export const confirmCheckoutActions = async (checkout, returnUrl, email) => {
|
|
48
|
+
const loadActionsResult = await checkout.loadActions();
|
|
49
|
+
if (loadActionsResult.type === 'error') {
|
|
50
|
+
throw new StripeAPIError({
|
|
51
|
+
type: 'api_error',
|
|
52
|
+
code: 'checkout_session_error',
|
|
53
|
+
message: loadActionsResult.error.message,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const { actions } = loadActionsResult;
|
|
57
|
+
const sessionStatus = () => { var _a, _b; return (_b = (_a = actions.getSession) === null || _a === void 0 ? void 0 : _a.call(actions)) === null || _b === void 0 ? void 0 : _b.status; };
|
|
58
|
+
assertCheckoutSessionOpen(sessionStatus());
|
|
59
|
+
const confirmWith = (withReturnUrl) => actions.confirm(Object.assign(Object.assign({ redirect: 'if_required' }, (withReturnUrl && returnUrl !== '' ? { returnUrl } : {})), (email != null && email !== '' ? { email } : {})));
|
|
60
|
+
// First attempt with returnUrl; a session created with `return_url` rejects it before processing.
|
|
61
|
+
// The rejection can arrive either as a thrown error or as an error result, so both are retried without it.
|
|
62
|
+
let result;
|
|
63
|
+
try {
|
|
64
|
+
result = await confirmWith(true);
|
|
65
|
+
if (result.type === 'error' && isCheckoutReturnUrlConflict(result.error)) {
|
|
66
|
+
result = await confirmWith(false);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
if (!isCheckoutReturnUrlConflict(e)) {
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
result = await confirmWith(false);
|
|
74
|
+
}
|
|
75
|
+
if (result.type === 'error') {
|
|
76
|
+
const { code, message } = result.error;
|
|
77
|
+
assertCheckoutSessionOpen(sessionStatus(), message);
|
|
78
|
+
if (code === 'paymentFailed') {
|
|
79
|
+
throw new StripeAPIError({ type: 'card_error', code, message });
|
|
80
|
+
}
|
|
81
|
+
throw new StripeAPIError({ type: 'api_error', code: 'checkout_session_error', message });
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"@stencil/core/internal/client";import{l as e}from"./index2.js";import{i}from"./i18n.js";const r=(()=>{let t;return(...e)=>{t&&clearTimeout(t),t=setTimeout((()=>{t=0,(t=>{for(let e of t.keys()){const i=t.get(e).filter((t=>{const e=t.deref();return e&&(!("isConnected"in(i=e))||i.isConnected);var i}));t.set(e,i)}})(...e)}),2e3)}})(),s=t.forceUpdate,n=t.getRenderingRef,o=(t,e)=>{const i=t.indexOf(e);i>=0&&(t[i]=t[t.length-1],t.length--)},l=(t,e)=>{const i=((t,e=(t,e)=>t!==e)=>{const i=()=>{return("function"==typeof(e=t)?e():e)??{};var e},r=i();let s=new Map(Object.entries(r));const n="undefined"!=typeof Proxy,l=n?null:{},c={dispose:[],get:[],set:[],reset:[]},a=new Map,h=()=>{s=new Map(Object.entries(i())),n||m(),c.reset.forEach((t=>t()))},u=t=>(c.get.forEach((e=>e(t))),s.get(t)),d=(t,i)=>{const r=s.get(t);e(i,r,t)&&(s.set(t,i),n||g(t),c.set.forEach((e=>e(t,i,r))))},v=n?new Proxy(r,{get:(t,e)=>u(e),ownKeys:()=>Array.from(s.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(t,e)=>s.has(e),set:(t,e,i)=>(d(e,i),!0)}):(m(),l),p=(t,e)=>(c[t].push(e),()=>{o(c[t],e)});function g(t){!n&&l&&(Object.prototype.hasOwnProperty.call(l,t)||Object.defineProperty(l,t,{configurable:!0,enumerable:!0,get:()=>u(t),set(e){d(t,e)}}))}function m(){if(n||!l)return;const t=new Set(s.keys());for(const e of Object.keys(l))t.has(e)||delete l[e];for(const e of t)g(e)}return{state:v,get:u,set:d,on:p,onChange:(t,e)=>{const r=(i,r)=>{i===t&&e(r)},s=()=>{const r=i();e(r[t])},n=p("set",r),o=p("reset",s);return a.set(e,{setHandler:r,resetHandler:s,propName:t}),()=>{n(),o(),a.delete(e)}},use:(...t)=>{const e=t.reduce(((t,e)=>(e.set&&t.push(p("set",e.set)),e.get&&t.push(p("get",e.get)),e.reset&&t.push(p("reset",e.reset)),e.dispose&&t.push(p("dispose",e.dispose)),t)),[]);return()=>e.forEach((t=>t()))},dispose:()=>{c.dispose.forEach((t=>t())),h()},reset:h,forceUpdate:t=>{const e=s.get(t);c.set.forEach((i=>i(t,e,e)))},removeListener:(t,e)=>{const i=a.get(e);i&&i.propName===t&&(o(c.set,i.setHandler),o(c.reset,i.resetHandler),a.delete(e))}}})(t,e);return i.use((()=>{if("function"!=typeof n||"function"!=typeof s)return{};const t=s,e=n,i=new Map;return{dispose:()=>i.clear(),get:t=>{const r=e();r&&((t,e,i)=>{let r=t.get(e);r||(r=[],t.set(e,r)),r.some((t=>t.deref()===i))||r.push(new WeakRef(i))})(i,t,r)},set:e=>{const s=i.get(e);if(s){const r=s.filter((e=>{const i=e.deref();return!!i&&t(i)}));i.set(e,r)}r(i)},reset:()=>{i.forEach((e=>{e.forEach((e=>{const i=e.deref();i&&t(i)}))})),r(i)}}})()),i};class c{constructor(){this.store=l({loadStripeStatus:"",applicationName:"stripe-pwa-elements",isCheckoutSession:!1}),this.initGeneration=0,this.changeListeners=new Map}get state(){return this.store.state}onChange(t,e){const i=this.store.onChange(t,e);return this.changeListeners.has(t)||this.changeListeners.set(t,[]),this.changeListeners.get(t).push(i),i}async initialize(t,i){const r=null!=(null==i?void 0:i.elementsOptions)?JSON.stringify(i.elementsOptions):void 0,s=null!=this.store.state.stripe&&!this.store.state.isCheckoutSession&&this.store.state.publishableKey===t&&this.store.state.stripeAccount===(null==i?void 0:i.stripeAccount)&&this.intentClientSecret===(null==i?void 0:i.clientSecret)&&this.elementsOptionsKey===r;if(this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!1,this.intentClientSecret=null==i?void 0:i.clientSecret,this.elementsOptionsKey=r,null!=(null==i?void 0:i.stripeAccount)&&""!==(null==i?void 0:i.stripeAccount)&&(this.store.state.stripeAccount=i.stripeAccount),null!=(null==i?void 0:i.applicationName)&&""!==(null==i?void 0:i.applicationName)&&(this.store.state.applicationName=i.applicationName),s)return;const n=++this.initGeneration;this.store.state.loadStripeStatus="loading";try{const r=await e(t,{stripeAccount:null==i?void 0:i.stripeAccount});if(n!==this.initGeneration)return;r.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=r,this.store.state.elements=null!=(null==i?void 0:i.clientSecret)&&""!==i.clientSecret?r.elements({clientSecret:i.clientSecret}):null!=(null==i?void 0:i.elementsOptions)?r.elements(i.elementsOptions):r.elements(),this.store.state.checkout=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to load Stripe.js:",t),this.store.state.loadStripeStatus="failure"}}async initializeWithCheckoutSession(t,i,r){const s=++this.initGeneration;this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!0,null!=(null==r?void 0:r.stripeAccount)&&""!==(null==r?void 0:r.stripeAccount)&&(this.store.state.stripeAccount=r.stripeAccount),null!=(null==r?void 0:r.applicationName)&&""!==(null==r?void 0:r.applicationName)&&(this.store.state.applicationName=r.applicationName),this.store.state.loadStripeStatus="loading";try{const n=await e(t,{stripeAccount:null==r?void 0:r.stripeAccount});if(s!==this.initGeneration)return;n.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=n;const o=n.initCheckoutElementsSdk({clientSecret:i,elementsOptions:null==r?void 0:r.elementsOptions});this.store.state.checkout=o,this.store.state.elements=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to initialize Stripe Checkout:",t),this.store.state.loadStripeStatus="failure"}}getStripe(){return this.store.state.stripe}getElements(){return this.store.state.elements}getCheckout(){return this.store.state.checkout}reset(){this.store.reset()}dispose(){this.changeListeners.forEach((t=>{t.forEach((t=>t()))})),this.changeListeners.clear(),this.store.dispose()}}function a(t,e,i=5e3){return new Promise(((r,s)=>{const n=t.querySelector(e);if(null!=n)return r(n);const o=setTimeout((()=>{l.disconnect(),s(new Error(`Element "${e}" not found within ${i}ms`))}),i),l=new MutationObserver((()=>{const i=t.querySelector(e);null!=i&&(clearTimeout(o),l.disconnect(),r(i))}));l.observe(t,{childList:!0,subtree:!0})}))}new c;class h{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",errorSource:void 0})}getState(){return this.store.state}async initialize(t){const e=this.stripeService.getElements();if(null==e)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.cardElements&&this.unmount();const r=e.create("cardNumber",{placeholder:i.t("Card Number")}),s=await a(t,"#card-number");r.mount(s),r.on("change",this.handleCardError("cardNumber"));const n=e.create("cardExpiry"),o=await a(t,"#card-expiry");n.mount(o),n.on("change",this.handleCardError("cardExpiry"));const l=e.create("cardCvc"),c=await a(t,"#card-cvc");return l.mount(c),l.on("change",this.handleCardError("cardCvc")),this.cardElements={cardNumber:r,cardExpiry:n,cardCVC:l},this.cardElements}getElements(){return this.cardElements}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage",""),this.store.set("errorSource",void 0)}unmount(){var t,e,i;null!=this.cardElements&&(null===(t=this.cardElements.cardNumber)||void 0===t||t.unmount(),null===(e=this.cardElements.cardExpiry)||void 0===e||e.unmount(),null===(i=this.cardElements.cardCVC)||void 0===i||i.unmount(),this.cardElements=void 0)}handleCardError(t){return({error:e})=>{if(e)return this.store.set("errorMessage",e.message),void this.store.set("errorSource",t);this.store.state.errorSource===t&&(this.store.set("errorMessage",""),this.store.set("errorSource",void 0))}}}class u{constructor(t){this.stripeService=t,this.store=l({errorMessage:""})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.state.isCheckoutSession;if(null!=this.paymentElement&&this.unmount(),i){const t=this.stripeService.getCheckout();if(null==t)throw new Error("StripeService not initialized with Checkout Session. Call StripeService.initializeWithCheckoutSession() first.");this.paymentElement=t.createPaymentElement(e)}else{const t=this.stripeService.getElements();if(null==t)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");this.paymentElement=t.create("payment",e||{})}const r=await a(t,"#payment-element");return this.paymentElement.mount(r),this.paymentElement}getElement(){return this.paymentElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.paymentElement&&(this.paymentElement.unmount(),this.paymentElement=void 0)}}class d{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isComplete:!1})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.addressElement&&this.unmount(),this.addressElement=i.create("address",e||{mode:"billing"});const r=await a(t,"#address-element");return this.addressElement.mount(r),this.addressElement.on("change",(t=>{this.store.set("errorMessage",""),this.store.set("isComplete",t.complete)})),this.addressElement}getElement(){return this.addressElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.addressElement&&(this.addressElement.unmount(),this.addressElement=void 0)}}class v{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",email:void 0,complete:void 0})}getState(){return this.store.state}onChange(t,e){return this.store.onChange(t,e)}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.linkAuthenticationElement&&this.unmount(),this.store.set("email",void 0),this.store.set("complete",void 0);const r=i.create("linkAuthentication",e),s=await a(t,"#link-authentication-element");return r.mount(s),r.on("change",(t=>{var e;this.store.set("email",null===(e=t.value)||void 0===e?void 0:e.email),this.store.set("complete",t.complete)})),this.linkAuthenticationElement=r,this.linkAuthenticationElement}getElement(){return this.linkAuthenticationElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.linkAuthenticationElement&&(this.linkAuthenticationElement.unmount(),this.linkAuthenticationElement=void 0)}}class p{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",selectedCurrency:void 0})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.currencySelectorElement&&this.unmount();const r=await a(t,"#currency-selector");return this.currencySelectorElement=i.create("currencySelector",e||{}),this.currencySelectorElement.mount(r),this.currencySelectorElement.on("change",(t=>{var e;this.store.set("errorMessage",""),(null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.currency)&&this.store.set("selectedCurrency",t.value.currency)})),this.currencySelectorElement}getElement(){return this.currencySelectorElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.currencySelectorElement&&(this.currencySelectorElement.unmount(),this.currencySelectorElement=void 0)}}var g=function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(i[r[s]]=t[r[s]])}return i};class m{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isReady:!1})}getState(){return this.store.state}async initialize(t,e,i){const r=this.stripeService.getElements();if(null==r)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.expressCheckoutElement&&this.unmount();const s=g(e,["mode","amount","currency"]),n=Object.assign({},s);if(n.buttonHeight&&"string"==typeof n.buttonHeight){const t=parseInt(n.buttonHeight.replace("px",""),10);isNaN(t)||(n.buttonHeight=t)}const o=r.create("expressCheckout",n),l=await a(t,"#express-checkout-element");return null!=(null==i?void 0:i.onConfirm)&&o.on("confirm",i.onConfirm),null!=(null==i?void 0:i.onClick)&&o.on("click",i.onClick),null!=(null==i?void 0:i.onCancel)&&o.on("cancel",i.onCancel),null!=(null==i?void 0:i.onShippingAddressChange)&&o.on("shippingaddresschange",i.onShippingAddressChange),null!=(null==i?void 0:i.onShippingRateChange)&&o.on("shippingratechange",i.onShippingRateChange),o.on("ready",(()=>{this.store.set("isReady",!0)})),o.mount(l),this.expressCheckoutElement=o,this.expressCheckoutElement}getElement(){return this.expressCheckoutElement}update(t){var e;if(null==this.expressCheckoutElement)return void console.warn("Express Checkout Element not initialized. Cannot update options.");const{mode:i,amount:r,currency:s}=t,n=g(t,["mode","amount","currency"]),o={};void 0!==i&&(o.mode=i),void 0!==r&&(o.amount=r),void 0!==s&&(o.currency=s),Object.keys(o).length>0&&(null===(e=this.stripeService.getElements())||void 0===e||e.update(o));const l=Object.assign({},n);if(l.buttonHeight&&"string"==typeof l.buttonHeight){const t=parseInt(l.buttonHeight.replace("px",""),10);isNaN(t)||(l.buttonHeight=t)}0!==Object.keys(l).length&&this.expressCheckoutElement.update(l)}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.expressCheckoutElement&&(this.expressCheckoutElement.unmount(),this.expressCheckoutElement=void 0,this.store.set("isReady",!1))}}const f=new class{createStripeService(){return new c}createCardElementManager(t){return new h(t)}createPaymentElementManager(t){return new u(t)}createAddressElementManager(t){return new d(t)}createLinkAuthenticationElementManager(t){return new v(t)}createCurrencySelectorElementManager(t){return new p(t)}createExpressCheckoutElementManager(t){return new m(t)}};export{a as f,f as s}
|
|
1
|
+
import*as t from"@stencil/core/internal/client";import{l as e}from"./index2.js";import{i}from"./i18n.js";const r=(()=>{let t;return(...e)=>{t&&clearTimeout(t),t=setTimeout((()=>{t=0,(t=>{for(let e of t.keys()){const i=t.get(e).filter((t=>{const e=t.deref();return e&&(!("isConnected"in(i=e))||i.isConnected);var i}));t.set(e,i)}})(...e)}),2e3)}})(),s=t.forceUpdate,n=t.getRenderingRef,o=(t,e)=>{const i=t.indexOf(e);i>=0&&(t[i]=t[t.length-1],t.length--)},l=(t,e)=>{const i=((t,e=(t,e)=>t!==e)=>{const i=()=>{return("function"==typeof(e=t)?e():e)??{};var e},r=i();let s=new Map(Object.entries(r));const n="undefined"!=typeof Proxy,l=n?null:{},a={dispose:[],get:[],set:[],reset:[]},c=new Map,h=()=>{s=new Map(Object.entries(i())),n||m(),a.reset.forEach((t=>t()))},u=t=>(a.get.forEach((e=>e(t))),s.get(t)),d=(t,i)=>{const r=s.get(t);e(i,r,t)&&(s.set(t,i),n||g(t),a.set.forEach((e=>e(t,i,r))))},v=n?new Proxy(r,{get:(t,e)=>u(e),ownKeys:()=>Array.from(s.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(t,e)=>s.has(e),set:(t,e,i)=>(d(e,i),!0)}):(m(),l),p=(t,e)=>(a[t].push(e),()=>{o(a[t],e)});function g(t){!n&&l&&(Object.prototype.hasOwnProperty.call(l,t)||Object.defineProperty(l,t,{configurable:!0,enumerable:!0,get:()=>u(t),set(e){d(t,e)}}))}function m(){if(n||!l)return;const t=new Set(s.keys());for(const e of Object.keys(l))t.has(e)||delete l[e];for(const e of t)g(e)}return{state:v,get:u,set:d,on:p,onChange:(t,e)=>{const r=(i,r)=>{i===t&&e(r)},s=()=>{const r=i();e(r[t])},n=p("set",r),o=p("reset",s);return c.set(e,{setHandler:r,resetHandler:s,propName:t}),()=>{n(),o(),c.delete(e)}},use:(...t)=>{const e=t.reduce(((t,e)=>(e.set&&t.push(p("set",e.set)),e.get&&t.push(p("get",e.get)),e.reset&&t.push(p("reset",e.reset)),e.dispose&&t.push(p("dispose",e.dispose)),t)),[]);return()=>e.forEach((t=>t()))},dispose:()=>{a.dispose.forEach((t=>t())),h()},reset:h,forceUpdate:t=>{const e=s.get(t);a.set.forEach((i=>i(t,e,e)))},removeListener:(t,e)=>{const i=c.get(e);i&&i.propName===t&&(o(a.set,i.setHandler),o(a.reset,i.resetHandler),c.delete(e))}}})(t,e);return i.use((()=>{if("function"!=typeof n||"function"!=typeof s)return{};const t=s,e=n,i=new Map;return{dispose:()=>i.clear(),get:t=>{const r=e();r&&((t,e,i)=>{let r=t.get(e);r||(r=[],t.set(e,r)),r.some((t=>t.deref()===i))||r.push(new WeakRef(i))})(i,t,r)},set:e=>{const s=i.get(e);if(s){const r=s.filter((e=>{const i=e.deref();return!!i&&t(i)}));i.set(e,r)}r(i)},reset:()=>{i.forEach((e=>{e.forEach((e=>{const i=e.deref();i&&t(i)}))})),r(i)}}})()),i};class a{constructor(){this.store=l({loadStripeStatus:"",applicationName:"stripe-pwa-elements",isCheckoutSession:!1}),this.initGeneration=0,this.changeListeners=new Map}get state(){return this.store.state}onChange(t,e){const i=this.store.onChange(t,e);return this.changeListeners.has(t)||this.changeListeners.set(t,[]),this.changeListeners.get(t).push(i),i}async initialize(t,i){const r=null!=(null==i?void 0:i.elementsOptions)?JSON.stringify(i.elementsOptions):void 0,s=null!=this.store.state.stripe&&!this.store.state.isCheckoutSession&&this.store.state.publishableKey===t&&this.store.state.stripeAccount===(null==i?void 0:i.stripeAccount)&&this.intentClientSecret===(null==i?void 0:i.clientSecret)&&this.elementsOptionsKey===r;if(this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!1,this.intentClientSecret=null==i?void 0:i.clientSecret,this.elementsOptionsKey=r,null!=(null==i?void 0:i.stripeAccount)&&""!==(null==i?void 0:i.stripeAccount)&&(this.store.state.stripeAccount=i.stripeAccount),null!=(null==i?void 0:i.applicationName)&&""!==(null==i?void 0:i.applicationName)&&(this.store.state.applicationName=i.applicationName),s)return;const n=++this.initGeneration;this.store.state.loadStripeStatus="loading";try{const r=await e(t,{stripeAccount:null==i?void 0:i.stripeAccount});if(n!==this.initGeneration)return;r.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=r,this.store.state.elements=null!=(null==i?void 0:i.clientSecret)&&""!==i.clientSecret?r.elements({clientSecret:i.clientSecret}):null!=(null==i?void 0:i.elementsOptions)?r.elements(i.elementsOptions):r.elements(),this.store.state.checkout=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to load Stripe.js:",t),this.store.state.loadStripeStatus="failure"}}async initializeWithCheckoutSession(t,i,r){const s=++this.initGeneration;this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!0,null!=(null==r?void 0:r.stripeAccount)&&""!==(null==r?void 0:r.stripeAccount)&&(this.store.state.stripeAccount=r.stripeAccount),null!=(null==r?void 0:r.applicationName)&&""!==(null==r?void 0:r.applicationName)&&(this.store.state.applicationName=r.applicationName),this.store.state.loadStripeStatus="loading";try{const n=await e(t,{stripeAccount:null==r?void 0:r.stripeAccount});if(s!==this.initGeneration)return;n.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=n;const o=n.initCheckoutElementsSdk({clientSecret:i,elementsOptions:null==r?void 0:r.elementsOptions,defaultValues:null==r?void 0:r.defaultValues});this.store.state.checkout=o,this.store.state.elements=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to initialize Stripe Checkout:",t),this.store.state.loadStripeStatus="failure"}}getStripe(){return this.store.state.stripe}getElements(){return this.store.state.elements}getCheckout(){return this.store.state.checkout}reset(){this.store.reset()}dispose(){this.changeListeners.forEach((t=>{t.forEach((t=>t()))})),this.changeListeners.clear(),this.store.dispose()}}function c(t,e,i=5e3){return new Promise(((r,s)=>{const n=t.querySelector(e);if(null!=n)return r(n);const o=setTimeout((()=>{l.disconnect(),s(new Error(`Element "${e}" not found within ${i}ms`))}),i),l=new MutationObserver((()=>{const i=t.querySelector(e);null!=i&&(clearTimeout(o),l.disconnect(),r(i))}));l.observe(t,{childList:!0,subtree:!0})}))}new a;class h{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",errorSource:void 0})}getState(){return this.store.state}async initialize(t){const e=this.stripeService.getElements();if(null==e)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.cardElements&&this.unmount();const r=e.create("cardNumber",{placeholder:i.t("Card Number")}),s=await c(t,"#card-number");r.mount(s),r.on("change",this.handleCardError("cardNumber"));const n=e.create("cardExpiry"),o=await c(t,"#card-expiry");n.mount(o),n.on("change",this.handleCardError("cardExpiry"));const l=e.create("cardCvc"),a=await c(t,"#card-cvc");return l.mount(a),l.on("change",this.handleCardError("cardCvc")),this.cardElements={cardNumber:r,cardExpiry:n,cardCVC:l},this.cardElements}getElements(){return this.cardElements}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage",""),this.store.set("errorSource",void 0)}unmount(){var t,e,i;null!=this.cardElements&&(null===(t=this.cardElements.cardNumber)||void 0===t||t.unmount(),null===(e=this.cardElements.cardExpiry)||void 0===e||e.unmount(),null===(i=this.cardElements.cardCVC)||void 0===i||i.unmount(),this.cardElements=void 0)}handleCardError(t){return({error:e})=>{if(e)return this.store.set("errorMessage",e.message),void this.store.set("errorSource",t);this.store.state.errorSource===t&&(this.store.set("errorMessage",""),this.store.set("errorSource",void 0))}}}class u{constructor(t){this.stripeService=t,this.store=l({errorMessage:""})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.state.isCheckoutSession;if(null!=this.paymentElement&&this.unmount(),i){const t=this.stripeService.getCheckout();if(null==t)throw new Error("StripeService not initialized with Checkout Session. Call StripeService.initializeWithCheckoutSession() first.");this.paymentElement=t.createPaymentElement(e)}else{const t=this.stripeService.getElements();if(null==t)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");this.paymentElement=t.create("payment",e||{})}const r=await c(t,"#payment-element");return this.paymentElement.mount(r),this.paymentElement}getElement(){return this.paymentElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.paymentElement&&(this.paymentElement.unmount(),this.paymentElement=void 0)}}class d{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isComplete:!1})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.addressElement&&this.unmount(),this.addressElement=i.create("address",e||{mode:"billing"});const r=await c(t,"#address-element");return this.addressElement.mount(r),this.addressElement.on("change",(t=>{this.store.set("errorMessage",""),this.store.set("isComplete",t.complete)})),this.addressElement}getElement(){return this.addressElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.addressElement&&(this.addressElement.unmount(),this.addressElement=void 0)}}class v{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",email:void 0,complete:void 0})}getState(){return this.store.state}onChange(t,e){return this.store.onChange(t,e)}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.linkAuthenticationElement&&this.unmount(),this.store.set("email",void 0),this.store.set("complete",void 0);const r=i.create("linkAuthentication",e),s=await c(t,"#link-authentication-element");return r.mount(s),r.on("change",(t=>{var e;this.store.set("email",null===(e=t.value)||void 0===e?void 0:e.email),this.store.set("complete",t.complete)})),this.linkAuthenticationElement=r,this.linkAuthenticationElement}getElement(){return this.linkAuthenticationElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.linkAuthenticationElement&&(this.linkAuthenticationElement.unmount(),this.linkAuthenticationElement=void 0)}}class p{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",selectedCurrency:void 0})}getState(){return this.store.state}async initialize(t,e){const i=this.stripeService.getElements();if(null==i)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.currencySelectorElement&&this.unmount();const r=await c(t,"#currency-selector");return this.currencySelectorElement=i.create("currencySelector",e||{}),this.currencySelectorElement.mount(r),this.currencySelectorElement.on("change",(t=>{var e;this.store.set("errorMessage",""),(null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.currency)&&this.store.set("selectedCurrency",t.value.currency)})),this.currencySelectorElement}getElement(){return this.currencySelectorElement}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.currencySelectorElement&&(this.currencySelectorElement.unmount(),this.currencySelectorElement=void 0)}}var g=function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(i[r[s]]=t[r[s]])}return i};class m{constructor(t){this.stripeService=t,this.store=l({errorMessage:"",isReady:!1})}getState(){return this.store.state}async initialize(t,e,i){const r=this.stripeService.getElements();if(null==r)throw new Error("StripeService not initialized. Call StripeService.initialize() first.");null!=this.expressCheckoutElement&&this.unmount();const s=g(e,["mode","amount","currency"]),n=Object.assign({},s);if(n.buttonHeight&&"string"==typeof n.buttonHeight){const t=parseInt(n.buttonHeight.replace("px",""),10);isNaN(t)||(n.buttonHeight=t)}const o=r.create("expressCheckout",n),l=await c(t,"#express-checkout-element");return null!=(null==i?void 0:i.onConfirm)&&o.on("confirm",i.onConfirm),null!=(null==i?void 0:i.onClick)&&o.on("click",i.onClick),null!=(null==i?void 0:i.onCancel)&&o.on("cancel",i.onCancel),null!=(null==i?void 0:i.onShippingAddressChange)&&o.on("shippingaddresschange",i.onShippingAddressChange),null!=(null==i?void 0:i.onShippingRateChange)&&o.on("shippingratechange",i.onShippingRateChange),o.on("ready",(()=>{this.store.set("isReady",!0)})),o.mount(l),this.expressCheckoutElement=o,this.expressCheckoutElement}getElement(){return this.expressCheckoutElement}update(t){var e;if(null==this.expressCheckoutElement)return void console.warn("Express Checkout Element not initialized. Cannot update options.");const{mode:i,amount:r,currency:s}=t,n=g(t,["mode","amount","currency"]),o={};void 0!==i&&(o.mode=i),void 0!==r&&(o.amount=r),void 0!==s&&(o.currency=s),Object.keys(o).length>0&&(null===(e=this.stripeService.getElements())||void 0===e||e.update(o));const l=Object.assign({},n);if(l.buttonHeight&&"string"==typeof l.buttonHeight){const t=parseInt(l.buttonHeight.replace("px",""),10);isNaN(t)||(l.buttonHeight=t)}0!==Object.keys(l).length&&this.expressCheckoutElement.update(l)}setError(t){this.store.set("errorMessage",t)}clearError(){this.store.set("errorMessage","")}unmount(){null!=this.expressCheckoutElement&&(this.expressCheckoutElement.unmount(),this.expressCheckoutElement=void 0,this.store.set("isReady",!1))}}const f=new class{createStripeService(){return new a}createCardElementManager(t){return new h(t)}createPaymentElementManager(t){return new u(t)}createAddressElementManager(t){return new d(t)}createLinkAuthenticationElementManager(t){return new v(t)}createCurrencySelectorElementManager(t){return new p(t)}createExpressCheckoutElementManager(t){return new m(t)}};export{c as f,f as s}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e}from"./error.js";const r=e=>{const
|
|
1
|
+
import{S as e}from"./error.js";const r=e=>{const r=e instanceof Error?e.message:null==e?void 0:e.message;return"string"==typeof r&&r.includes("cannot provide `returnUrl`")},t=(r,t)=>{if(null!=r&&"open"!==r.type)throw new e({type:"invalid_request_error",code:`checkout_session_${r.type}`,message:null!=t?t:`The Checkout Session is ${r.type} and can no longer be paid.`})},o=async(o,n,s)=>{const i=await o.loadActions();if("error"===i.type)throw new e({type:"api_error",code:"checkout_session_error",message:i.error.message});const{actions:c}=i,a=()=>{var e,r;return null===(r=null===(e=c.getSession)||void 0===e?void 0:e.call(c))||void 0===r?void 0:r.status};t(a());const l=e=>c.confirm(Object.assign(Object.assign({redirect:"if_required"},e&&""!==n?{returnUrl:n}:{}),null!=s&&""!==s?{email:s}:{}));let u;try{u=await l(!0),"error"===u.type&&r(u.error)&&(u=await l(!1))}catch(e){if(!r(e))throw e;u=await l(!1)}if("error"===u.type){const{code:r,message:o}=u.error;if(t(a(),o),"paymentFailed"===r)throw new e({type:"card_error",code:r,message:o});throw new e({type:"api_error",code:"checkout_session_error",message:o})}return u},n=e=>{const{progress:r,isCheckoutSession:t,loadStripeStatus:o,intentClientSecret:n}=e;return"loading"===r||"success"===r||!(t?"success"===o:null!=n&&""!==n)},s=async(r,t,o,n,s)=>{const i=await("payment"===o?r.confirmPayment({elements:t,confirmParams:Object.assign({return_url:n},s),redirect:"if_required"}):r.confirmSetup({elements:t,confirmParams:Object.assign({return_url:n},s),redirect:"if_required"}));if(i.error)throw new e(i.error);return i},i=async(e,r,t)=>o(e,r,t),c=e=>{const{stripe:r,isCheckoutSession:t,checkout:o,checkoutSessionClientSecret:n,elements:s,intentClientSecret:i}=e,c={stripe:r};return t?null==o?{error:"Checkout not properly initialized"}:(c.checkout=o,c.checkoutSessionClientSecret=n,{props:c}):null==s?{error:"Elements not properly initialized"}:(c.elements=s,c.intentClientSecret=i,{props:c})};export{i as a,c as b,s as c,o as d,n 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 o,i as r}from"./i18n.js";import{s as a}from"./factory.js";import{b as c,c as l,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}),"success"===this.progress&&(this.progress=""))}async updateCheckoutSessionClientSecret(t){null!=this.publishableKey&&""!==this.publishableKey&&null!=t&&""!==t&&(await this.initStripeWithCheckoutSession(this.publishableKey,t,{stripeAccount:this.stripeAccount}),"success"===this.progress&&(this.progress=""))}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async formSubmitEventHandler(){const t=this.stripeService.getStripe(),e=!0===this.stripeService.state.isCheckoutSession;if(null==t)return void console.error("Stripe not properly initialized");const i=c({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 l(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=c({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
|
+
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,defaultValues:null==i?void 0:i.defaultValues}),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,defaultValues:this.checkoutSessionDefaultValues}):this.initStripe(t,i?e:void 0)}updateStripeAccountId(t){this.hasCheckoutSessionClientSecret()?this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey,this.checkoutSessionClientSecret,{stripeAccount:t,defaultValues:this.checkoutSessionDefaultValues}):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}),"success"===this.progress&&(this.progress=""))}async updateCheckoutSessionClientSecret(t){null!=this.publishableKey&&""!==this.publishableKey&&null!=t&&""!==t&&(await this.initStripeWithCheckoutSession(this.publishableKey,t,{stripeAccount:this.stripeAccount,defaultValues:this.checkoutSessionDefaultValues}),"success"===this.progress&&(this.progress=""))}stripeLoadedEventHandler(){const t={stripe:this.stripeService.getStripe()};null!=this.stripeDidLoaded&&this.stripeDidLoaded(t),this.stripeLoaded.emit(t)}async formSubmitEventHandler(){const t=this.stripeService.getStripe(),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,defaultValues:this.checkoutSessionDefaultValues})))}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){var i;t.preventDefault();try{const t=await h(e,null!==(i=this.checkoutSessionReturnUrl)&&void 0!==i?i:window.location.href,this.checkoutSessionEmail);this.checkoutSessionConfirmResultHandler(t)}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,defaultValues:this.checkoutSessionDefaultValues}))}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"],checkoutSessionReturnUrl:[1,"checkout-session-return-url"],checkoutSessionEmail:[1,"checkout-session-email"],checkoutSessionDefaultValues:[16],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 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}
|
|
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 o,i as r}from"./i18n.js";import{s as l,f as c}from"./factory.js";import{d,c as h}from"./stripe-payment-element.helpers.js";import{d as p}from"./icon.js";import{d as u}from"./stripe-modal2.js";const f={phase:"idle",generation:0,pendingPresent:!1,openRequested:!1},m=[[/^pi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/,"payment"],[/^seti_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/,"setup"]],b=e=>({state:e,effects:[]}),y=(e,t)=>e.pendingPresent?{state:Object.assign(Object.assign({},e),{pendingPresent:!1}),effects:[{type:"resolvePresent",result:t}]}:b(e),v=e=>{const t=y(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 b(e);if("confirming"===e.phase)return b(Object.assign(Object.assign({},e),{deferredSecret:{clientSecret:t,source:i}}));const n="presented"===e.phase?v(e):b(e),s=e.generation+1,a=((e,t)=>"checkoutSession"===t?"checkoutSession":(e=>{const t=m.find((([t])=>t.test(e)));return null==t?void 0:t[1]})(e))(t,i);if(null==a){const e=y(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))),D=e=>{const{postalCode:t}=e,i=j(e,["postalCode"]);return x(Object.assign(Object.assign({},i),{postal_code:t}))},P=e=>null==e?void 0:e?"auto":"never",F=e=>{if(null==e)return{};const{merchantDisplayName:t,paymentMethodLayout:i,defaultBillingDetails:n,billingDetailsCollectionConfiguration:s,enableApplePay:a,enableGooglePay:o}=e,r={},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:P(a),googlePay:P(o)});if(null!=l&&(r.fields={billingDetails:l}),Object.keys(c).length>0&&(r.wallets=c),null!=t&&(r.business={name:t}),null!=i&&(r.layout=k[i]),null!=n){const{address:e}=n,t=j(n,["address"]),i=x(t);null!=e&&(i.address=D(e)),r.defaultValues={billingDetails:i}}return r},_=e=>{if(null!=e)return{theme:C[e]}},E=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({},D(n)),{country:s})})},R=e=>null==e||""===e,q=(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=>{var t,i;const n=null==e?void 0:e.defaultBillingDetails;if(null==n)return;const s={};null!=n.email&&""!==n.email&&(s.email=n.email),null!=n.phone&&""!==n.phone&&(s.phoneNumber=n.phone);const a=null===(t=n.address)||void 0===t?void 0:t.country;if(null!=a&&""!==a){const e=n.address,t=(e=>Object.fromEntries(Object.entries(e).filter((([,e])=>void 0!==e))))({country:a,line1:null==e?void 0:e.line1,line2:null==e?void 0:e.line2,city:null==e?void 0:e.city,postal_code:null==e?void 0:e.postalCode,state:null==e?void 0:e.state}),o={name:null!==(i=n.name)&&void 0!==i?i:null,address:t};s.billingAddress=o}return 0===Object.keys(s).length?void 0:s},N=e=>{const t=_(null==e?void 0:e.style);return null==t?void 0:{appearance:t}},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=f,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(o())}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 b(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 b(e);const i=y(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 b(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 b(Object.assign(Object.assign({},e),{pendingPresent:!0,openRequested:!0}));case"presented":case"confirming":return b(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"}]}:b("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?b(e):v(e);case"submitted":return"presented"!==e.phase||null==e.intentKind?b(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 b(e);const i=y(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}]}):b(e);case"confirmFailed":{if(!S(e,t.generation))return b(e);const i=y(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,o,r,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(R(d[e]))throw q(e,e);h[e]=d[e]}})),"never"===c.address){const e=d.address;if(null==e||R(e.country))throw q("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!==(o=e.city)&&void 0!==o?o:"",state:null!==(r=e.state)&&void 0!==r?r:"",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:E(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=R(d.email)?{}:{defaultValues:{email:d.email}});const f=null==e?void 0:e.shippingDetails;if(null!=f&&"payment"===t){const e={mode:"shipping",defaultValues:E(f)};R(f.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 o=_(null===(n=this.options)||void 0===n?void 0:n.style);if(null!=o&&(await this.stripeService.getElements().update({appearance:o}),s()))return;if(!await this.mountExtraElements(a,s))return;await this.paymentElementManager.initialize(this.el,F(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(R(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,o=await this.confirmParams();return h(this.stripeService.getStripe(),n,t,a,o)}))}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)?r.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:N(this.options),defaultValues: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}=F(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)=>d(e,t,i))(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=>{var t;if(null==e)return[];const{merchantDisplayName:i,defaultBillingDetails:n}=e,s=[],a=null===(t=null==n?void 0:n.address)||void 0===t?void 0:t.country;if(!(null==(null==n?void 0:n.name)&&null==(null==n?void 0:n.address)||null!=a&&""!==a))for(const e of["name","address"])null!=(null==n?void 0:n[e])&&s.push("defaultBillingDetails."+e);return null!=i&&s.push("merchantDisplayName"),["billingDetailsCollectionConfiguration","shippingDetails","enableApplePay","enableGooglePay"].filter((t=>void 0!==e[t])).forEach((e=>s.push(e))),s.sort()})(this.options);this.warnedCheckoutIgnoredOptions||0===e.length||(this.warnedCheckoutIgnoredOptions=!0,console.warn("<stripe-payment-sheet>: these options have no effect with a Checkout Session: "+e.join(", ")))}render(){var e,t,i;const{phase:n}=this.sheet,o="confirming"===n;return s(a,{key:"52591afbd5af5ceb2530a37248e3bb1f410f880c"},s("stripe-modal",{key:"607c26d28f381b5017f9714fca398c2f5eb9c066",open:this.visible,showCloseButton:!o,onClose:this.handleModalClose},s("div",{key:"44cfb1929b178257878d5a42d8441b2f7f823436",class:"stripe-payment-sheet-wrap"},s("form",{key:"20be8d4cb150883936241639c299a86d081c1903",id:"stripe-payment-sheet",onSubmit:this.handleSubmit},s("div",{key:"14e5c98793de6d2ebb1a1cc755e501b427915d9f",class:"stripe-heading"},r.t(this.sheetTitle)),s("div",{key:"235ac34c0c2260793756960caa75ef9f62e401fd",class:"payment-info visible"},s("div",{key:"10ed4c9be02a08429b8bfd028f40be409613250b",class:"stripe-payment-sheet-email"},null!=(null===(e=this.collection)||void 0===e?void 0:e.emailElement)&&s("div",{key:"5a21882fc11b839287bd499f9441b7a37b2f7e4d",id:"link-authentication-element"})),s("div",{key:"d88e637fcecc62bba18fc25cdf674a03624ceb8a",class:"stripe-payment-sheet-shipping-address"},null!=(null===(t=this.collection)||void 0===t?void 0:t.shippingAddressElement)&&s("div",{key:"934f6b59ce787c6452191f1df14b1848f847db4a",id:"address-element"})),s("div",{key:"1fe9f0371e0669c6b5485b19672ee02169312674",class:"stripe-payment-sheet-billing-address"},null!=(null===(i=this.collection)||void 0===i?void 0:i.billingAddressElement)&&s("div",{key:"fb548084588b34ffcd8534cc2b0a402e1af60d76",id:"address-element"})),s("div",{key:"8dec277132c63cc11c49962f136b67685e810ccb",id:"payment-element"})),s("div",{key:"e0f20ba527fb9b941cc8d70d7631a03dcfc2c370",class:"stripe-element-errors",role:"alert"},this.errorMessage),s("div",{key:"db7357b49c141ff9272f1b4690f933ea54d9bfb3",class:"stripe-submit"},s("button",{key:"9112ed21047df0b2fdfa5f8d6b7872f878062dc1",type:"submit",disabled:"presented"!==n},r.t(o?"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 V=K,$=T;export{V as StripePaymentSheet,$ as defineCustomElement}
|
|
@@ -413,6 +413,7 @@ class StripeServiceClass {
|
|
|
413
413
|
const checkout = stripe.initCheckoutElementsSdk({
|
|
414
414
|
clientSecret: checkoutSessionClientSecret,
|
|
415
415
|
elementsOptions: options === null || options === void 0 ? void 0 : options.elementsOptions,
|
|
416
|
+
defaultValues: options === null || options === void 0 ? void 0 : options.defaultValues,
|
|
416
417
|
});
|
|
417
418
|
this.store.state.checkout = checkout;
|
|
418
419
|
this.store.state.elements = undefined;
|
package/dist/esm/loader.js
CHANGED
|
@@ -5,7 +5,7 @@ import { g as globalScripts } from './app-globals-DQuL1Twl.js';
|
|
|
5
5
|
const defineCustomElements = async (win, options) => {
|
|
6
6
|
if (typeof window === 'undefined') return undefined;
|
|
7
7
|
await globalScripts();
|
|
8
|
-
return bootstrapLazy([["stripe-card-element-modal",[[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]}]]],["stripe-payment-sheet",[[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]},null,{"publishableKey":[{"handleSecretChange":0}],"intentClientSecret":[{"handleSecretChange":0}],"checkoutSessionClientSecret":[{"handleSecretChange":0}],"stripeAccount":[{"handleSecretChange":0}],"open":[{"handleOpenChange":0}]}]]],["stripe-address-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-currency-selector",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-express-checkout-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-link-authentication-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-payment-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}],"intentClientSecret":[{"updateIntentClientSecret":0}],"checkoutSessionClientSecret":[{"updateCheckoutSessionClientSecret":0}]}]]],["stripe-payment-request-button",[[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]}]]],["stripe-card-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}],"intentClientSecret":[{"updateIntentClientSecret":0}]}]]],["ion-icon_2",[[257,"stripe-modal",{"showCloseButton":[4,"show-close-button"],"open":[1028],"renderedOpen":[32],"toggleModal":[64],"openModal":[64],"closeModal":[64]},null,{"open":[{"onOpenChange":0}]}],[1,"ion-icon",{"mode":[1025],"color":[1],"ios":[1],"md":[1],"flipRtl":[4,"flip-rtl"],"name":[513],"src":[1],"icon":[8],"size":[1],"lazy":[4],"sanitize":[4],"svgContent":[32],"isVisible":[32]},null,{"name":[{"loadIcon":0}],"src":[{"loadIcon":0}],"icon":[{"loadIcon":0}],"ios":[{"loadIcon":0}],"md":[{"loadIcon":0}]}]]]], options);
|
|
8
|
+
return bootstrapLazy([["stripe-card-element-modal",[[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]}]]],["stripe-payment-sheet",[[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]},null,{"publishableKey":[{"handleSecretChange":0}],"intentClientSecret":[{"handleSecretChange":0}],"checkoutSessionClientSecret":[{"handleSecretChange":0}],"stripeAccount":[{"handleSecretChange":0}],"open":[{"handleOpenChange":0}]}]]],["stripe-address-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-currency-selector",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-express-checkout-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-link-authentication-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-payment-element",[[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"],"checkoutSessionReturnUrl":[1,"checkout-session-return-url"],"checkoutSessionEmail":[1,"checkout-session-email"],"checkoutSessionDefaultValues":[16],"handleSubmit":[1040],"stripeDidLoaded":[1040],"progress":[32],"initStripe":[64],"initStripeWithCheckoutSession":[64],"updateProgress":[64],"setErrorMessage":[64]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}],"intentClientSecret":[{"updateIntentClientSecret":0}],"checkoutSessionClientSecret":[{"updateCheckoutSessionClientSecret":0}]}]]],["stripe-payment-request-button",[[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]}]]],["stripe-card-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}],"intentClientSecret":[{"updateIntentClientSecret":0}]}]]],["ion-icon_2",[[257,"stripe-modal",{"showCloseButton":[4,"show-close-button"],"open":[1028],"renderedOpen":[32],"toggleModal":[64],"openModal":[64],"closeModal":[64]},null,{"open":[{"onOpenChange":0}]}],[1,"ion-icon",{"mode":[1025],"color":[1],"ios":[1],"md":[1],"flipRtl":[4,"flip-rtl"],"name":[513],"src":[1],"icon":[8],"size":[1],"lazy":[4],"sanitize":[4],"svgContent":[32],"isVisible":[32]},null,{"name":[{"loadIcon":0}],"src":[{"loadIcon":0}],"icon":[{"loadIcon":0}],"ios":[{"loadIcon":0}],"md":[{"loadIcon":0}]}]]]], options);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export { defineCustomElements };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, a as createEvent, h, g as getElement } from './index-C6bbmyga.js';
|
|
2
2
|
import { c as checkPlatform, i as i18n } from './i18n-HWdALSvT.js';
|
|
3
|
-
import { s as serviceFactory } from './factory-
|
|
3
|
+
import { s as serviceFactory } from './factory-B_WxdnxM.js';
|
|
4
4
|
import './index-CBXaOfXU.js';
|
|
5
5
|
|
|
6
6
|
const stripeAddressElementCss = () => `: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)}`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, a as createEvent, h, g as getElement } from './index-C6bbmyga.js';
|
|
2
2
|
import { c as checkPlatform, i as i18n } from './i18n-HWdALSvT.js';
|
|
3
|
-
import { s as serviceFactory } from './factory-
|
|
3
|
+
import { s as serviceFactory } from './factory-B_WxdnxM.js';
|
|
4
4
|
import { S as StripeAPIError } from './error-XRfh5Wrs.js';
|
|
5
5
|
import './index-CBXaOfXU.js';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, a as createEvent, h, g as getElement } from './index-C6bbmyga.js';
|
|
2
2
|
import { c as checkPlatform, i as i18n } from './i18n-HWdALSvT.js';
|
|
3
|
-
import { s as serviceFactory } from './factory-
|
|
3
|
+
import { s as serviceFactory } from './factory-B_WxdnxM.js';
|
|
4
4
|
import './index-CBXaOfXU.js';
|
|
5
5
|
|
|
6
6
|
const stripeCurrencySelectorCss = () => `: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}`;
|
|
@@ -44,5 +44,5 @@ var patchCloneNodeFix = (HTMLElementPrototype) => {
|
|
|
44
44
|
|
|
45
45
|
patchBrowser().then(async (options) => {
|
|
46
46
|
await globalScripts();
|
|
47
|
-
return bootstrapLazy([["stripe-card-element-modal",[[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]}]]],["stripe-payment-sheet",[[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]},null,{"publishableKey":[{"handleSecretChange":0}],"intentClientSecret":[{"handleSecretChange":0}],"checkoutSessionClientSecret":[{"handleSecretChange":0}],"stripeAccount":[{"handleSecretChange":0}],"open":[{"handleOpenChange":0}]}]]],["stripe-address-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-currency-selector",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-express-checkout-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-link-authentication-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-payment-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}],"intentClientSecret":[{"updateIntentClientSecret":0}],"checkoutSessionClientSecret":[{"updateCheckoutSessionClientSecret":0}]}]]],["stripe-payment-request-button",[[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]}]]],["stripe-card-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}],"intentClientSecret":[{"updateIntentClientSecret":0}]}]]],["ion-icon_2",[[257,"stripe-modal",{"showCloseButton":[4,"show-close-button"],"open":[1028],"renderedOpen":[32],"toggleModal":[64],"openModal":[64],"closeModal":[64]},null,{"open":[{"onOpenChange":0}]}],[1,"ion-icon",{"mode":[1025],"color":[1],"ios":[1],"md":[1],"flipRtl":[4,"flip-rtl"],"name":[513],"src":[1],"icon":[8],"size":[1],"lazy":[4],"sanitize":[4],"svgContent":[32],"isVisible":[32]},null,{"name":[{"loadIcon":0}],"src":[{"loadIcon":0}],"icon":[{"loadIcon":0}],"ios":[{"loadIcon":0}],"md":[{"loadIcon":0}]}]]]], options);
|
|
47
|
+
return bootstrapLazy([["stripe-card-element-modal",[[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]}]]],["stripe-payment-sheet",[[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]},null,{"publishableKey":[{"handleSecretChange":0}],"intentClientSecret":[{"handleSecretChange":0}],"checkoutSessionClientSecret":[{"handleSecretChange":0}],"stripeAccount":[{"handleSecretChange":0}],"open":[{"handleOpenChange":0}]}]]],["stripe-address-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-currency-selector",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-express-checkout-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-link-authentication-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}]}]]],["stripe-payment-element",[[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"],"checkoutSessionReturnUrl":[1,"checkout-session-return-url"],"checkoutSessionEmail":[1,"checkout-session-email"],"checkoutSessionDefaultValues":[16],"handleSubmit":[1040],"stripeDidLoaded":[1040],"progress":[32],"initStripe":[64],"initStripeWithCheckoutSession":[64],"updateProgress":[64],"setErrorMessage":[64]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}],"intentClientSecret":[{"updateIntentClientSecret":0}],"checkoutSessionClientSecret":[{"updateCheckoutSessionClientSecret":0}]}]]],["stripe-payment-request-button",[[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]}]]],["stripe-card-element",[[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]},null,{"publishableKey":[{"updatePublishableKey":0}],"stripeAccount":[{"updateStripeAccountId":0}],"intentClientSecret":[{"updateIntentClientSecret":0}]}]]],["ion-icon_2",[[257,"stripe-modal",{"showCloseButton":[4,"show-close-button"],"open":[1028],"renderedOpen":[32],"toggleModal":[64],"openModal":[64],"closeModal":[64]},null,{"open":[{"onOpenChange":0}]}],[1,"ion-icon",{"mode":[1025],"color":[1],"ios":[1],"md":[1],"flipRtl":[4,"flip-rtl"],"name":[513],"src":[1],"icon":[8],"size":[1],"lazy":[4],"sanitize":[4],"svgContent":[32],"isVisible":[32]},null,{"name":[{"loadIcon":0}],"src":[{"loadIcon":0}],"icon":[{"loadIcon":0}],"ios":[{"loadIcon":0}],"md":[{"loadIcon":0}]}]]]], options);
|
|
48
48
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, a as createEvent, h, g as getElement } from './index-C6bbmyga.js';
|
|
2
2
|
import { c as checkPlatform, i as i18n } from './i18n-HWdALSvT.js';
|
|
3
|
-
import { s as serviceFactory } from './factory-
|
|
3
|
+
import { s as serviceFactory } from './factory-B_WxdnxM.js';
|
|
4
4
|
import { S as StripeAPIError } from './error-XRfh5Wrs.js';
|
|
5
5
|
import './index-CBXaOfXU.js';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, a as createEvent, h, g as getElement } from './index-C6bbmyga.js';
|
|
2
2
|
import { c as checkPlatform, i as i18n } from './i18n-HWdALSvT.js';
|
|
3
|
-
import { s as serviceFactory } from './factory-
|
|
3
|
+
import { s as serviceFactory } from './factory-B_WxdnxM.js';
|
|
4
4
|
import './index-CBXaOfXU.js';
|
|
5
5
|
|
|
6
6
|
const stripeLinkAuthenticationElementCss = () => `: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)}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as registerInstance, a as createEvent, h, g as getElement } from './index-C6bbmyga.js';
|
|
2
2
|
import { c as checkPlatform, i as i18n } from './i18n-HWdALSvT.js';
|
|
3
|
-
import { s as serviceFactory } from './factory-
|
|
4
|
-
import { b as buildSubmitEventProps, c as confirmPaymentOrSetup, a as confirmCheckoutSession, i as isSubmitButtonDisabled } from './stripe-payment-element.helpers-
|
|
3
|
+
import { s as serviceFactory } from './factory-B_WxdnxM.js';
|
|
4
|
+
import { b as buildSubmitEventProps, c as confirmPaymentOrSetup, a as confirmCheckoutSession, i as isSubmitButtonDisabled } from './stripe-payment-element.helpers-PuWxhMNR.js';
|
|
5
5
|
import './index-CBXaOfXU.js';
|
|
6
6
|
import './error-XRfh5Wrs.js';
|
|
7
7
|
|
|
@@ -57,6 +57,7 @@ const StripePaymentElement = class {
|
|
|
57
57
|
stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
|
|
58
58
|
applicationName: this.applicationName,
|
|
59
59
|
elementsOptions: options === null || options === void 0 ? void 0 : options.elementsOptions,
|
|
60
|
+
defaultValues: options === null || options === void 0 ? void 0 : options.defaultValues,
|
|
60
61
|
});
|
|
61
62
|
await this.mountWhenLoaded(generation);
|
|
62
63
|
}
|
|
@@ -101,14 +102,20 @@ const StripePaymentElement = class {
|
|
|
101
102
|
options.stripeAccount = this.stripeService.state.stripeAccount;
|
|
102
103
|
const hasOptionValue = Object.values(options).filter(value => value != null && value !== '').length > 0;
|
|
103
104
|
if (this.hasCheckoutSessionClientSecret()) {
|
|
104
|
-
this.initStripeWithCheckoutSession(publishableKey, this.checkoutSessionClientSecret, {
|
|
105
|
+
this.initStripeWithCheckoutSession(publishableKey, this.checkoutSessionClientSecret, {
|
|
106
|
+
stripeAccount: options.stripeAccount,
|
|
107
|
+
defaultValues: this.checkoutSessionDefaultValues,
|
|
108
|
+
});
|
|
105
109
|
return;
|
|
106
110
|
}
|
|
107
111
|
this.initStripe(publishableKey, hasOptionValue ? options : undefined);
|
|
108
112
|
}
|
|
109
113
|
updateStripeAccountId(stripeAccount) {
|
|
110
114
|
if (this.hasCheckoutSessionClientSecret()) {
|
|
111
|
-
this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
|
|
115
|
+
this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
|
|
116
|
+
stripeAccount: stripeAccount,
|
|
117
|
+
defaultValues: this.checkoutSessionDefaultValues,
|
|
118
|
+
});
|
|
112
119
|
return;
|
|
113
120
|
}
|
|
114
121
|
this.initStripe(this.stripeService.state.publishableKey, {
|
|
@@ -136,6 +143,7 @@ const StripePaymentElement = class {
|
|
|
136
143
|
if (this.publishableKey != null && this.publishableKey !== '' && newValue != null && newValue !== '') {
|
|
137
144
|
await this.initStripeWithCheckoutSession(this.publishableKey, newValue, {
|
|
138
145
|
stripeAccount: this.stripeAccount,
|
|
146
|
+
defaultValues: this.checkoutSessionDefaultValues,
|
|
139
147
|
});
|
|
140
148
|
// A new secret starts a fresh payment, so re-enable the submit button after a previous success
|
|
141
149
|
if (this.progress === 'success') {
|
|
@@ -191,6 +199,7 @@ const StripePaymentElement = class {
|
|
|
191
199
|
if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
|
|
192
200
|
this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
|
|
193
201
|
stripeAccount: this.stripeService.state.stripeAccount,
|
|
202
|
+
defaultValues: this.checkoutSessionDefaultValues,
|
|
194
203
|
});
|
|
195
204
|
return;
|
|
196
205
|
}
|
|
@@ -226,11 +235,12 @@ const StripePaymentElement = class {
|
|
|
226
235
|
* @param checkout - The Stripe Checkout instance
|
|
227
236
|
*/
|
|
228
237
|
async checkoutSessionFormSubmitAction(event, checkout) {
|
|
238
|
+
var _a;
|
|
229
239
|
event.preventDefault();
|
|
230
240
|
try {
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
const result = await confirmCheckoutSession(checkout,
|
|
241
|
+
// returnUrl defaults to the current page; confirmCheckoutSession retries without it when the
|
|
242
|
+
// session was created with `return_url` (which rejects the argument before processing)
|
|
243
|
+
const result = await confirmCheckoutSession(checkout, (_a = this.checkoutSessionReturnUrl) !== null && _a !== void 0 ? _a : window.location.href, this.checkoutSessionEmail);
|
|
234
244
|
this.checkoutSessionConfirmResultHandler(result);
|
|
235
245
|
}
|
|
236
246
|
catch (e) {
|
|
@@ -347,6 +357,7 @@ const StripePaymentElement = class {
|
|
|
347
357
|
if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
|
|
348
358
|
this.initStripeWithCheckoutSession(this.publishableKey, this.checkoutSessionClientSecret, {
|
|
349
359
|
stripeAccount: this.stripeAccount,
|
|
360
|
+
defaultValues: this.checkoutSessionDefaultValues,
|
|
350
361
|
});
|
|
351
362
|
return;
|
|
352
363
|
}
|