stripe-pwa-elements 4.0.5 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/cjs/{factory-xOoxnMhx.js → factory-yd5HDEZn.js} +1 -0
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/stripe-address-element.cjs.entry.js +1 -1
  4. package/dist/cjs/stripe-card-element.cjs.entry.js +1 -1
  5. package/dist/cjs/stripe-currency-selector.cjs.entry.js +1 -1
  6. package/dist/cjs/stripe-elements.cjs.js +1 -1
  7. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +1 -1
  8. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +1 -1
  9. package/dist/cjs/stripe-payment-element.cjs.entry.js +18 -7
  10. package/dist/cjs/stripe-payment-element.helpers-D1JnhTa-.js +182 -0
  11. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +72 -57
  12. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +9 -32
  13. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +87 -5
  14. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +60 -48
  15. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +5 -2
  16. package/dist/collection/services/stripe-service.js +1 -0
  17. package/dist/collection/utils/checkout-confirm.js +84 -0
  18. package/dist/components/factory.js +1 -1
  19. package/dist/components/stripe-payment-element.helpers.js +1 -1
  20. package/dist/components/stripe-payment-element.js +1 -1
  21. package/dist/components/stripe-payment-sheet.js +1 -1
  22. package/dist/esm/{factory-CsurRVcp.js → factory-B_WxdnxM.js} +1 -0
  23. package/dist/esm/loader.js +1 -1
  24. package/dist/esm/stripe-address-element.entry.js +1 -1
  25. package/dist/esm/stripe-card-element.entry.js +1 -1
  26. package/dist/esm/stripe-currency-selector.entry.js +1 -1
  27. package/dist/esm/stripe-elements.js +1 -1
  28. package/dist/esm/stripe-express-checkout-element.entry.js +1 -1
  29. package/dist/esm/stripe-link-authentication-element.entry.js +1 -1
  30. package/dist/esm/stripe-payment-element.entry.js +18 -7
  31. package/dist/esm/stripe-payment-element.helpers-PuWxhMNR.js +176 -0
  32. package/dist/esm/stripe-payment-sheet.entry.js +72 -57
  33. package/dist/stripe-elements/{p-949a8bba.entry.js → p-2e2bf0fe.entry.js} +1 -1
  34. package/dist/stripe-elements/{p-b0f9ebba.entry.js → p-32a2d5a4.entry.js} +1 -1
  35. package/dist/stripe-elements/{p-edbbe060.entry.js → p-84d45b48.entry.js} +1 -1
  36. package/dist/stripe-elements/{p-a2d11152.entry.js → p-a266da6f.entry.js} +1 -1
  37. package/dist/stripe-elements/p-c4a0e310.entry.js +1 -0
  38. package/dist/stripe-elements/{p-50e495e3.entry.js → p-e660d76a.entry.js} +1 -1
  39. package/dist/stripe-elements/p-eeebfbbf.entry.js +1 -0
  40. package/dist/stripe-elements/p-n0XJSLU3.js +1 -0
  41. package/dist/stripe-elements/p-wrjrFokg.js +1 -0
  42. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  43. package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +33 -0
  44. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +8 -2
  45. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +19 -11
  46. package/dist/types/components.d.ts +34 -2
  47. package/dist/types/services/interfaces.d.ts +3 -1
  48. package/dist/types/utils/checkout-confirm.d.ts +35 -0
  49. package/package.json +1 -1
  50. package/dist/cjs/stripe-payment-element.helpers-lafmSRmb.js +0 -121
  51. package/dist/esm/stripe-payment-element.helpers-CklK5RlF.js +0 -116
  52. package/dist/stripe-elements/p-855d1aee.entry.js +0 -1
  53. package/dist/stripe-elements/p-B2G-wquO.js +0 -1
  54. package/dist/stripe-elements/p-BoZLkOAy.js +0 -1
  55. package/dist/stripe-elements/p-a45268d4.entry.js +0 -1
