import{U as m,u,_ as p,o as l,e as h,w as r,h as d,al as y,n as f,f as b,t as g,i as _,g as c,q as S,ac as B,s as E,ag as C,ai as k}from"./index.cf09daef.js";import{l as P}from"./stripe.esm.385a2a03.js";const v={base:{iconColor:"#666EE8",color:"#31325F",lineHeight:"28px",fontWeight:400,fontSize:"14px","::placeholder":{color:"#CFD7E0"},":focus":{color:"#CFD7E0"}}},A={props:{id:{type:String,default:"card-element"},title:String,amount:[String,Number],btnLabel:String,processing:Boolean,pay:Boolean,add:Boolean,disabled:Boolean,dense:Boolean,hasButton:Boolean,billingDetails:Object},data(){return{loading:Boolean(this.processing),stripe:null,cardElement:null}},emits:["failed","success","confirmed"],methods:{async load(){if(!this.stripe_key)return!1;const t=this.stripe=await P(this.stripe_key),a=t.elements(),e=this.cardElement=a.create("card",{hidePostalCode:!0,style:v});e.mount(`#${this.id}`),document.getElementById(`${this.id}-card-button`).addEventListener("click",async i=>{this.loading=!0;const{paymentMethod:n,error:o}=await t.createPaymentMethod("card",e,{billing_details:{...this.billingDetails}});o?(this.loading=!1,this.$emit("failed",o.message),console.log("paymentMethod",o)):(this.loading=!1,this.$emit("success",n),console.log("paymentMethod",n))})},submit(){this.$refs["card-button"].$el.click()},confirmPaymentMethod({client_secret:t,payment_method:a}){this.loading=!0,this.stripe.confirmCardPayment(t,{setup_future_usage:"off_session",payment_method:a.id}).then(({error:s,paymentIntent:i})=>{this.loading=!1,s?(this.$emit("failed",s.message),console.log("paymentIntent",s)):(this.$emit("confirmed",i),console.log("paymentIntent",i))})}},async mounted(){await this.load()},computed:{...m(u,["stripePayment"]),stripe_key(){var t;return((t=this.stripePayment)==null?void 0:t.API_KEY)||{}.STRIPE_KEY},label(){return this.btnLabel||this.$t("payAmount",{amount:this.$core.money(this.amount)})},paymentMethods(){return[{title:"Card",type:"card",remember:!0,redirects:!1,element:"card"},{title:"Alipay",type:"alipay"},{title:"BECS Direct Debit",type:"au_becs_debit",remember:!0,redirects:!1,element:"auBankAccount"},{title:"Bancontact",type:"bancontact",remember:!0},{title:"EPS",type:"eps",element:"epsBank"},{title:"Giropay",type:"giropay"},{title:"iDEAL",type:"ideal",remember:!0,element:"idealBank"},{title:"SEPA Debit",type:"sepa_debit",remember:!0,redirects:!1,element:"iban",options:{supportedCountries:["SEPA"]}}].map(a=>({remember:!1,redirects:!0,options:{},...a}))}},watch:{processing:{deep:!0,handler(t){this.loading=Boolean(t)}},stripe_key(){this.load()}},unmounted(){this.cardElement.unmount(),[document.querySelectorAll("[name^=__privateStripeMetricsController]"),document.querySelectorAll("[name^=__privateStripeController]")].forEach(a=>a.forEach(e=>{e.parentNode.removeChild(e)}))}},D={key:0,class:"text-h6 q-mb-md"},w=["id"],M={class:"actions"};function $(t,a,e,s,i,n){return l(),h(k,{class:"stripe-credit-card"},{default:r(()=>[d(y,{class:f({"q-pa-none":e.dense})},{default:r(()=>[e.title?(l(),b("div",D,g(e.title),1)):_("",!0),c("div",{id:e.id},null,8,w),S(t.$slots,"default"),c("div",M,[B(d(E,{color:"primary","no-caps":"",class:"full-width",icon:"far fa-credit-card",label:n.label,loading:i.loading,disabled:e.disabled,id:`${e.id}-card-button`,ref:"card-button"},null,8,["label","loading","disabled","id"]),[[C,e.hasButton]])])]),_:3},8,["class"])]),_:3})}var q=p(A,[["render",$]]);export{q as S};
