FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
surecart
Edit File: p-634860e0.entry.js
import{r as e,c as i,h as t,a as o}from"./p-e97fde0a.js";import{p as l}from"./p-9ef0f73f.js";import{s}from"./p-4cae87fc.js";import{o as d,s as n,u as a}from"./p-53e7f7d7.js";import{o as r}from"./p-95325ec5.js";import"./p-3dc3bd12.js";import{s as c,g as v}from"./p-566c9487.js";import{c as u}from"./p-ff10bfbf.js";import{c as f}from"./p-1f60f497.js";import{t as p,b as m}from"./p-2f193d80.js";import{a as h}from"./p-401e165e.js";import"./p-03631502.js";import"./p-9dbc54d6.js";import"./p-d3366af3.js";import"./p-830ab1a3.js";import"./p-ec182234.js";import"./p-3f6362a4.js";import"./p-4df6e0c5.js";import"./p-93127aa7.js";import"./p-2805073a.js";const y="sc-stripe-payment-element{display:block}sc-stripe-payment-element [hidden]{display:none}.loader{display:grid;height:128px;gap:2em}.loader__row{display:flex;align-items:flex-start;justify-content:space-between;gap:1em}.loader__details{display:grid;gap:0.5em}";const b=y;const g=class{constructor(t){e(this,t);this.scPaid=i(this,"scPaid",7);this.scSetState=i(this,"scSetState",7);this.scPaymentInfoAdded=i(this,"scPaymentInfoAdded",7);this.error=undefined;this.confirming=false;this.isInitializingStripe=false;this.isCreatingUpdatingStripeElement=false;this.loaded=false;this.styles=undefined}async componentWillLoad(){this.fetchStyles();this.syncCheckoutMode()}async handleStylesChange(){this.createOrUpdateElements()}async fetchStyles(){this.styles=await this.getComputedStyles()}getComputedStyles(){return new Promise((e=>{let i=setInterval((()=>{const t=window.getComputedStyle(document.body);const o=t.getPropertyValue("--sc-color-primary-500");if(o){clearInterval(i);e(t)}}),100)}))}async syncCheckoutMode(){d("checkout",(()=>{this.initializeStripe()}))}async componentDidLoad(){this.initializeStripe()}async initializeStripe(){var e,i;if(typeof((e=n===null||n===void 0?void 0:n.checkout)===null||e===void 0?void 0:e.live_mode)==="undefined"||((i=c===null||c===void 0?void 0:c.instances)===null||i===void 0?void 0:i.stripe)||this.isInitializingStripe){return}this.isInitializingStripe=true;const{processor_data:t}=v("stripe")||{};try{c.instances.stripe=await l.loadStripe(t===null||t===void 0?void 0:t.publishable_key,{stripeAccount:t===null||t===void 0?void 0:t.account_id});this.error=""}catch(e){this.error=(e===null||e===void 0?void 0:e.message)||wp.i18n.__("Stripe could not be loaded","surecart");this.isInitializingStripe=false;return}this.createOrUpdateElements();this.handleUpdateElement();this.unlistenToCheckout=d("checkout",(()=>{this.fetchStyles();this.createOrUpdateElements();this.handleUpdateElement()}));this.unlistenToFormState=r("formState",(()=>{var e;if(!((e=n===null||n===void 0?void 0:n.checkout)===null||e===void 0?void 0:e.payment_method_required))return;if("paying"===u()){this.maybeConfirmOrder()}}));this.isInitializingStripe=false}clearStripeInstances(){var e,i,t,o;this.isInitializingStripe=false;this.isCreatingUpdatingStripeElement=false;if(this===null||this===void 0?void 0:this.element){try{(i=(e=this.element)===null||e===void 0?void 0:e.unmount)===null||i===void 0?void 0:i.call(e)}catch(e){console.warn("Could not unmount Stripe element:",e)}this.element=null}if((t=c===null||c===void 0?void 0:c.instances)===null||t===void 0?void 0:t.stripeElements){c.instances.stripeElements=null}if((o=c===null||c===void 0?void 0:c.instances)===null||o===void 0?void 0:o.stripe){c.instances.stripe=null}}disconnectedCallback(){this.unlistenToFormState();this.unlistenToCheckout();this.clearStripeInstances()}getElementsConfig(){var e,i,t,o;const l=getComputedStyle(this.el);return{mode:((e=n.checkout)===null||e===void 0?void 0:e.remaining_amount_due)>0?"payment":"setup",amount:(i=n.checkout)===null||i===void 0?void 0:i.remaining_amount_due,currency:(t=n.checkout)===null||t===void 0?void 0:t.currency,setupFutureUsage:((o=n.checkout)===null||o===void 0?void 0:o.reusable_payment_method_required)?"off_session":null,appearance:{variables:{colorPrimary:l.getPropertyValue("--sc-color-primary-500")||"black",colorText:l.getPropertyValue("--sc-input-label-color")||"black",borderRadius:l.getPropertyValue("--sc-input-border-radius-medium")||"4px",colorBackground:l.getPropertyValue("--sc-input-background-color")||"white",fontSizeBase:l.getPropertyValue("--sc-input-font-size-medium")||"16px",colorLogo:l.getPropertyValue("--sc-stripe-color-logo")||"light",colorLogoTab:l.getPropertyValue("--sc-stripe-color-logo-tab")||"light",colorLogoTabSelected:l.getPropertyValue("--sc-stripe-color-logo-tab-selected")||"light",colorTextPlaceholder:l.getPropertyValue("--sc-input-placeholder-color")||"black"},rules:{".Input":{border:l.getPropertyValue("--sc-input-border")}}}}}maybeApplyFilters(e){var i,t,o;if(!((t=(i=window===null||window===void 0?void 0:window.wp)===null||i===void 0?void 0:i.hooks)===null||t===void 0?void 0:t.applyFilters))return e;return{...e,paymentMethodOrder:window.wp.hooks.applyFilters("surecart_stripe_payment_element_payment_method_order",[],n.checkout),wallets:window.wp.hooks.applyFilters("surecart_stripe_payment_element_wallets",{},n.checkout),terms:window.wp.hooks.applyFilters("surecart_stripe_payment_element_terms",{},n.checkout),fields:window.wp.hooks.applyFilters("surecart_stripe_payment_element_fields",(o=e.fields)!==null&&o!==void 0?o:{})}}createOrUpdateElements(){var e,i,t,o,l,s;if(!((e=n===null||n===void 0?void 0:n.checkout)===null||e===void 0?void 0:e.payment_method_required))return;if(!c.instances.stripe||this.isCreatingUpdatingStripeElement)return;if(((i=n.checkout)===null||i===void 0?void 0:i.status)&&["paid","processing"].includes((t=n.checkout)===null||t===void 0?void 0:t.status))return;this.isCreatingUpdatingStripeElement=true;if(!c.instances.stripeElements){c.instances.stripeElements=c.instances.stripe.elements(this.getElementsConfig());const e=p(m());const i=this.maybeApplyFilters({defaultValues:{billingDetails:{...((o=n.checkout)===null||o===void 0?void 0:o.name)?{name:n.checkout.name}:{},...((l=n.checkout)===null||l===void 0?void 0:l.email)?{email:n.checkout.email}:{},...((s=n.checkout)===null||s===void 0?void 0:s.phone)?{phone:n.checkout.phone}:{},...e?{address:e}:{}}},fields:{billingDetails:{email:"never"}}});c.instances.stripeElements.create("payment",i).mount(this.container);this.element=c.instances.stripeElements.getElement("payment");this.element.on("ready",(()=>this.loaded=true));this.element.on("change",(e=>{var i,t,o,l,s,d,a;const r=["cashapp","klarna","clearpay"];n.paymentMethodRequiresShipping=r.includes((i=e===null||e===void 0?void 0:e.value)===null||i===void 0?void 0:i.type);if(e.complete){this.scPaymentInfoAdded.emit({checkout_id:(t=n.checkout)===null||t===void 0?void 0:t.id,currency:(o=n.checkout)===null||o===void 0?void 0:o.currency,processor_type:"stripe",total_amount:(l=n.checkout)===null||l===void 0?void 0:l.total_amount,line_items:(s=n.checkout)===null||s===void 0?void 0:s.line_items,payment_method:{billing_details:{email:(d=n.checkout)===null||d===void 0?void 0:d.email,name:(a=n.checkout)===null||a===void 0?void 0:a.name}}})}}));this.isCreatingUpdatingStripeElement=false;return}c.instances.stripeElements.update(this.getElementsConfig());this.isCreatingUpdatingStripeElement=false}handleUpdateElement(){var e,i,t,o;if(!this.element)return;if(((e=n.checkout)===null||e===void 0?void 0:e.status)!=="draft")return;const l=p(m());const s=this.maybeApplyFilters({defaultValues:{billingDetails:{...((i=n.checkout)===null||i===void 0?void 0:i.name)?{name:n.checkout.name}:{},...((t=n.checkout)===null||t===void 0?void 0:t.email)?{email:n.checkout.email}:{},...((o=n.checkout)===null||o===void 0?void 0:o.phone)?{phone:n.checkout.phone}:{},...l?{address:l}:{}}},fields:{billingDetails:{email:"never"}}});this.element.update(s)}async submit(){if((s===null||s===void 0?void 0:s.id)!=="stripe")return;const{error:e}=await c.instances.stripeElements.submit();if(e){console.error({error:e});a("REJECT");f(e);this.error=e.message;return}}async maybeConfirmOrder(){var e,i,t,o,l,d,a,r,c,v,u,f,p,m;if((s===null||s===void 0?void 0:s.id)!=="stripe")return;if(((i=(e=n.checkout)===null||e===void 0?void 0:e.payment_intent)===null||i===void 0?void 0:i.processor_type)!=="stripe")return;if(!((d=(l=(o=(t=n.checkout)===null||t===void 0?void 0:t.payment_intent)===null||o===void 0?void 0:o.processor_data)===null||l===void 0?void 0:l.stripe)===null||d===void 0?void 0:d.type))return;if(!((v=(c=(r=(a=n.checkout)===null||a===void 0?void 0:a.payment_intent)===null||r===void 0?void 0:r.processor_data)===null||c===void 0?void 0:c.stripe)===null||v===void 0?void 0:v.client_secret))return;return await this.confirm((m=(p=(f=(u=n.checkout)===null||u===void 0?void 0:u.payment_intent)===null||f===void 0?void 0:f.processor_data)===null||p===void 0?void 0:p.stripe)===null||m===void 0?void 0:m.type)}async confirm(e,i={}){var t,o,l,s,d,r,v;const u=p(m());const y={elements:c.instances.stripeElements,clientSecret:(s=(l=(o=(t=n.checkout)===null||t===void 0?void 0:t.payment_intent)===null||o===void 0?void 0:o.processor_data)===null||l===void 0?void 0:l.stripe)===null||s===void 0?void 0:s.client_secret,confirmParams:{return_url:h(window.location.href,{...n.checkout.id?{checkout_id:n.checkout.id}:{}}),payment_method_data:{billing_details:{...((d=n.checkout)===null||d===void 0?void 0:d.email)?{email:n.checkout.email}:{},...((r=n.checkout)===null||r===void 0?void 0:r.name)?{name:n.checkout.name}:{},...((v=n.checkout)===null||v===void 0?void 0:v.phone)?{phone:n.checkout.phone}:{},...u?{address:u}:{}}}},redirect:"if_required",...i};if(this.confirming)return;if(!c.instances.stripe)return;try{this.scSetState.emit("PAYING");const i=e==="setup"?await c.instances.stripe.confirmSetup(y):await c.instances.stripe.confirmPayment(y);if(i===null||i===void 0?void 0:i.error){this.error=i.error.message;throw i.error}else{this.scSetState.emit("PAID");this.scPaid.emit()}}catch(e){console.error(e);a("REJECT");f(e);if(e.message){this.error=e.message}}finally{this.confirming=false}}render(){return t("div",{key:"62045da9bff951fac624f0ee095b1ee6fd5d6ec7",class:"sc-stripe-payment-element","data-testid":"stripe-payment-element"},!!this.error&&t("sc-text",{key:"e0209d355f391e4c87791a32857723a8dd2f65f6",style:{color:"var(--sc-color-danger-500)","--font-size":"var(--sc-font-size-small)",marginBottom:"0.5em"}},this.error),t("div",{key:"cd5dab61cf6ef21734ea1bd65c6c30339c5b4f25",class:"loader",hidden:this.loaded},t("div",{key:"5a6e1bf3de0980a246ee742433a7de49b38f16ef",class:"loader__row"},t("div",{key:"4a8f54f8042e6baf73c845ee6ba0bae1e0945b93",style:{width:"50%"}},t("sc-skeleton",{key:"dc03cd2e49b2d84ae8144c630ca8c272a8d26913",style:{width:"50%",marginBottom:"0.5em"}}),t("sc-skeleton",{key:"8f946572cd75d5010aa7ee95c23e1de080cd0c0b"})),t("div",{key:"612cd57feb0809fd39b77c50b6431952a52f4984",style:{flex:"1"}},t("sc-skeleton",{key:"15ed79b9f32f30ab10404e1a114966e0b9ddbbed",style:{width:"50%",marginBottom:"0.5em"}}),t("sc-skeleton",{key:"47b07c198bf27f739f1d2a5c05cfbbcb65c76e27"})),t("div",{key:"0d1d298c9782e9a212a21fb3128b6634ca7b4db3",style:{flex:"1"}},t("sc-skeleton",{key:"1e8be09d9b30a178376b5927f71b4175cc0ded2d",style:{width:"50%",marginBottom:"0.5em"}}),t("sc-skeleton",{key:"2fbc497390ec3055a36397ed271336d22fa5e35d"}))),t("div",{key:"b28e232f00ac20952be7fc5b4a58990e3f9e47c1",class:"loader__details"},t("sc-skeleton",{key:"11b99f2ef41ba0b4c2abc2c432c9ee508ed30206",style:{height:"1rem"}}),t("sc-skeleton",{key:"c5ad73ac9c81feeeeb4a36d4b2480315763ad9a7",style:{height:"1rem",width:"30%"}}))),t("div",{key:"5b9da343268d24c0f0704636975cd13d245c4a3f",hidden:!this.loaded,class:"sc-payment-element-container",ref:e=>this.container=e}))}get el(){return o(this)}static get watchers(){return{styles:["handleStylesChange"]}}};g.style=b;export{g as sc_stripe_payment_element}; //# sourceMappingURL=p-634860e0.entry.js.map
Save
Back