@@ -0,0 +1 @@
1
+ import{r as e,a as t,h as i,d as n,g as s}from"./p-C6bbmyga.js";import{c as a,i as r}from"./p-HWdALSvT.js";import{s as o,f as l}from"./p-n0XJSLU3.js";import{d as c,c as d}from"./p-wrjrFokg.js";import"./p-CBXaOfXU.js";import"./p-XRfh5Wrs.js";const h={phase:"idle",generation:0,pendingPresent:!1,openRequested:!1},p=[[/^pi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/,"payment"],[/^seti_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/,"setup"]],u=e=>({state:e,effects:[]}),f=(e,t)=>e.pendingPresent?{state:Object.assign(Object.assign({},e),{pendingPresent:!1}),effects:[{type:"resolvePresent",result:t}]}:u(e),m=e=>{const t=f(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]}},b=(e,t,i)=>{if(""===t)return u(e);if("confirming"===e.phase)return u(Object.assign(Object.assign({},e),{deferredSecret:{clientSecret:t,source:i}}));const n="presented"===e.phase?m(e):u(e),s=e.generation+1,a=((e,t)=>"checkoutSession"===t?"checkoutSession":(e=>{const t=p.find((([t])=>t.test(e)));return null==t?void 0:t[1]})(e))(t,i);if(null==a){const e=f(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}]}},y=e=>{const{deferredSecret:t}=e.state;if(null==t)return e;const i=b(Object.assign(Object.assign({},e.state),{deferredSecret:void 0}),t.clientSecret,t.source);return{state:i.state,effects:[...e.effects,...i.effects]}},v=(e,t)=>"confirming"===e.phase&&e.generation===t;var g=function(e,t){var i={};for(var 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 w=["merchantDisplayName","paymentMethodLayout","defaultBillingDetails","returnURL","style","billingDetailsCollectionConfiguration","shippingDetails","enableApplePay","enableGooglePay"],j={horizontal:"tabs",vertical:"accordion",automatic:"auto"},O={alwaysLight:"stripe",alwaysDark:"night"},S=e=>Object.fromEntries(Object.entries(e).filter((([,e])=>void 0!==e))),k=e=>{const{postalCode:t}=e,i=g(e,["postalCode"]);return S(Object.assign(Object.assign({},i),{postal_code:t}))},C=e=>null==e?void 0:e?"auto":"never",x=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=S({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=S({applePay:C(a),googlePay:C(r)});if(null!=l&&(o.fields={billingDetails:l}),Object.keys(c).length>0&&(o.wallets=c),null!=t&&(o.business={name:t}),null!=i&&(o.layout=j[i]),null!=n){const{address:e}=n,t=g(n,["address"]),i=S(t);null!=e&&(i.address=k(e)),o.defaultValues={billingDetails:i}}return o},D=e=>{if(null!=e)return{theme:O[e]}},P=e=>{const{name:t,phone:i,address:n}=e,s=null==n?void 0:n.country;return S({name:t,phone:i,address:null==s||""===s?void 0:Object.assign(Object.assign({},k(n)),{country:s})})},F=e=>null==e||""===e,_=(e,t)=>new Error(`<stripe-payment-sheet>: billingDetailsCollectionConfiguration.${e} is 'never', so defaultBillingDetails.${t} is required`),R=e=>Object.assign(new Error(e),{type:"validation_error",sheetValidation:!0}),q=["card_error","validation_error","api_connection_error","rate_limit_error","api_error"],L=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=Object.fromEntries(Object.entries({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}).filter((([,e])=>void 0!==e))),r={name:null!==(i=n.name)&&void 0!==i?i:null,address:t};s.billingAddress=r}return 0===Object.keys(s).length?void 0:s},A=e=>{const t=D(null==e?void 0:e.style);return null==t?void 0:{appearance:t}},E=e=>null==e||""===e?void 0:e,z=class{async present(){null==this.presentPromise&&(this.presentPromise=new Promise((e=>{this.resolvePresent=e})));const e=this.presentPromise;return this.dispatch({type:"presentRequested"}),e}handleSecretChange(){this.startLoading()}handleOpenChange(e){this.dispatch({type:e?"openRequested":"closeRequested"})}constructor(i){e(this,i),this.paymentSheetLoaded=t(this,"paymentSheetLoaded",7),this.paymentSheetFailedToLoad=t(this,"paymentSheetFailedToLoad",7),this.paymentSheetCompleted=t(this,"paymentSheetCompleted",7),this.paymentSheetCanceled=t(this,"paymentSheetCanceled",7),this.paymentSheetFailed=t(this,"paymentSheetFailed",7),this.warnedUnsupportedOptions=!1,this.warnedCheckoutIgnoredOptions=!1,this.open=!1,this.sheetTitle="Add your payment information",this.buttonLabel="Pay",this.applicationName="stripe-pwa-elements",this.sheet=h,this.visible=!1,this.errorMessage="",this.handleSubmit=e=>{e.preventDefault(),this.errorMessage="",this.dispatch({type:"submitted"})},this.handleModalClose=()=>{var e;this.dispatch({type:"closeRequested"}),this.visible&&(null===(e=this.el.querySelector("stripe-modal"))||void 0===e||e.openModal())},this.stripeService=o.createStripeService(),this.paymentElementManager=o.createPaymentElementManager(this.stripeService),this.billingAddressElementManager=o.createAddressElementManager(this.stripeService),this.shippingAddressElementManager=o.createAddressElementManager(this.stripeService),this.emailElementManager=o.createLinkAuthenticationElementManager(this.stripeService)}componentWillLoad(){this.open&&this.dispatch({type:"openRequested"}),this.startLoading()}componentDidLoad(){this.el.classList.add(a())}disconnectedCallback(){this.paymentElementManager.unmount(),this.unmountExtraElements()}unmountExtraElements(){this.billingAddressElementManager.unmount(),this.shippingAddressElementManager.unmount(),this.emailElementManager.unmount()}startLoading(){const e=this.loadTarget();null!=e&&e.key!==this.lastLoadKey&&(this.lastLoadKey=e.key,this.dispatch({type:"secretChanged",clientSecret:e.clientSecret,source:e.source}))}loadTarget(){var e;const t=E(this.publishableKey);if(null==t)return;const i=E(this.checkoutSessionClientSecret),n=E(this.intentClientSecret),[s,a]=null!=i?[i,"checkoutSession"]:[n,"intent"];return null!=s?{key:JSON.stringify([t,null!==(e=E(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 b(e,t.clientSecret,t.source);case"loadSucceeded":{if(t.generation!==e.generation||"loading"!==e.phase)return u(e);const i=e.openRequested;return{state:Object.assign(Object.assign({},e),{phase:i?"presented":"ready",openRequested:!1}),effects:[{type:"emit",event:"paymentSheetLoaded"},...i?[{type:"show"}]:[]]}}case"loadFailed":{if(t.generation!==e.generation||"loading"!==e.phase)return u(e);const i=f(Object.assign(Object.assign({},e),{phase:"loadFailed",openRequested:!1}),"paymentSheetFailed");return{state:i.state,effects:[{type:"emit",event:"paymentSheetFailedToLoad"},...i.effects]}}case"presentRequested":if(e.pendingPresent)return u(e);switch(e.phase){case"ready":return{state:Object.assign(Object.assign({},e),{phase:"presented",pendingPresent:!0}),effects:[{type:"show"}]};case"idle":case"loading":return u(Object.assign(Object.assign({},e),{pendingPresent:!0,openRequested:!0}));case"presented":case"confirming":return u(Object.assign(Object.assign({},e),{pendingPresent:!0}));default:return{state:e,effects:[{type:"resolvePresent",result:"paymentSheetFailed"}]}}case"openRequested":return"ready"===e.phase?{state:Object.assign(Object.assign({},e),{phase:"presented"}),effects:[{type:"show"}]}:u("idle"===e.phase||"loading"===e.phase?Object.assign(Object.assign({},e),{openRequested:!0}):e);case"closeRequested":if("presented"===e.phase){const t=m(e);return{state:Object.assign(Object.assign({},t.state),{phase:"ready"}),effects:t.effects}}return"idle"!==e.phase&&"loading"!==e.phase||!e.openRequested?u(e):m(e);case"submitted":return"presented"!==e.phase||null==e.intentKind?u(e):{state:Object.assign(Object.assign({},e),{phase:"confirming"}),effects:[{type:"confirm",generation:e.generation,intentKind:e.intentKind}]};case"confirmSucceeded":{if(!v(e,t.generation))return u(e);const i=f(Object.assign(Object.assign({},e),{phase:"completed"}),"paymentSheetCompleted");return y({state:i.state,effects:[{type:"hide"},{type:"emit",event:"paymentSheetCompleted"},...i.effects]})}case"confirmDeclined":return v(e,t.generation)?y({state:Object.assign(Object.assign({},e),{phase:"presented"}),effects:[{type:"showError",message:t.message}]}):u(e);case"confirmFailed":{if(!v(e,t.generation))return u(e);const i=f(Object.assign(Object.assign({},e),{phase:"errored"}),"paymentSheetFailed");return y({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(F(d[e]))throw _(e,e);h[e]=d[e]}})),"never"===c.address){const e=d.address;if(null==e||F(e.country))throw _("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:P(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=F(d.email)?{}:{defaultValues:{email:d.email}});const f=null==e?void 0:e.shippingDetails;if(null!=f&&"payment"===t){const e={mode:"shipping",defaultValues:P(f)};F(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 new Error("Failed to load Stripe.js");const r=D(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,x(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 l(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 R("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(F(a))throw R("Please enter your email address.");if(!1===t.emailComplete||null==t.emailComplete&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a))throw R("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,n;try{this.lastResult=await t(),this.dispatch({type:"confirmSucceeded",generation:e})}catch(t){const s=null!==(i=t.message)&&void 0!==i?i:String(t),a=!0===(null==(n=t)?void 0:n.sheetValidation)?r.t(s):s;if((e=>{const t=null==e?void 0:e.type;return"string"==typeof t&&q.includes(t)})(t))return void this.dispatch({type:"confirmDeclined",generation:e,message:a});this.lastError=t,this.dispatch({type:"confirmFailed",generation:e,message:a})}}async loadCheckoutSession(e,t){this.warnUnsupportedOptions("checkoutSession"),this.warnCheckoutIgnoredOptions(),this.collection=void 0,this.unmountExtraElements();try{if(await this.stripeService.initializeWithCheckoutSession(this.publishableKey,t,{stripeAccount:this.stripeAccount,applicationName:this.applicationName,elementsOptions:A(this.options),defaultValues:L(this.options)}),e!==this.sheet.generation)return;if("success"!==this.stripeService.state.loadStripeStatus)throw new Error("Failed to load Stripe.js");await this.paymentElementManager.initialize(this.el,(e=>{const{layout:t}=x(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 new Error("Checkout Session is not initialized");return(async(e,t,i)=>c(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&&!w.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,s;const{phase:a}=this.sheet,o="confirming"===a;return i(n,{key:"52591afbd5af5ceb2530a37248e3bb1f410f880c"},i("stripe-modal",{key:"607c26d28f381b5017f9714fca398c2f5eb9c066",open:this.visible,showCloseButton:!o,onClose:this.handleModalClose},i("div",{key:"44cfb1929b178257878d5a42d8441b2f7f823436",class:"stripe-payment-sheet-wrap"},i("form",{key:"20be8d4cb150883936241639c299a86d081c1903",id:"stripe-payment-sheet",onSubmit:this.handleSubmit},i("div",{key:"14e5c98793de6d2ebb1a1cc755e501b427915d9f",class:"stripe-heading"},r.t(this.sheetTitle)),i("div",{key:"235ac34c0c2260793756960caa75ef9f62e401fd",class:"payment-info visible"},i("div",{key:"10ed4c9be02a08429b8bfd028f40be409613250b",class:"stripe-payment-sheet-email"},null!=(null===(e=this.collection)||void 0===e?void 0:e.emailElement)&&i("div",{key:"5a21882fc11b839287bd499f9441b7a37b2f7e4d",id:"link-authentication-element"})),i("div",{key:"d88e637fcecc62bba18fc25cdf674a03624ceb8a",class:"stripe-payment-sheet-shipping-address"},null!=(null===(t=this.collection)||void 0===t?void 0:t.shippingAddressElement)&&i("div",{key:"934f6b59ce787c6452191f1df14b1848f847db4a",id:"address-element"})),i("div",{key:"1fe9f0371e0669c6b5485b19672ee02169312674",class:"stripe-payment-sheet-billing-address"},null!=(null===(s=this.collection)||void 0===s?void 0:s.billingAddressElement)&&i("div",{key:"fb548084588b34ffcd8534cc2b0a402e1af60d76",id:"address-element"})),i("div",{key:"8dec277132c63cc11c49962f136b67685e810ccb",id:"payment-element"})),i("div",{key:"e0f20ba527fb9b941cc8d70d7631a03dcfc2c370",class:"stripe-element-errors",role:"alert"},this.errorMessage),i("div",{key:"db7357b49c141ff9272f1b4690f933ea54d9bfb3",class:"stripe-submit"},i("button",{key:"9112ed21047df0b2fdfa5f8d6b7872f878062dc1",type:"submit",disabled:"presented"!==a},r.t(o?"Loading":this.buttonLabel)))))))}get el(){return s(this)}static get watchers(){return{publishableKey:[{handleSecretChange:0}],intentClientSecret:[{handleSecretChange:0}],checkoutSessionClientSecret:[{handleSecretChange:0}],stripeAccount:[{handleSecretChange:0}],open:[{handleOpenChange:0}]}}};z.style=':root{--color-label:#565656;--color-placeholder:#acacac;--color-heading-text:#333;--color-text-error:#ef4444;--color-input-border:#e4e4e6;--color-input-border-shadow:rgba(228, 228, 230, 0.6);--color-button-text:rgba(255, 255, 255, 0.95);--color-button-text-disabled:rgba(255, 255, 255, 0.4);--color-primary:#0074d4}stripe-payment-sheet{display:contents}.stripe-payment-sheet-wrap{box-sizing:border-box}.stripe-payment-sheet-wrap *:where(:not(iframe,canvas,img,svg,video):not(svg *)){all:unset;display:revert;background:none;border:none;font-family:"Roboto", sans-serif;box-sizing:border-box}.stripe-payment-sheet-wrap button{cursor:pointer}.stripe-payment-sheet-wrap{display:block;width:100%;background:#fff;padding:32px 16px}.stripe-payment-sheet-wrap .stripe-heading{font-size:24px;font-weight:bold;color:var(--color-heading-text);margin-bottom:24px}.stripe-payment-sheet-wrap .payment-info{margin-top:8px}.stripe-payment-sheet-wrap .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}.stripe-payment-sheet-wrap .stripe-submit{margin-top:32px}.stripe-payment-sheet-wrap button{display:block;color:var(--color-button-text);background-color:var(--color-primary);width:100%;text-align:center;padding:16px 16px;font-size:18px;border-radius:6px;min-height:42px}.stripe-payment-sheet-wrap button:disabled{color:var(--color-button-text-disabled)}';export{z as stripe_payment_sheet}
@@ -0,0 +1 @@
1
+ import{S as t}from"./p-C6bbmyga.js";import{l as e}from"./p-CBXaOfXU.js";import{i}from"./p-HWdALSvT.js";const r=(()=>{let t;return(...e)=>{t&&clearTimeout(t),t=setTimeout((()=>{t=0,(t=>{for(let e of t.keys()){const i=t.get(e).filter((t=>{const e=t.deref();return e&&(!("isConnected"in(i=e))||i.isConnected);var i}));t.set(e,i)}})(...e)}),2e3)}})(),s=t.forceUpdate,n=t.getRenderingRef,o=(t,e)=>{const i=t.indexOf(e);i>=0&&(t[i]=t[t.length-1],t.length--)},l=(t,e)=>{const i=((t,e=(t,e)=>t!==e)=>{const i=()=>{return("function"==typeof(e=t)?e():e)??{};var e},r=i();let s=new Map(Object.entries(r));const n="undefined"!=typeof Proxy,l=n?null:{},a={dispose:[],get:[],set:[],reset:[]},c=new Map,h=()=>{s=new Map(Object.entries(i())),n||m(),a.reset.forEach((t=>t()))},u=t=>(a.get.forEach((e=>e(t))),s.get(t)),d=(t,i)=>{const r=s.get(t);e(i,r,t)&&(s.set(t,i),n||g(t),a.set.forEach((e=>e(t,i,r))))},v=n?new Proxy(r,{get:(t,e)=>u(e),ownKeys:()=>Array.from(s.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(t,e)=>s.has(e),set:(t,e,i)=>(d(e,i),!0)}):(m(),l),p=(t,e)=>(a[t].push(e),()=>{o(a[t],e)});function g(t){!n&&l&&(Object.prototype.hasOwnProperty.call(l,t)||Object.defineProperty(l,t,{configurable:!0,enumerable:!0,get:()=>u(t),set(e){d(t,e)}}))}function m(){if(n||!l)return;const t=new Set(s.keys());for(const e of Object.keys(l))t.has(e)||delete l[e];for(const e of t)g(e)}return{state:v,get:u,set:d,on:p,onChange:(t,e)=>{const r=(i,r)=>{i===t&&e(r)},s=()=>{const r=i();e(r[t])},n=p("set",r),o=p("reset",s);return c.set(e,{setHandler:r,resetHandler:s,propName:t}),()=>{n(),o(),c.delete(e)}},use:(...t)=>{const e=t.reduce(((t,e)=>(e.set&&t.push(p("set",e.set)),e.get&&t.push(p("get",e.get)),e.reset&&t.push(p("reset",e.reset)),e.dispose&&t.push(p("dispose",e.dispose)),t)),[]);return()=>e.forEach((t=>t()))},dispose:()=>{a.dispose.forEach((t=>t())),h()},reset:h,forceUpdate:t=>{const e=s.get(t);a.set.forEach((i=>i(t,e,e)))},removeListener:(t,e)=>{const i=c.get(e);i&&i.propName===t&&(o(a.set,i.setHandler),o(a.reset,i.resetHandler),c.delete(e))}}})(t,e);return i.use((()=>{if("function"!=typeof n||"function"!=typeof s)return{};const t=s,e=n,i=new Map;return{dispose:()=>i.clear(),get:t=>{const r=e();r&&((t,e,i)=>{let r=t.get(e);r||(r=[],t.set(e,r)),r.some((t=>t.deref()===i))||r.push(new WeakRef(i))})(i,t,r)},set:e=>{const s=i.get(e);if(s){const r=s.filter((e=>{const i=e.deref();return!!i&&t(i)}));i.set(e,r)}r(i)},reset:()=>{i.forEach((e=>{e.forEach((e=>{const i=e.deref();i&&t(i)}))})),r(i)}}})()),i};class a{constructor(){this.store=l({loadStripeStatus:"",applicationName:"stripe-pwa-elements",isCheckoutSession:!1}),this.initGeneration=0,this.changeListeners=new Map}get state(){return this.store.state}onChange(t,e){const i=this.store.onChange(t,e);return this.changeListeners.has(t)||this.changeListeners.set(t,[]),this.changeListeners.get(t).push(i),i}async initialize(t,i){const r=null!=(null==i?void 0:i.elementsOptions)?JSON.stringify(i.elementsOptions):void 0,s=null!=this.store.state.stripe&&!this.store.state.isCheckoutSession&&this.store.state.publishableKey===t&&this.store.state.stripeAccount===(null==i?void 0:i.stripeAccount)&&this.intentClientSecret===(null==i?void 0:i.clientSecret)&&this.elementsOptionsKey===r;if(this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!1,this.intentClientSecret=null==i?void 0:i.clientSecret,this.elementsOptionsKey=r,null!=(null==i?void 0:i.stripeAccount)&&""!==(null==i?void 0:i.stripeAccount)&&(this.store.state.stripeAccount=i.stripeAccount),null!=(null==i?void 0:i.applicationName)&&""!==(null==i?void 0:i.applicationName)&&(this.store.state.applicationName=i.applicationName),s)return;const n=++this.initGeneration;this.store.state.loadStripeStatus="loading";try{const r=await e(t,{stripeAccount:null==i?void 0:i.stripeAccount});if(n!==this.initGeneration)return;r.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=r,this.store.state.elements=null!=(null==i?void 0:i.clientSecret)&&""!==i.clientSecret?r.elements({clientSecret:i.clientSecret}):null!=(null==i?void 0:i.elementsOptions)?r.elements(i.elementsOptions):r.elements(),this.store.state.checkout=void 0,this.store.state.loadStripeStatus="success"}catch(t){console.error("Failed to load Stripe.js:",t),this.store.state.loadStripeStatus="failure"}}async initializeWithCheckoutSession(t,i,r){const s=++this.initGeneration;this.store.state.publishableKey=t,this.store.state.isCheckoutSession=!0,null!=(null==r?void 0:r.stripeAccount)&&""!==(null==r?void 0:r.stripeAccount)&&(this.store.state.stripeAccount=r.stripeAccount),null!=(null==r?void 0:r.applicationName)&&""!==(null==r?void 0:r.applicationName)&&(this.store.state.applicationName=r.applicationName),this.store.state.loadStripeStatus="loading";try{const n=await e(t,{stripeAccount:null==r?void 0:r.stripeAccount});if(s!==this.initGeneration)return;n.registerAppInfo({name:this.store.state.applicationName}),this.store.state.stripe=n;const o=n.initCheckoutElementsSdk({clientSecret:i,elementsOptions:null==r?void 0:r.elementsOptions,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}
@@ -0,0 +1 @@
1
+ import{S as e}from"./p-XRfh5Wrs.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.`})},n=async(n,o,s)=>{const i=await n.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&&""!==o?{returnUrl:o}:{}),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:n}=u.error;if(t(a(),n),"paymentFailed"===r)throw new e({type:"card_error",code:r,message:n});throw new e({type:"api_error",code:"checkout_session_error",message:n})}return u},o=e=>{const{progress:r,isCheckoutSession:t,loadStripeStatus:n,intentClientSecret:o}=e;return"loading"===r||"success"===r||!(t?"success"===n:null!=o&&""!==o)},s=async(r,t,n,o,s)=>{const i=await("payment"===n?r.confirmPayment({elements:t,confirmParams:Object.assign({return_url:o},s),redirect:"if_required"}):r.confirmSetup({elements:t,confirmParams:Object.assign({return_url:o},s),redirect:"if_required"}));if(i.error)throw new e(i.error);return i},i=async(e,r,t)=>n(e,r,t),c=e=>{const{stripe:r,isCheckoutSession:t,checkout:n,checkoutSessionClientSecret:o,elements:s,intentClientSecret:i}=e,c={stripe:r};return t?null==n?{error:"Checkout not properly initialized"}:(c.checkout=n,c.checkoutSessionClientSecret=o,{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,n as d,o as i}
@@ -1 +1 @@
1
- import{p as e,B as t,c as n,w as i,N as a,H as l,b as o}from"./p-C6bbmyga.js";export{s as setNonce}from"./p-C6bbmyga.js";import{g as p}from"./p-DQuL1Twl.js";var r=e=>{const t=e.cloneNode;e.cloneNode=function(e){if("TEMPLATE"===this.nodeName)return t.call(this,e);const n=t.call(this,!1),i=this.childNodes;if(e)for(let e=0;e<i.length;e++)2!==i[e].nodeType&&n.appendChild(i[e].cloneNode(!0));return n}};(()=>{t.isDev&&!t.isTesting&&n("Running in development mode."),t.cloneNodeFix&&r(l.prototype);const s=t.scriptDataOpts?i.document&&Array.from(i.document.querySelectorAll("script")).find((e=>new RegExp(`/${a}(\\.esm)?\\.js($|\\?|#)`).test(e.src)||e.getAttribute("data-stencil-namespace")===a)):null,o=import.meta.url,p=t.scriptDataOpts&&(s||{})["data-opts"]||{};return""!==o&&(p.resourcesUrl=new URL(".",o).href),e(p)})().then((async e=>(await p(),o([["p-4891edf0",[[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]}]]],["p-a45268d4",[[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}]}]]],["p-50e495e3",[[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}]}]]],["p-949a8bba",[[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}]}]]],["p-b0f9ebba",[[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}]}]]],["p-edbbe060",[[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}]}]]],["p-855d1aee",[[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}]}]]],["p-ba791c8f",[[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]}]]],["p-a2d11152",[[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}]}]]],["p-b4faa9db",[[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}]}]]]],e))));
1
+ import{p as e,B as t,c as n,w as i,N as a,H as l,b as o}from"./p-C6bbmyga.js";export{s as setNonce}from"./p-C6bbmyga.js";import{g as p}from"./p-DQuL1Twl.js";var r=e=>{const t=e.cloneNode;e.cloneNode=function(e){if("TEMPLATE"===this.nodeName)return t.call(this,e);const n=t.call(this,!1),i=this.childNodes;if(e)for(let e=0;e<i.length;e++)2!==i[e].nodeType&&n.appendChild(i[e].cloneNode(!0));return n}};(()=>{t.isDev&&!t.isTesting&&n("Running in development mode."),t.cloneNodeFix&&r(l.prototype);const s=t.scriptDataOpts?i.document&&Array.from(i.document.querySelectorAll("script")).find((e=>new RegExp(`/${a}(\\.esm)?\\.js($|\\?|#)`).test(e.src)||e.getAttribute("data-stencil-namespace")===a)):null,o=import.meta.url,p=t.scriptDataOpts&&(s||{})["data-opts"]||{};return""!==o&&(p.resourcesUrl=new URL(".",o).href),e(p)})().then((async e=>(await p(),o([["p-4891edf0",[[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]}]]],["p-eeebfbbf",[[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}]}]]],["p-e660d76a",[[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}]}]]],["p-2e2bf0fe",[[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}]}]]],["p-32a2d5a4",[[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}]}]]],["p-84d45b48",[[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}]}]]],["p-c4a0e310",[[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}]}]]],["p-ba791c8f",[[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]}]]],["p-a266da6f",[[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}]}]]],["p-b4faa9db",[[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}]}]]]],e))));
@@ -182,6 +182,39 @@ export declare class StripePaymentElement {
182
182
  * And listen the 'formSubmit' event on the element
183
183
  */
184
184
  readonly shouldUseDefaultFormSubmitAction: boolean;
185
+ /**
186
+ * URL Stripe redirects to after a redirect-based payment method (Checkout Session mode only).
187
+ * Used when the Checkout Session was created WITHOUT `return_url`. Defaults to the current page URL.
188
+ * A session created with `return_url` ignores this value: Stripe redirects there automatically.
189
+ * @example
190
+ * ```
191
+ * <stripe-payment-element checkout-session-client-secret="cs_xxx_secret_xxx" checkout-session-return-url="https://example.com/return" />
192
+ * ```
193
+ */
194
+ readonly checkoutSessionReturnUrl?: string;
195
+ /**
196
+ * Customer email passed to `confirm()` (Checkout Session mode only).
197
+ * Required when the Checkout Session was created without `customer_email` or `customer`,
198
+ * because confirming such a session fails with "An email address is required".
199
+ * @example
200
+ * ```
201
+ * <stripe-payment-element checkout-session-client-secret="cs_xxx_secret_xxx" checkout-session-email="customer@example.com" />
202
+ * ```
203
+ */
204
+ readonly checkoutSessionEmail?: string;
205
+ /**
206
+ * Prefilled values of the Checkout Elements (Checkout Session mode only): `email`, `phoneNumber`,
207
+ * `billingAddress` and `shippingAddress` as supported by `initCheckoutElementsSdk`.
208
+ * JavaScript property only: it cannot be set through an HTML attribute.
209
+ * @example
210
+ * ```
211
+ * const stripeElement = document.createElement('stripe-payment-element');
212
+ * customElements.whenDefined('stripe-payment-element').then(() => {
213
+ * stripeElement.checkoutSessionDefaultValues = { email: 'customer@example.com' };
214
+ * });
215
+ * ```
216
+ */
217
+ readonly checkoutSessionDefaultValues?: CheckoutSessionOptions['defaultValues'];
185
218
  /**
186
219
  * Form submit event handler
187
220
  */
@@ -34,12 +34,18 @@ export type ExtraConfirmParams = Pick<ConfirmPaymentData & ConfirmSetupData, 'pa
34
34
  export declare const confirmPaymentOrSetup: (stripe: Stripe, elements: StripeElements, intentType: IntentType, returnUrl: string, extraConfirmParams?: ExtraConfirmParams) => Promise<import("@stripe/stripe-js").PaymentIntentResult | import("@stripe/stripe-js").SetupIntentResult>;
35
35
  /**
36
36
  * Confirm a Checkout Session payment using the checkout actions.
37
+ *
38
+ * Stripe requires exactly one of `returnUrl` (confirm argument) or the session's `return_url`, and the client
39
+ * cannot tell which one a session has (`getSession()` does not expose it). The shared implementation passes
40
+ * `returnUrl` first and retries without it when Stripe rejects it because the session already has
41
+ * `return_url`. See `confirmCheckoutActions` for the full behavior and error classification.
37
42
  * @param checkout the Stripe Checkout instance
38
- * @param returnUrl the URL Stripe should redirect back to when required
43
+ * @param returnUrl URL Stripe should redirect back to when the session has no `return_url`
44
+ * @param email customer email, required when the session was created without `customer_email` or `customer`
39
45
  * @returns the confirmation result
40
46
  * @throws StripeAPIError when loading actions or confirming fails
41
47
  */
42
- export declare const confirmCheckoutSession: (checkout: StripeCheckoutElementsSdk, returnUrl: string) => Promise<StripeCheckoutConfirmResult>;
48
+ export declare const confirmCheckoutSession: (checkout: StripeCheckoutElementsSdk, returnUrl: string, email?: string) => Promise<StripeCheckoutConfirmResult>;
43
49
  /**
44
50
  * Resolve the mode-specific properties for a submit event.
45
51
  * Picks the Checkout or Elements payload depending on the active mode and
@@ -1,4 +1,4 @@
1
- import type { StripeCheckoutConfirmResult, StripeCheckoutElementsOptions, StripeCheckoutElementsSdk, StripeCheckoutPaymentElementOptions } from '@stripe/stripe-js';
1
+ import type { StripeCheckoutConfirmResult, StripeCheckoutElementsOptions, StripeCheckoutElementsSdk, StripeCheckoutElementsSdkOptions, StripeCheckoutPaymentElementOptions } from '@stripe/stripe-js';
2
2
  import type { PaymentSheetOptions } from './stripe-payment-sheet.helpers';
3
3
  /**
4
4
  * Build the Checkout Payment Element options from the payment sheet options.
@@ -7,9 +7,18 @@ import type { PaymentSheetOptions } from './stripe-payment-sheet.helpers';
7
7
  * @param options - Payment sheet options
8
8
  */
9
9
  export declare const toCheckoutPaymentElementOptions: (options: PaymentSheetOptions | undefined) => StripeCheckoutPaymentElementOptions;
10
+ type CheckoutDefaultValues = NonNullable<StripeCheckoutElementsSdkOptions['defaultValues']>;
11
+ /**
12
+ * Build the `defaultValues` passed to `initCheckoutElementsSdk` from the payment sheet options.
13
+ * The email and phone prefill the Checkout Elements; name and address are passed as `billingAddress`,
14
+ * which Stripe only accepts with a country, so a name or address without `country` cannot be prefilled.
15
+ * @param options - Payment sheet options
16
+ */
17
+ export declare const toCheckoutDefaultValues: (options: PaymentSheetOptions | undefined) => CheckoutDefaultValues | undefined;
10
18
  /**
11
19
  * List the given options that a Checkout Session does not use, sorted by name.
12
- * Name, phone and address come from the session or from other Checkout elements; the email is passed to `confirm`.
20
+ * Name and address are prefilled through `defaultValues`, which Stripe only accepts with a country, so they are
21
+ * listed when they cannot be used. The email is passed to `confirm` and the phone prefilled through `defaultValues`.
13
22
  * @param options - Payment sheet options
14
23
  */
15
24
  export declare const checkoutIgnoredOptionKeys: (options: PaymentSheetOptions | undefined) => string[];
@@ -21,19 +30,18 @@ export declare const toCheckoutElementsOptions: (options: PaymentSheetOptions |
21
30
  /**
22
31
  * Confirm a Checkout Session from the payment sheet.
23
32
  *
24
- * Unlike the default of `confirm`, which always redirects to `returnUrl`, this passes `redirect: 'if_required'`
25
- * so that payment methods without a redirect finish in the page and can be reported as `paymentSheetCompleted`.
33
+ * The shared implementation (see `confirmCheckoutActions`) retries without `returnUrl` when the session was
34
+ * created with `return_url`, and passes `redirect: 'if_required'` so that payment methods without a redirect
35
+ * finish in the page and can be reported as `paymentSheetCompleted`.
26
36
  *
27
- * Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands.
28
- * A confirm error only carries `code: 'paymentFailed'` or `code: null` (`StripeCheckoutConfirmResult` in @stripe/stripe-js),
29
- * so whether the session can still be paid is read from `session.status`:
30
- * - session `expired` or `complete` (before confirming or after a failed confirm): `invalid_request_error`, which ends the sheet
31
- * - `paymentFailed` on an open session (a decline): `card_error`, which keeps the sheet open
32
- * - any other confirm error on an open session, or a failure to load the actions: `api_error`, which keeps the sheet open
37
+ * Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands:
38
+ * an expired or complete session is an `invalid_request_error` (unrecoverable), a decline is a `card_error`,
39
+ * and any other failure is an `api_error` (both recoverable).
33
40
  * @param checkout - The Checkout instance from `initCheckoutElementsSdk`
34
- * @param returnUrl - Where Stripe redirects after a redirect-based payment method
41
+ * @param returnUrl - Where Stripe redirects after a redirect-based payment method, when the session has no `return_url`
35
42
  * @param email - Customer email; needed when the session was created without `customer_email` or `customer`
36
43
  * @returns The confirmation result
37
44
  * @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
38
45
  */
39
46
  export declare const confirmCheckoutSessionSheet: (checkout: StripeCheckoutElementsSdk, returnUrl: string, email?: string) => Promise<StripeCheckoutConfirmResult>;
47
+ export {};
@@ -8,13 +8,13 @@ import { HTMLStencilElement, JSXBase } from "./stencil-public-runtime";
8
8
  import { AddressSubmitEvent, AddressSubmitHandler } from "./components/stripe-address-element/stripe-address-element";
9
9
  import { CurrencySelectorChangeEvent, CurrencySelectorChangeHandler, DefaultFormSubmitResult, FormSubmitEvent, FormSubmitHandler, InitStripeOptions, IntentType, LinkAuthenticationElementChangeEvent, LinkAuthenticationElementChangeHandler, PaymentRequestButtonOption, PaymentRequestPaymentMethodEventHandler, PaymentRequestShippingAddressEventHandler, PaymentRequestShippingOptionEventHandler, ProgressStatus, StripeDidLoadedHandler, StripeLoadedEvent } from "./interfaces";
10
10
  import { PaymentIntentResult, PaymentRequestOptions, PaymentRequestWallet, SetupIntentResult, StripeCheckoutConfirmResult, StripeExpressCheckoutElementClickEvent, StripeExpressCheckoutElementConfirmEvent } from "@stripe/stripe-js";
11
- import { ExpressCheckoutElementOptions } from "./services/interfaces";
11
+ import { CheckoutSessionOptions, ExpressCheckoutElementOptions } from "./services/interfaces";
12
12
  import { CheckoutSessionFormSubmitResult, InitCheckoutSessionOptions, PaymentElementSubmitEvent, PaymentElementSubmitHandler } from "./components/stripe-payment-element/stripe-payment-element";
13
13
  import { PaymentSheetOptions, PaymentSheetPresentResult } from "./components/stripe-payment-sheet/stripe-payment-sheet.helpers";
14
14
  export { AddressSubmitEvent, AddressSubmitHandler } from "./components/stripe-address-element/stripe-address-element";
15
15
  export { CurrencySelectorChangeEvent, CurrencySelectorChangeHandler, DefaultFormSubmitResult, FormSubmitEvent, FormSubmitHandler, InitStripeOptions, IntentType, LinkAuthenticationElementChangeEvent, LinkAuthenticationElementChangeHandler, PaymentRequestButtonOption, PaymentRequestPaymentMethodEventHandler, PaymentRequestShippingAddressEventHandler, PaymentRequestShippingOptionEventHandler, ProgressStatus, StripeDidLoadedHandler, StripeLoadedEvent } from "./interfaces";
16
16
  export { PaymentIntentResult, PaymentRequestOptions, PaymentRequestWallet, SetupIntentResult, StripeCheckoutConfirmResult, StripeExpressCheckoutElementClickEvent, StripeExpressCheckoutElementConfirmEvent } from "@stripe/stripe-js";
17
- export { ExpressCheckoutElementOptions } from "./services/interfaces";
17
+ export { CheckoutSessionOptions, ExpressCheckoutElementOptions } from "./services/interfaces";
18
18
  export { CheckoutSessionFormSubmitResult, InitCheckoutSessionOptions, PaymentElementSubmitEvent, PaymentElementSubmitHandler } from "./components/stripe-payment-element/stripe-payment-element";
19
19
  export { PaymentSheetOptions, PaymentSheetPresentResult } from "./components/stripe-payment-sheet/stripe-payment-sheet.helpers";
20
20
  export namespace Components {
@@ -510,6 +510,21 @@ export namespace Components {
510
510
  * @example ``` const stripeElement = document.createElement('stripe-payment-element'); customElements .whenDefined('stripe-payment-element') .then(() => { stripeElement.initStripeWithCheckoutSession('pk_test_xxx', 'cs_xxx_secret_xxx') }) ```
511
511
  */
512
512
  "checkoutSessionClientSecret"?: string;
513
+ /**
514
+ * Prefilled values of the Checkout Elements (Checkout Session mode only): `email`, `phoneNumber`, `billingAddress` and `shippingAddress` as supported by `initCheckoutElementsSdk`. JavaScript property only: it cannot be set through an HTML attribute.
515
+ * @example ``` const stripeElement = document.createElement('stripe-payment-element'); customElements.whenDefined('stripe-payment-element').then(() => { stripeElement.checkoutSessionDefaultValues = { email: 'customer@example.com' }; }); ```
516
+ */
517
+ "checkoutSessionDefaultValues"?: CheckoutSessionOptions['defaultValues'];
518
+ /**
519
+ * Customer email passed to `confirm()` (Checkout Session mode only). Required when the Checkout Session was created without `customer_email` or `customer`, because confirming such a session fails with "An email address is required".
520
+ * @example ``` <stripe-payment-element checkout-session-client-secret="cs_xxx_secret_xxx" checkout-session-email="customer@example.com" /> ```
521
+ */
522
+ "checkoutSessionEmail"?: string;
523
+ /**
524
+ * URL Stripe redirects to after a redirect-based payment method (Checkout Session mode only). Used when the Checkout Session was created WITHOUT `return_url`. Defaults to the current page URL. A session created with `return_url` ignores this value: Stripe redirects there automatically.
525
+ * @example ``` <stripe-payment-element checkout-session-client-secret="cs_xxx_secret_xxx" checkout-session-return-url="https://example.com/return" /> ```
526
+ */
527
+ "checkoutSessionReturnUrl"?: string;
513
528
  /**
514
529
  * Form submit event handler
515
530
  */
@@ -1376,6 +1391,21 @@ declare namespace LocalJSX {
1376
1391
  * @example ``` const stripeElement = document.createElement('stripe-payment-element'); customElements .whenDefined('stripe-payment-element') .then(() => { stripeElement.initStripeWithCheckoutSession('pk_test_xxx', 'cs_xxx_secret_xxx') }) ```
1377
1392
  */
1378
1393
  "checkoutSessionClientSecret"?: string;
1394
+ /**
1395
+ * Prefilled values of the Checkout Elements (Checkout Session mode only): `email`, `phoneNumber`, `billingAddress` and `shippingAddress` as supported by `initCheckoutElementsSdk`. JavaScript property only: it cannot be set through an HTML attribute.
1396
+ * @example ``` const stripeElement = document.createElement('stripe-payment-element'); customElements.whenDefined('stripe-payment-element').then(() => { stripeElement.checkoutSessionDefaultValues = { email: 'customer@example.com' }; }); ```
1397
+ */
1398
+ "checkoutSessionDefaultValues"?: CheckoutSessionOptions['defaultValues'];
1399
+ /**
1400
+ * Customer email passed to `confirm()` (Checkout Session mode only). Required when the Checkout Session was created without `customer_email` or `customer`, because confirming such a session fails with "An email address is required".
1401
+ * @example ``` <stripe-payment-element checkout-session-client-secret="cs_xxx_secret_xxx" checkout-session-email="customer@example.com" /> ```
1402
+ */
1403
+ "checkoutSessionEmail"?: string;
1404
+ /**
1405
+ * URL Stripe redirects to after a redirect-based payment method (Checkout Session mode only). Used when the Checkout Session was created WITHOUT `return_url`. Defaults to the current page URL. A session created with `return_url` ignores this value: Stripe redirects there automatically.
1406
+ * @example ``` <stripe-payment-element checkout-session-client-secret="cs_xxx_secret_xxx" checkout-session-return-url="https://example.com/return" /> ```
1407
+ */
1408
+ "checkoutSessionReturnUrl"?: string;
1379
1409
  /**
1380
1410
  * Form submit event handler
1381
1411
  */
@@ -1625,6 +1655,8 @@ declare namespace LocalJSX {
1625
1655
  "intentClientSecret": string;
1626
1656
  "checkoutSessionClientSecret": string;
1627
1657
  "shouldUseDefaultFormSubmitAction": boolean;
1658
+ "checkoutSessionReturnUrl": string;
1659
+ "checkoutSessionEmail": string;
1628
1660
  }
1629
1661
  interface StripePaymentRequestButtonAttributes {
1630
1662
  "publishableKey": string;
@@ -1,10 +1,12 @@
1
- import { Stripe, StripeElements, StripeCardNumberElement, StripeCardExpiryElement, StripeCardCvcElement, StripePaymentElement, StripeAddressElement, StripeLinkAuthenticationElement, StripeCurrencySelectorElement, StripeExpressCheckoutElement, StripeExpressCheckoutElementConfirmEvent, StripeExpressCheckoutElementClickEvent, StripeExpressCheckoutElementShippingAddressChangeEvent, StripeExpressCheckoutElementShippingRateChangeEvent, StripeCheckoutElementsSdk, StripeCheckoutElementsOptions } from '@stripe/stripe-js';
1
+ import { Stripe, StripeElements, StripeCardNumberElement, StripeCardExpiryElement, StripeCardCvcElement, StripePaymentElement, StripeAddressElement, StripeLinkAuthenticationElement, StripeCurrencySelectorElement, StripeExpressCheckoutElement, StripeExpressCheckoutElementConfirmEvent, StripeExpressCheckoutElementClickEvent, StripeExpressCheckoutElementShippingAddressChangeEvent, StripeExpressCheckoutElementShippingRateChangeEvent, StripeCheckoutElementsSdk, StripeCheckoutElementsOptions, StripeCheckoutElementsSdkOptions } from '@stripe/stripe-js';
2
2
  import { ProgressStatus } from '../interfaces';
3
3
  /**
4
4
  * Checkout session initialization options
5
5
  */
6
6
  export type CheckoutSessionOptions = {
7
7
  elementsOptions?: StripeCheckoutElementsOptions;
8
+ /** Prefilled values of the Checkout Elements (email, phone, billing or shipping address) */
9
+ defaultValues?: StripeCheckoutElementsSdkOptions['defaultValues'];
8
10
  };
9
11
  /**
10
12
  * Stripe service state
@@ -0,0 +1,35 @@
1
+ import type { StripeCheckoutConfirmResult, StripeCheckoutElementsSdk, StripeCheckoutStatus } from '@stripe/stripe-js';
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 declare const isCheckoutReturnUrlConflict: (error: unknown) => boolean;
9
+ /**
10
+ * Throw when the session can no longer be paid. Stripe documents an `expired` session as "No further processing will occur",
11
+ * and a `complete` one is already paid or being paid, so confirming again cannot succeed.
12
+ * @param status - `session.status` from `getSession()`; undefined when it cannot be read
13
+ * @param message - Message of the confirm error, if any
14
+ * @throws StripeAPIError of type `invalid_request_error` (unrecoverable), with the code `checkout_session_expired` or `checkout_session_complete`
15
+ */
16
+ export declare const assertCheckoutSessionOpen: (status: StripeCheckoutStatus | undefined, message?: string) => void;
17
+ /**
18
+ * Confirm a Checkout Session through the checkout actions.
19
+ *
20
+ * Stripe requires exactly one of `returnUrl` (confirm argument) or the session's `return_url`, and the client
21
+ * cannot tell which one a session has (`getSession()` does not expose it). So the first attempt passes
22
+ * `returnUrl`, and when Stripe rejects it because the session already has `return_url`, the confirmation is
23
+ * retried without `returnUrl` (Stripe then redirects to the session's `return_url` automatically).
24
+ *
25
+ * Errors are thrown as `StripeAPIError`:
26
+ * - session `expired` or `complete` (before confirming or after a failed confirm): `invalid_request_error`
27
+ * - `paymentFailed` on an open session (a decline): `card_error`
28
+ * - any other confirm error on an open session, or a failure to load the actions: `api_error`
29
+ * @param checkout - The Checkout instance from `initCheckoutElementsSdk`
30
+ * @param returnUrl - Where Stripe redirects after a redirect-based payment method, when the session has no `return_url`
31
+ * @param email - Customer email; needed when the session was created without `customer_email` or `customer`
32
+ * @returns The confirmation result
33
+ * @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
34
+ */
35
+ export declare const confirmCheckoutActions: (checkout: StripeCheckoutElementsSdk, returnUrl: string, email?: string) => Promise<StripeCheckoutConfirmResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stripe-pwa-elements",
3
- "version": "4.0.5",
3
+ "version": "4.1.0",
4
4
  "description": "Framework-agnostic Stripe Payment Elements as Web Components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -1,121 +0,0 @@
1
- 'use strict';
2
-
3
- var error = require('./error-FFC4kSs5.js');
4
-
5
- /**
6
- * Determine whether the submit button should be disabled.
7
- * For Checkout Session mode: the checkout is ready once Stripe finished loading.
8
- * For Payment Intent / Setup Intent mode: an intent client secret must be present.
9
- * The button stays disabled after a successful payment as well: the intent or
10
- * checkout is already confirmed and cannot be submitted again.
11
- * @param params progress / loading state and the current mode information
12
- * @returns true when the submit button should be disabled
13
- */
14
- const isSubmitButtonDisabled = (params) => {
15
- const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
16
- const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
17
- return progress === 'loading' || progress === 'success' || !hasValidSecret;
18
- };
19
- /**
20
- * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
21
- * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
22
- * @param stripe the loaded Stripe.js instance
23
- * @param elements the Stripe Elements instance bound to the payment element
24
- * @param intentType the configured intent type
25
- * @param returnUrl the URL Stripe should redirect back to when required
26
- * @param extraConfirmParams optional params merged into `confirmParams` (for example `payment_method_data.billing_details`)
27
- * @returns the confirmation result
28
- * @throws StripeAPIError when Stripe returns an error
29
- */
30
- const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl, extraConfirmParams) => {
31
- const result = await (() => {
32
- if (intentType === 'payment') {
33
- return stripe.confirmPayment({
34
- elements,
35
- confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
36
- redirect: 'if_required',
37
- });
38
- }
39
- return stripe.confirmSetup({
40
- elements,
41
- confirmParams: Object.assign({ return_url: returnUrl }, extraConfirmParams),
42
- redirect: 'if_required',
43
- });
44
- })();
45
- if (result.error) {
46
- throw new error.StripeAPIError(result.error);
47
- }
48
- return result;
49
- };
50
- /**
51
- * Confirm a Checkout Session payment using the checkout actions.
52
- * @param checkout the Stripe Checkout instance
53
- * @param returnUrl the URL Stripe should redirect back to when required
54
- * @returns the confirmation result
55
- * @throws StripeAPIError when loading actions or confirming fails
56
- */
57
- const confirmCheckoutSession = async (checkout, returnUrl) => {
58
- var _a;
59
- // Load actions from the checkout session
60
- const loadActionsResult = await checkout.loadActions();
61
- if (loadActionsResult.type === 'error') {
62
- // Create a StripeError-compatible object from the Checkout Session error
63
- const stripeError = {
64
- type: 'api_error',
65
- code: loadActionsResult.error.code || 'checkout_session_error',
66
- message: loadActionsResult.error.message,
67
- };
68
- throw new error.StripeAPIError(stripeError);
69
- }
70
- const { actions } = loadActionsResult;
71
- // Confirm the payment using checkout session actions
72
- const result = await actions.confirm({
73
- returnUrl,
74
- redirect: 'if_required',
75
- });
76
- if (result.type === 'error') {
77
- // Create a StripeError-compatible object from the confirm error
78
- const stripeError = {
79
- type: 'card_error',
80
- code: result.error.code || 'payment_failed',
81
- message: result.error.message,
82
- decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
83
- };
84
- throw new error.StripeAPIError(stripeError);
85
- }
86
- return result;
87
- };
88
- /**
89
- * Resolve the mode-specific properties for a submit event.
90
- * Picks the Checkout or Elements payload depending on the active mode and
91
- * reports a descriptive error string when the required instance is missing.
92
- * @param params the resolved Stripe instances and client secrets for the current mode
93
- * @returns the submit event props, or an error message when an instance is missing
94
- */
95
- const buildSubmitEventProps = (params) => {
96
- const { stripe, isCheckoutSession, checkout, checkoutSessionClientSecret, elements, intentClientSecret } = params;
97
- const props = {
98
- stripe,
99
- };
100
- if (isCheckoutSession) {
101
- // Checkout Session mode
102
- if (checkout == null) {
103
- return { error: 'Checkout not properly initialized' };
104
- }
105
- props.checkout = checkout;
106
- props.checkoutSessionClientSecret = checkoutSessionClientSecret;
107
- return { props };
108
- }
109
- // Payment Intent / Setup Intent mode
110
- if (elements == null) {
111
- return { error: 'Elements not properly initialized' };
112
- }
113
- props.elements = elements;
114
- props.intentClientSecret = intentClientSecret;
115
- return { props };
116
- };
117
-
118
- exports.buildSubmitEventProps = buildSubmitEventProps;
119
- exports.confirmCheckoutSession = confirmCheckoutSession;
120
- exports.confirmPaymentOrSetup = confirmPaymentOrSetup;
121
- exports.isSubmitButtonDisabled = isSubmitButtonDisabled;