1import{_ as I}from"./BFE_pyP7.js";import{_ as L}from"./C07Bvf6I.js";import{z as M,a as O,ak as K,G as U,k as n,m as i,l as a,j as e,t as o,x as v,f as x,O as b,F as P,R,e as N,v as y,r as C,a0 as G,w as T,E as q,aA as H,o as J,P as Q,aB as W,q as z,n as X,y as w,an as Y,M as Z,b as ee,a5 as te,a2 as F,_ as se,aC as ae,a3 as oe}from"./mEzNQUA2.js";import{_ as ne}from"./CA7uey8z.js";import{_ as re}from"./D6-abTFg.js";import"./BKiTnmA2.js";import"./_02Ei6BK.js";import"./BceMUvbb.js";import"./_IojVz0O.js";const ie={key:0,id:"klarna-fail"},le={class:"alert alert-danger",role:"alert"},ce={key:0,class:"alert alert-info"},de=["disabled"],ue=M({__name:"klarnaPayments",props:{orderData:{type:Object,required:!0},klarnaToken:{type:String,required:!0}},setup(S){const{t:u}=O(),k=K(),t=S,p=C(!1),c=C(""),m=C(!1),s=C(!1);window.klarnaAsyncCallback=function(){Klarna.Payments.init({client_token:t.klarnaToken}),Klarna.Payments.load({container:"#klarna-payments-container"},{},function(l){l.show_form||(p.value=!0,c.value=u("no_payment_details_message")),l.error&&(p.value=!0,c.value=JSON.parse(l.error))})};const g=l=>{const r=l.split(" ");return{given_name:r.slice(0,-1).join(" ")||"",family_name:r[r.length-1]||""}},h=()=>{m.value=!0;const l=g(t.orderData.customers.invoicing.name),r=g(t.orderData.customers.delivery.name),$={given_name:l.given_name,family_name:l.family_name,email:t.orderData.customers.invoicing.email.length>0?t.orderData.customers.invoicing.email:t.orderData.email,street_address:t.orderData.customers.invoicing.address.street,postal_code:t.orderData.customers.invoicing.address.zipcode,city:t.orderData.customers.invoicing.address.city,phone:t.orderData.customers.invoicing.phone.length>0?t.orderData.customers.invoicing.phone:t.orderData.phone,country:t.orderData.customers.invoicing.address.country},d={given_name:r.given_name,family_name:r.family_name,email:t.orderData.customers.delivery.email.length>0?t.orderData.customers.delivery.email:t.orderData.email,street_address:t.orderData.customers.delivery.address.street,postal_code:t.orderData.customers.delivery.address.zipcode,city:t.orderData.customers.delivery.address.city,phone:t.orderData.customers.delivery.phone.length>0?t.orderData.customers.delivery.phone:t.orderData.phone,country:t.orderData.customers.delivery.address.country};Klarna.Payments.authorize({instance_id:`klarna-payments-instance-${t.orderData.id}`},{billing_address:$,shipping_address:d},async function(f){if(f.approved){s.value=!0;try{await $fetch("/api/klarna/authorize",{method:"POST",body:{order_id:t.orderData.id,authorization_token:f.authorization_token}}),G({path:k(`/payment/ok?payment=klarnapayments&pmt_id=${t.orderData.id}`),ttl:1e3,force:!0})}catch{s.value=!1,m.value=!1,p.value=!0,c.value=u("payment_cancelled")}}else m.value=!1,p.value=!0,c.value=u("payment_cancelled")})};return U({script:[{id:"klarna-payments-script",src:"https://x.klarnacdn.net/kp/lib/v1/api.js",async:!0}]}),(l,r)=>{const $=L,d=I;return n(),i(P,null,[r[0]||(r[0]=a("div",{id:"klarna-payments-container"},null,-1)),S.klarnaToken.length<=0||e(p)&&e(c).length>0?(n(),i("div",ie,[a("div",le,o(e(c)),1),a("p",null,[v($,{class:"btn btn-default",to:"/checkout"},{default:x(()=>[b(o(l.$t("back")),1)]),_:1})])])):(n(),i(P,{key:1},[e(s)?(n(),i("div",ce,[v(d),b(" "+o(l.$t("v1.views.checkout.payment.processing_payment")),1)])):(n(),i("button",{key:1,class:"btn btn-success btn-lg btn-block",type:"button",disabled:e(m),onClick:R(h,["prevent"])},[e(m)?(n(),N(d,{key:0})):y("",!0),b(" "+o(l.$t("to_payment_button_text")),1)],8,de))],64))],64)}}}),me={key:0},_e={class:"alert alert-info"},pe={key:1},ye={class:"alert alert-danger"},ve={key:2},he={key:0},fe={class:"alert alert-info"},ke=["data-submethod","action","method"],ge=["name","type","value"],be=["src","alt"],$e={key:1,class:"btn btn-success btn-lg btn-block",type:"submit",name:"smt_button"},De=M({__name:"form",props:{orderId:{type:Number,required:!0},selectedMethod:{type:String,default:"",required:!1},autoSubmit:{type:Boolean,default:!1}},async setup(S){let u,k;const t=S,{data:p,error:c,status:m}=([u,k]=T(()=>q(`paymentform/${t.orderId}`,()=>H(t.orderId))),u=await u,k(),u),s=w(()=>m.value!=="pending"&&!c.value?p.value:[]),g=w(()=>(s.value?.length??0)>1),h=w(()=>m.value!=="pending"&&(s.value?.length??0)===0),l=C(!1);return J(()=>{if(!t.autoSubmit||!s.value?.length){l.value=!0;return}setTimeout(()=>{let r=null;s.value?.length===1?r=document.querySelector("form.payment-form"):t.selectedMethod.length>0&&(r=document.querySelector(`form[data-submethod="${t.selectedMethod}"]`)),r?r.submit():l.value=!0},100)}),(r,$)=>{const d=I,f=L;return e(m)==="pending"?(n(),i("div",me,[a("div",_e,[v(d),b(" "+o(r.$t("loading"))+"... ",1)])])):e(c)||e(h)?(n(),i("div",pe,[a("div",ye,o(r.$t("op_checkout_error_notice")),1),v(f,{to:"/checkout",class:"btn btn-secondary"},{default:x(()=>[b(o(r.$t("return_to_checkout")),1)]),_:1})])):(n(),i("div",ve,[e(l)?y("",!0):(n(),i("div",he,[a("div",fe,[v(d),b(" "+o(r.$t("loading"))+"... ",1)])])),Q(a("div",{class:X({"btn-wrapper":e(g)})},[(n(!0),i(P,null,z(e(s),_=>(n(),i("form",{key:_.form.action,"data-submethod":_.id,action:_.form.action,method:_.form.method,class:"payment-form"},[(n(!0),i(P,null,z(_.form.inputs,D=>(n(),i("input",{key:D.name,name:D.name,type:D.type,value:D.value}
1,null,8,ge))),128)),_.picture?(n(),i("input",{key:0,type:"image",class:"pm-logo",src:_.picture,alt:r.$t("to_payment_button_text")},null,8,be)):y("",!0),e(g)?y("",!0):(n(),i("button",$e,o(r.$t("to_payment_button_text")),1))],8,ke))),128))],2),[[W,e(l)]])]))}}}),we=Y(De,[["__scopeId","data-v-390b32f4"]]),Pe={class:"alert alert-info"},Se={key:2,class:"row border-bottom py-3"},Ce={key:0,class:"col-12 col-sm-6 pb-2 pb-sm-0"},Ne={class:"row"},xe={class:"col-sm-4 os-font-weight-semibold"},Ie={class:"col-sm-8 d-flex flex-column"},Me={key:0},ze={class:"col-12 col-sm-6"},Fe={class:"row"},Le={class:"col-sm-4 os-font-weight-semibold"},Oe={class:"col-sm-8 d-flex flex-column"},Te={key:0},qe={class:"row justify-content-end py-3"},Ae={class:"col-12 col-sm-6"},Je=M({__name:"[id]",async setup(S){let u,k;const t=Z(),{t:p}=O(),c=w(()=>parseInt(t.params.id)),m=w(()=>`${p("to_payment_title")} ${c.value}`);ee({title:m});const{data:s,status:g,error:h}=([u,k]=T(()=>q(`order/${c.value}`,()=>ae(c.value))),u=await u,k(),u),l=w(()=>s.value?.paymentMethod?.submethod??""),r=te("autoSubmitPaymentOrderId",()=>0),$=r.value===c.value;if(r.value=0,h.value){const d=h.value.message,f=h.value.statusCode;h.value=null,f===404?F({statusCode:404,statusMessage:"Data not found"}):F({message:d,statusCode:f})}return(d,f)=>{const _=I,D=ue,A=we,B=ne,j=re,V=oe,E=se;return n(),N(E,{name:"nosidenav"},{default:x(()=>[v(V,null,{default:x(()=>[e(g)==="pending"?(n(),i(P,{key:0},[a("h1",null,o(d.$t("order"))+" "+o(e(c)),1),a("div",Pe,[v(_),b(" "+o(d.$t("loading"))+"... ",1)])],64)):e(s)?(n(),i(P,{key:1},[a("h1",null,o(d.$t("to_payment_title")),1),a("p",null,o(d.$t("to_payment_info_text")),1),e(s).paymentMethod.id==="klarnapayments"?(n(),N(D,{key:0,"order-data":e(s),"klarna-token":e(s).paymentMethod?.token??""},null,8,["order-data","klarna-token"])):(n(),N(A,{key:1,"order-id":e(c),"selected-method":e(l),"auto-submit":$},null,8,["order-id","selected-method"])),e(s).customers?(n(),i("div",Se,[e(s).customers.invoicing?(n(),i("div",Ce,[a("div",Ne,[a("div",xe,o(d.$t("customer"))+": ",1),a("div",Ie,[a("span",null,o(e(s).customers.invoicing.name),1),a("span",null,o(e(s).customers.invoicing.address.street),1),a("span",null,o(e(s).customers.invoicing.address.zipcode)+" "+o(e(s).customers.invoicing.address.city),1),e(s).customers.invoicing.address.country!=="FI"?(n(),i("span",Me,o(e(s).customers.invoicing.address.country),1)):y("",!0)])])])):y("",!0),a("div",ze,[a("div",Fe,[a("div",Le,o(d.$t("delivery"))+": ",1),a("div",Oe,[a("span",null,o(e(s).customers.delivery.name),1),a("span",null,o(e(s).customers.delivery.address.street),1),a("span",null,o(e(s).customers.delivery.address.zipcode)+" "+o(e(s).customers.delivery.address.city),1),e(s).customers.delivery.address.country!=="FI"?(n(),i("span",Te,o(e(s).customers.delivery.address.country),1)):y("",!0)])])])])):y("",!0),v(B,{cart:e(s).cart,"vat-on":e(s).paymentVatOn,"show-totals":!1},null,8,["cart","vat-on"]),a("div",qe,[a("div",Ae,[v(j,{order:e(s)},null,8,["order"])])])],64)):y("",!0)]),_:1})]),_:1})}}});
1export{Je 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.