import{i as e,n as t,u as n}from"./nc-main-C6OeyNBF.js";import{createBlock as r,createCommentVNode as i,createElementBlock as a,createElementVNode as o,createTextVNode as s,createVNode as c,inject as l,onUnmounted as u,openBlock as d,ref as f,resolveComponent as p,unref as m,withCtx as h}from"/vue.js";var g=f(!1),_;function v(e){g.value=e}async function y(){return new Promise((e,t)=>{let n=document.createElement(`script`);n.setAttribute(`src`,`https://beta.hyperswitch.io/v1/HyperLoader.js`),n.setAttribute(`type`,`text/javascript`),document.head.appendChild(n),n.onload=()=>e(),n.onerror=()=>t()})}var b,x;async function S(e,r){_=e,b||(b=Hyper(`pk_snd_20ab944e9d684c3db90177706f134777`)),t.callServer(_,`payment/create`,{parameter:{items:[{id:`xl-tshirt`}],country:`FI`,payment:{amount:10,currency:`EUR`}}},e=>{let t=e.client_secret;x=b.widgets({appearance:{},clientSecret:t});let i={layout:{type:`accordion`,defaultCollapsed:!1,radios:!0,spacedAccordionItems:!0},wallets:{walletReturnUrl:n()+`/payment/complete`}};x.create(`payment`,i).mount(`#unified-checkout`),r()})}async function C(t){t.preventDefault(),v(!0);let r={return_url:n()+`/payment/complete`},i=setTimeout(()=>{w()},10),a=await b.confirmPayment({widgets:x,confirmParams:r});clearTimeout(i),console.log(`🚀 ~ processPayment ~ hyper.confirmPayment() ~ ret:`,a);let o=a.error||{type:a.error_code,message:a.error_message};if(o&&o.message)o.type===`validation_error`?e.setError(_,`An payment validation error occurred, error: '${o.message}'`):e.setError(_,`An unexpected payment error type '${o.type||`unknown`}' occurred, error: '${o.message}'`);else if(a.status===`succeeded`){let{amount:t,amount_received:n,net_amount:r,connector:i,payment_id:o,created:s,currency:c}=a;e.setSuccess(_,`Payment succeeded, result: ${JSON.stringify({amount:t,amount_received:n,net_amount:r,connector:i,payment_id:o,created:s,currency:c},null,2)}`)}else e.setError(_,`An unexpected payment error occurred, result: ${JSON.stringify(a)}`);v(!1)}async function w(){let t=new URLSearchParams(window.location.search).get(`payment_intent_client_secret`);if(!t)return;console.log(`🚀 ~ checkStatus ~ clientSecret:`,t);let n=await b.retrievePayment(t);switch(console.log(`🚀 ~ checkStatus ~ hyper.retrievePayment() ~ ret:`,n),(n.payment||{}).status){case`succeeded`:e.setSuccess(_,`Payment succeeded!`);break;case`processing`:e.setInfo(_,`Your payment is processing.`);break;case`requires_payment_method`:e.setWarning(_,`Your payment was not successful, please try again.`);break;default:e.setError(_,`Something went wrong, result: '${JSON.stringify(n,null,2)}'`);break}}var T={class:`nc-payment`,id:`payment-form`},E={id:`button-text`},D=Object.assign({name:`NcPayment`},{__name:`nc-payment`,setup(t){let n=f(!1),_=l(`state`);async function v(){y().then(()=>{S(_,()=>{let e,t=`orca-payment-element-iframeRef-unified-checkout`,r=0,i=setInterval(()=>{r++,e=document.getElementById(t),e?(console.debug(`id found`,e),clearInterval(i),setTimeout(()=>{n.value=!0},1e3)):(r>20&&(t=`orca-element-unified-checkout`),console.debug(`id`,e))},100)})}).catch(()=>{e.setError(_,`Loading HyperSwitch Payment script failed`)})}return v(),u(()=>{n.value=!1}),(e,t)=>{let l=p(`nc-header`),u=p(`nc-row`),f=p(`nc-col`),_=p(`nc-translate`),v=p(`nc-button`),y=p(`nc-span`);return d(),a(`form`,T,[c(u,{class:`nc-center-h`},{default:h(()=>[c(l,{size:`medium`,hdr:m(n)?`hdr.login.payment_select`:`hdr.login.payment_loading`},null,8,[`hdr`])]),_:1}),c(u,{class:`nc-center-h nc-margin-top`},{default:h(()=>[c(f,{id:`unified-checkout`})]),_:1}),c(u,{class:`nc-center-h`},{default:h(()=>[c(v,{disabled:!m(n),onClick:m(C)},{default:h(()=>[t[1]||(t[1]=o(`div`,{class:`spinner hidden`,id:`spinner`},null,-1)),o(`span`,E,[c(_,{hdr:`hdr.login.payment_pay_now`},{default:h(()=>[...t[0]||(t[0]=[s(`Pay now`,-1)])]),_:1})])]),_:1},8,[`disabled`,`onClick`]),t[2]||(t[2]=o(`div`,{class:`hidden`,id:`payment-message`},null,-1))]),_:1}),c(u,{class:`nc-center-h`},{default:h(()=>[m(g)?(d(),r(y,{key:0},{default:h(()=>[c(_,{hdr:`hdr.login.payment_processing`},{default:h(()=>[...t[3]||(t[3]=[s(`Processing payment...`,-1)])]),_:1})]),_:1})):i(``,!0)]),_:1})])}}});export{D as default};