1import{s as N,Q as T,p as _,r as m,T as $,l as U,K as D,c as V,o as A,w as p,a as r,t as a,h as K,x as v,z as w,b as x,u as E,f as g,A as S}from"./app-DDSQZi8b.js";import{l as z}from"./index-BS5DzTJm.js";import{_ as B}from"./ActionMessage-CIJlOAlq.js";import{_ as F}from"./BillingSection-CV36WjO0.js";import"./SectionTitle-CplT-p85.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";const H={class:"text-right mb-4"},I={class:"text-sm font-medium text-gray-700"},O={for:"billingCardName",class:"block text-sm font-medium text-gray-700"},Y={for:"card-element",class:"block text-sm font-medium text-gray-700"},Z={for:"billing-postalcode",class:"block text-sm font-medium text-gray-700"},j={class:"flex justify-end items-center gap-4"},Q={type:"submit",class:"float-right mb-4 inline-flex items-center px-4 py-2 btn btn-primary btn-sm border border-transparent rounded-md font-semibold text-xs text-white dark:text-gray-800 uppercase tracking-widest hover:bg-gray-700 dark:hover:bg-white focus:bg-gray-700 dark:focus:bg-white active:bg-gray-900 dark:active:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800 transition ease-in-out duration-150"},ee={__name:"PaymentMethod",setup(q){const n=N(),k=T(),b=_(()=>n.state.userbilling.subscription),C=_(()=>{var e,t;return((t=(e=n.state.userbilling)==null?void 0:e.subscription)==null?void 0:t.stripeKey)||n.state.userbilling.stripeKey});let l=null,i=null;const d=m(""),c=m("");let M=m("");m(!1);const u=$({payment_method:""});U(async()=>{var e,t,o;try{if(M.value=(o=(t=(e=b.value)==null?void 0:e.subscription)==null?void 0:t.owner)==null?void 0:o.pm_last_four,l=await z(C.value),!l){console.error("Stripe failed to initialize.");return}i=l.elements(),i.create("card",{hidePostalCode:!0}).mount("#card-element")}catch(s){console.error("Error loading Stripe:",s)}});const f=()=>{var o,s,y,h;const e=(y=(s=(o=b.value)==null?void 0:o.subscription)==null?void 0:s.owner)==null?void 0:y.pm_last_four,t=(h=k.props.auth.user)==null?void 0:h.pm_last_four;return e?"**** **** **** "+e:t?"**** **** **** "+t:""},P=async()=>{if(!l||!i){console.error("Stripe or Elements is not initialized.");return}try{const{error:e,paymentMethod:t}=await l.createPaymentMethod({type:"card",card:i.getElement("card"),allow_redisplay:"always",billing_details:{name:d.value,address:{postal_code:c.value}}});if(e){console.error("Error creating payment method:",e.message);return}u.payment_method=t.id,u.post("/api/update-payment-method",{preserveScroll:!0,onSuccess:async()=>{d.value="",c.value="",i.getElement("card").clear(),n.commit("userbilling/UPDATE_PAYMENT_METHOD",{last4:t.card.last4}),n.commit("userbilling/SET_PAYMENT_METHOD",t)},onError:o=>{o.payment_method?S.error(o.payment_method):S.error("Something went wrong."),console.error("Payment method update errors:",o)}})}catch(e){console.error("Error in handleSubmit:",e)}};return(e,t)=>{const o=D("InputError");return A(),V(F,null,{title:p(()=>[g(a(e.$t("Payment Method")),1)]),description:p(()=>[g(a(e.$t("Update your payment method.")),1)]),form:p(()=>[r("div",H,[r("span",I," Current Credit Card: "+a(f()?f():"None"),1)]),r("form",{onSubmit:K(P,["prevent"]),class:"space-y-6"},[r("div",null,[r("label",O,a(e.$t("Cardholder's Name")),1),v(r("input",{id:"billingCardName",type:"text","onUpdate:modelValue":t[0]||(t[0]=s=>d.value=s),placeholder:"Cardholder's Name",class:"mt-1 block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500"},null,512),[[w,d.value]])]),r("div",null,[r("label",Y,a(e.$t("Card")),1),t[2]||(t[2]=r("div",{id:"card-element",class:"mt-1 p-4 border border-gray-300 rounded-md bg-gray-50"},null,-1)),x(o,{message:E(u).errors.payment_method},null,8,["message"])]),r("div",null,[r("label",Z,a(e.$t("Zip / Postal code")),1),v(r("input",{id:"billing-postalcode",type:"text","onUpdate:modelValue":t[1]||(t[1]=s=>c.value=s),placeholder:"Zip / Postal code",class:"mt-1 block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500"},null,512),[[w,c.value]])]),r("div",j,[x(B,{on:E(u).recentlySuccessful,class:"me-3"},{default:p(()=>[g(a(e.$t("Updated")),1)]),_:1},8,["on"]),r("button",Q,a(e.$t("Update Payment Method")),1)])],32)]),_:1})}}};export{ee as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.