@paynext/sdk 0.0.43 → 0.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -20,7 +20,7 @@
20
20
  <line x1='1' y1='8' x2='27' y2='8'></line>
21
21
  </svg>
22
22
  <span class="${L.srOnly}">Pay with</span>
23
- `);l(this,"element",document.createElement("div"));this.element.classList.add(L.card),this.element.innerHTML=this.template}render(){return this.element}}const Tt={button:"_button_1br9w_1",press:"_press_1br9w_21"};class ic{constructor(e){l(this,"element");l(this,"icon",new nc);this.element=document.createElement("button"),this.element.classList.add(Tt.button);const r=document.createElement("span");r.textContent=e.getState().messages.card.compact.button,this.element.append(this.icon.render(),r),this.element.addEventListener("mousedown",()=>this.element.classList.add(Tt.press)),this.element.addEventListener("mouseup",()=>this.element.classList.remove(Tt.press)),this.element.addEventListener("mouseout",()=>this.element.classList.remove(Tt.press)),e.subscribe(({messages:n})=>{r.textContent=n.card.compact.button})}addEventListener(e){return this.element.addEventListener("click",e)}render(){return this.element}}const ac=(t,e,r)=>e.concat(t.filter(n=>e.every(i=>!r(n,i)))),xr=(t="sandbox")=>({develop:"https://api-dev.paynext.com/v1",sandbox:"https://sandbox-api.paynext.com/v1",production:"https://api.paynext.com/v1"})[t],sc=[{type:"paypal",order:1,is_active:!0},{type:"apple-pay",order:2,is_active:!0},{type:"google-pay",order:3,is_active:!0},{type:"card",order:4,is_active:!0}],oc=(t,e="sandbox")=>b(this,null,function*(){var s,o,c,u,d,p,h,f,m,g,y,v,T,k,I,w,A,V,C,R,B,q,me,W,fe,re,Ke,Be,Ae,J,G,ye,be,ve,we,xe,Ce,_e,ne,le,ce,ie,ae,lt,ct,dt,ut,pt,ht,mt,ft,gt,yt,bt,Li,Ti,Ii,Ai,Vi,Si,Mi,Pi,ji,Di,Ni,Oi,Ri,qi,Ki,Bi,zi,Fi,$i,Gi,Ui,Hi,Yi,Zi,Wi,Ji,Xi,Qi,ea,ta,ra,na,ia,aa,sa,oa,la,ca,da,ua,pa,ha,ma,fa,ga,ya,ba,va,wa,xa,Ca,_a,ka,Ea,La,Ta,Ia,Aa;const r=`${xr(e)}/payments/create`,n=new Headers;return n.append("Content-Type","application/json"),yield(yield fetch(r,{method:"POST",headers:n,body:JSON.stringify({client_session:t.clientSession,three_ds_session_id:t.threeDsSessionId,type:t.googlePay?"GPAY":t.applePay?"APPLEPAY":t.paypal?"PAYPAL":"CARD",name:(o=(s=t.applePay)==null?void 0:s.billingContact)!=null&&o.givenName?((p=(d=t.applePay)==null?void 0:d.billingContact)==null?void 0:p.givenName)+" "+((f=(h=t.applePay)==null?void 0:h.billingContact)==null?void 0:f.familyName):(u=(c=t.card)==null?void 0:c.metadata)==null?void 0:u.name,phone:(g=(m=t.applePay)==null?void 0:m.shippingContact)==null?void 0:g.phoneNumber,billing_address:t.applePay||t.googlePay?{city:((v=(y=t.applePay)==null?void 0:y.billingContact)==null?void 0:v.locality)||((k=(T=t==null?void 0:t.googlePay)==null?void 0:T.billingAddress)==null?void 0:k.locality)||void 0,country:((w=(I=t.applePay)==null?void 0:I.billingContact)==null?void 0:w.countryCode)||((V=(A=t==null?void 0:t.googlePay)==null?void 0:A.billingAddress)==null?void 0:V.countryCode)||void 0,line1:((B=(R=(C=t.applePay)==null?void 0:C.billingContact)==null?void 0:R.addressLines)==null?void 0:B.at(0))||((me=(q=t==null?void 0:t.googlePay)==null?void 0:q.billingAddress)==null?void 0:me.address1)||void 0,line2:((re=(fe=(W=t.applePay)==null?void 0:W.billingContact)==null?void 0:fe.addressLines)==null?void 0:re.at(1))||((Be=(Ke=t==null?void 0:t.googlePay)==null?void 0:Ke.billingAddress)==null?void 0:Be.address2)||void 0,postal_code:((J=(Ae=t.applePay)==null?void 0:Ae.billingContact)==null?void 0:J.postalCode)||((ye=(G=t==null?void 0:t.googlePay)==null?void 0:G.billingAddress)==null?void 0:ye.postalCode)||void 0,state:((ve=(be=t.applePay)==null?void 0:be.billingContact)==null?void 0:ve.administrativeArea)||((xe=(we=t==null?void 0:t.googlePay)==null?void 0:we.billingAddress)==null?void 0:xe.administrativeArea)||void 0}:void 0,card:t.card||(Ce=t.googlePay)!=null&&Ce.card||(_e=t.applePay)!=null&&_e.card?{bin:(ne=t.card)==null?void 0:ne.firstSixDigits,bin_data:{brand:((le=t.card)==null?void 0:le.cardBrand)||((ie=(ce=t.googlePay)==null?void 0:ce.card)==null?void 0:ie.brand)||((lt=(ae=t.applePay)==null?void 0:ae.card)==null?void 0:lt.brand),country:((ct=t.card)==null?void 0:ct.country)||((ut=(dt=t.googlePay)==null?void 0:dt.card)==null?void 0:ut.country)||((ht=(pt=t.applePay)==null?void 0:pt.card)==null?void 0:ht.country),currency_code:((mt=t.card)==null?void 0:mt.currency)||((gt=(ft=t.googlePay)==null?void 0:ft.card)==null?void 0:gt.currency)||((bt=(yt=t.applePay)==null?void 0:yt.card)==null?void 0:bt.currency),funding:((Li=t.card)==null?void 0:Li.funding)||((Ii=(Ti=t.googlePay)==null?void 0:Ti.card)==null?void 0:Ii.funding)||((Vi=(Ai=t.applePay)==null?void 0:Ai.card)==null?void 0:Vi.funding),issuer:((Si=t.card)==null?void 0:Si.issuer)||((Pi=(Mi=t.googlePay)==null?void 0:Mi.card)==null?void 0:Pi.issuer)||((Di=(ji=t.applePay)==null?void 0:ji.card)==null?void 0:Di.issuer),type:((Ni=t.card)==null?void 0:Ni.type)||((Ri=(Oi=t.googlePay)==null?void 0:Oi.card)==null?void 0:Ri.segment)||((Ki=(qi=t.applePay)==null?void 0:qi.card)==null?void 0:Ki.segment)},cvc:(Bi=t.card)==null?void 0:Bi.cvc,exp_month:(zi=t.card)!=null&&zi.expMonth||($i=(Fi=t.googlePay)==null?void 0:Fi.card)!=null&&$i.expiry.month?Number(((Gi=t.card)==null?void 0:Gi.expMonth)||((Hi=(Ui=t.googlePay)==null?void 0:Ui.card)==null?void 0:Hi.expiry.month)):void 0,exp_year:(Yi=t.card)!=null&&Yi.expYear||(Wi=(Zi=t.googlePay)==null?void 0:Zi.card)!=null&&Wi.expiry.year?Number(((Ji=t.card)==null?void 0:Ji.expYear)||((Qi=(Xi=t.googlePay)==null?void 0:Xi.card)==null?void 0:Qi.expiry.year)):void 0,last4:((ea=t.card)==null?void 0:ea.lastFourDigits)||((ra=(ta=t.googlePay)==null?void 0:ta.card)==null?void 0:ra.lastFour)||((ia=(na=t.applePay)==null?void 0:na.card)==null?void 0:ia.lastFour),number:((aa=t.card)==null?void 0:aa.number)||((oa=(sa=t.googlePay)==null?void 0:sa.card)==null?void 0:oa.number)}:void 0,paypal:(la=t.paypal)!=null&&la.billing_agreement_token.paypalId?{billing_agreement_token:(ca=t.paypal)==null?void 0:ca.billing_agreement_token.paypalId}:void 0,google_pay:t.googlePay&&t.googlePay.token?{cryptogram:t.googlePay.cryptogram,eci:t.googlePay.eci,exp_month:(ua=(da=t.googlePay)==null?void 0:da.card)!=null&&ua.expiry.month||(pa=t.googlePay)!=null&&pa.token.expiry.month?Number(t.googlePay.card.expiry.month||t.googlePay.token.expiry.month):void 0,exp_year:(ma=(ha=t.googlePay)==null?void 0:ha.card)!=null&&ma.expiry.year||(fa=t.googlePay)!=null&&fa.token.expiry.year?Number(t.googlePay.card.expiry.year||t.googlePay.token.expiry.year):void 0,token:(ya=(ga=t.googlePay)==null?void 0:ga.token)==null?void 0:ya.number,token_service_provider:(va=(ba=t.googlePay)==null?void 0:ba.token)==null?void 0:va.tokenServiceProvider}:void 0,apple_pay:t.applePay?{cryptogram:t.applePay.cryptogram,eci:t.applePay.eci,exp_month:(Ca=(xa=(wa=t.applePay)==null?void 0:wa.networkToken)==null?void 0:xa.expiry)!=null&&Ca.month?Number(t.applePay.networkToken.expiry.month):void 0,exp_year:(Ea=(ka=(_a=t.applePay)==null?void 0:_a.networkToken)==null?void 0:ka.expiry)!=null&&Ea.year?Number(t.applePay.networkToken.expiry.year):void 0,token:(Ta=(La=t.applePay)==null?void 0:La.networkToken)==null?void 0:Ta.number,token_service_provider:(Aa=(Ia=t.applePay)==null?void 0:Ia.networkToken)==null?void 0:Aa.tokenServiceProvider}:void 0})})).json()}),lc=(t,e="sandbox")=>b(this,null,function*(){const r=`${xr(e)}/payments/create/billing/agreement`,n=new Headers;return n.append("Content-Type","application/json"),(yield(yield fetch(r,{method:"POST",headers:n,body:JSON.stringify({client_session:t})})).json()).paypal_agreement_token_response.token_id||""}),cc=(t,e="sandbox")=>b(this,null,function*(){const r=`${xr(e)}/payments/config?client_session_id=${t}`,i=yield(yield fetch(r)).json();return i.checkout_config||(i.checkout_config=sc),i});var yi=(t=>(t.Card="CARD",t))(yi||{});class dc{constructor(e){l(this,"isAppleReady",!0);l(this,"isGoogleReady",!0);l(this,"isPayPalReady",!0);l(this,"buttons");l(this,"applePay");l(this,"googlePay");l(this,"paypal");l(this,"card");l(this,"events",{ready:new D,open:new D,error:new D,cancel:new D,success:new D});this.config=e,this.applePay=new Rl(e.service.ev),this.paypal=new ec(e.service.paypal),this.googlePay=new Ql(e.service.ev),this.card=new ic(e.state.translate),this.buttons=document.createElement("div"),this.buttons.classList.add(gr.buttons,gr.hidden)}init(){return b(this,null,function*(){this.config.state.transaction.subscribe(()=>{this.config.service.ev.isReady&&this.initPaymentMethods().catch(console.error)}),this.config.state.checkout.subscribe(()=>{this.config.service.ev.isReady&&this.initPaymentMethods().catch(console.error)}),this.config.service.ev.addEventListener("ready",()=>{this.initPaymentMethods().catch(console.error)}),this.card.addEventListener(()=>this.events.open.emit())})}initApple(){return b(this,null,function*(){this.isAppleReady=!1,this.buttons.appendChild(this.applePay.render());const e=this.config.state.transaction.getState(),{locale:r,supportedCardTypes:n}=this.config.state.checkout.getState(),i=Jl(e);try{if(!i)return;yield this.applePay.init({transaction:i,supportedCardTypes:Xl(n),locale:tc(r||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:a=>this.events.success.emit(j(E({},a),{type:"apple"}))})}catch(a){console.error(a)}finally{this.isAppleReady=!0}})}initGoogle(){return b(this,null,function*(){this.isGoogleReady=!1,this.buttons.appendChild(this.googlePay.render());const e=this.config.state.transaction.getState(),{locale:r}=this.config.state.checkout.getState(),n=Wl(e);try{if(!n)return;yield this.googlePay.init({transaction:n,locale:rc(r||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:i=>this.events.success.emit(j(E({},i),{type:"google"}))})}catch(i){console.error(i)}finally{this.isGoogleReady=!0}})}initPayPal(){return b(this,null,function*(){var i,a;this.isPayPalReady=!1,this.buttons.appendChild(this.paypal.render());const e=this.config.state.transaction.getState(),r=this.config.state.checkout.getState(),n=()=>b(this,null,function*(){return yield lc(r.clientToken,r.environment)});try{if(!e)return;yield this.paypal.init({clientId:((i=e==null?void 0:e.paypal_info)==null?void 0:i.client_id)||"",environment:((a=e==null?void 0:e.paypal_info)==null?void 0:a.environment)||"sandbox",createBillingAgreement:n,onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:s=>this.events.success.emit({paypalId:s,type:"paypal"})})}catch(s){console.error(s)}finally{this.isPayPalReady=!0}})}initCard(){return b(this,null,function*(){this.buttons.appendChild(this.card.render())})}initPaymentMethods(){return b(this,null,function*(){const e=this.config.state.transaction.getState(),n=ac(ql,(e==null?void 0:e.checkout_config)||[],(i,a)=>i.type===a.type).filter(({is_active:i})=>i).sort((i,a)=>i.order-a.order).map(({type:i})=>{switch(i){case"apple-pay":return this.initApple();case"google-pay":return this.initGoogle();case"paypal":return this.initPayPal();case"card":return this.initCard();default:throw new Error("Unknown button type")}});yield Promise.all(n),this.handleReady()})}handleReady(){this.isAppleReady&&this.isGoogleReady&&this.isPayPalReady&&this.events.ready.emit()}addEventListener(e,r){return this.events[e].addListener(r)}showButton(){this.buttons.classList.remove(gr.hidden)}render(){return this.buttons}}class uc{constructor(){l(this,"template",`
23
+ `);l(this,"element",document.createElement("div"));this.element.classList.add(L.card),this.element.innerHTML=this.template}render(){return this.element}}const Tt={button:"_button_1br9w_1",press:"_press_1br9w_21"};class ic{constructor(e){l(this,"element");l(this,"icon",new nc);this.element=document.createElement("button"),this.element.classList.add(Tt.button);const r=document.createElement("span");r.textContent=e.getState().messages.card.compact.button,this.element.append(this.icon.render(),r),this.element.addEventListener("mousedown",()=>this.element.classList.add(Tt.press)),this.element.addEventListener("mouseup",()=>this.element.classList.remove(Tt.press)),this.element.addEventListener("mouseout",()=>this.element.classList.remove(Tt.press)),e.subscribe(({messages:n})=>{r.textContent=n.card.compact.button})}addEventListener(e){return this.element.addEventListener("click",e)}render(){return this.element}}const ac=(t,e,r)=>e.concat(t.filter(n=>e.every(i=>!r(n,i)))),xr=(t="sandbox")=>({develop:"https://api-dev.paynext.com/v1",sandbox:"https://api-sandbox.paynext.com/v1",production:"https://api.paynext.com/v1"})[t],sc=[{type:"paypal",order:1,is_active:!0},{type:"apple-pay",order:2,is_active:!0},{type:"google-pay",order:3,is_active:!0},{type:"card",order:4,is_active:!0}],oc=(t,e="sandbox")=>b(this,null,function*(){var s,o,c,u,d,p,h,f,m,g,y,v,T,k,I,w,A,V,C,R,B,q,me,W,fe,re,Ke,Be,Ae,J,G,ye,be,ve,we,xe,Ce,_e,ne,le,ce,ie,ae,lt,ct,dt,ut,pt,ht,mt,ft,gt,yt,bt,Li,Ti,Ii,Ai,Vi,Si,Mi,Pi,ji,Di,Ni,Oi,Ri,qi,Ki,Bi,zi,Fi,$i,Gi,Ui,Hi,Yi,Zi,Wi,Ji,Xi,Qi,ea,ta,ra,na,ia,aa,sa,oa,la,ca,da,ua,pa,ha,ma,fa,ga,ya,ba,va,wa,xa,Ca,_a,ka,Ea,La,Ta,Ia,Aa;const r=`${xr(e)}/payments/create`,n=new Headers;return n.append("Content-Type","application/json"),yield(yield fetch(r,{method:"POST",headers:n,body:JSON.stringify({client_session:t.clientSession,three_ds_session_id:t.threeDsSessionId,type:t.googlePay?"GPAY":t.applePay?"APPLEPAY":t.paypal?"PAYPAL":"CARD",name:(o=(s=t.applePay)==null?void 0:s.billingContact)!=null&&o.givenName?((p=(d=t.applePay)==null?void 0:d.billingContact)==null?void 0:p.givenName)+" "+((f=(h=t.applePay)==null?void 0:h.billingContact)==null?void 0:f.familyName):(u=(c=t.card)==null?void 0:c.metadata)==null?void 0:u.name,phone:(g=(m=t.applePay)==null?void 0:m.shippingContact)==null?void 0:g.phoneNumber,billing_address:t.applePay||t.googlePay?{city:((v=(y=t.applePay)==null?void 0:y.billingContact)==null?void 0:v.locality)||((k=(T=t==null?void 0:t.googlePay)==null?void 0:T.billingAddress)==null?void 0:k.locality)||void 0,country:((w=(I=t.applePay)==null?void 0:I.billingContact)==null?void 0:w.countryCode)||((V=(A=t==null?void 0:t.googlePay)==null?void 0:A.billingAddress)==null?void 0:V.countryCode)||void 0,line1:((B=(R=(C=t.applePay)==null?void 0:C.billingContact)==null?void 0:R.addressLines)==null?void 0:B.at(0))||((me=(q=t==null?void 0:t.googlePay)==null?void 0:q.billingAddress)==null?void 0:me.address1)||void 0,line2:((re=(fe=(W=t.applePay)==null?void 0:W.billingContact)==null?void 0:fe.addressLines)==null?void 0:re.at(1))||((Be=(Ke=t==null?void 0:t.googlePay)==null?void 0:Ke.billingAddress)==null?void 0:Be.address2)||void 0,postal_code:((J=(Ae=t.applePay)==null?void 0:Ae.billingContact)==null?void 0:J.postalCode)||((ye=(G=t==null?void 0:t.googlePay)==null?void 0:G.billingAddress)==null?void 0:ye.postalCode)||void 0,state:((ve=(be=t.applePay)==null?void 0:be.billingContact)==null?void 0:ve.administrativeArea)||((xe=(we=t==null?void 0:t.googlePay)==null?void 0:we.billingAddress)==null?void 0:xe.administrativeArea)||void 0}:void 0,card:t.card||(Ce=t.googlePay)!=null&&Ce.card||(_e=t.applePay)!=null&&_e.card?{bin:(ne=t.card)==null?void 0:ne.firstSixDigits,bin_data:{brand:((le=t.card)==null?void 0:le.cardBrand)||((ie=(ce=t.googlePay)==null?void 0:ce.card)==null?void 0:ie.brand)||((lt=(ae=t.applePay)==null?void 0:ae.card)==null?void 0:lt.brand),country:((ct=t.card)==null?void 0:ct.country)||((ut=(dt=t.googlePay)==null?void 0:dt.card)==null?void 0:ut.country)||((ht=(pt=t.applePay)==null?void 0:pt.card)==null?void 0:ht.country),currency_code:((mt=t.card)==null?void 0:mt.currency)||((gt=(ft=t.googlePay)==null?void 0:ft.card)==null?void 0:gt.currency)||((bt=(yt=t.applePay)==null?void 0:yt.card)==null?void 0:bt.currency),funding:((Li=t.card)==null?void 0:Li.funding)||((Ii=(Ti=t.googlePay)==null?void 0:Ti.card)==null?void 0:Ii.funding)||((Vi=(Ai=t.applePay)==null?void 0:Ai.card)==null?void 0:Vi.funding),issuer:((Si=t.card)==null?void 0:Si.issuer)||((Pi=(Mi=t.googlePay)==null?void 0:Mi.card)==null?void 0:Pi.issuer)||((Di=(ji=t.applePay)==null?void 0:ji.card)==null?void 0:Di.issuer),type:((Ni=t.card)==null?void 0:Ni.type)||((Ri=(Oi=t.googlePay)==null?void 0:Oi.card)==null?void 0:Ri.segment)||((Ki=(qi=t.applePay)==null?void 0:qi.card)==null?void 0:Ki.segment)},cvc:(Bi=t.card)==null?void 0:Bi.cvc,exp_month:(zi=t.card)!=null&&zi.expMonth||($i=(Fi=t.googlePay)==null?void 0:Fi.card)!=null&&$i.expiry.month?Number(((Gi=t.card)==null?void 0:Gi.expMonth)||((Hi=(Ui=t.googlePay)==null?void 0:Ui.card)==null?void 0:Hi.expiry.month)):void 0,exp_year:(Yi=t.card)!=null&&Yi.expYear||(Wi=(Zi=t.googlePay)==null?void 0:Zi.card)!=null&&Wi.expiry.year?Number(((Ji=t.card)==null?void 0:Ji.expYear)||((Qi=(Xi=t.googlePay)==null?void 0:Xi.card)==null?void 0:Qi.expiry.year)):void 0,last4:((ea=t.card)==null?void 0:ea.lastFourDigits)||((ra=(ta=t.googlePay)==null?void 0:ta.card)==null?void 0:ra.lastFour)||((ia=(na=t.applePay)==null?void 0:na.card)==null?void 0:ia.lastFour),number:((aa=t.card)==null?void 0:aa.number)||((oa=(sa=t.googlePay)==null?void 0:sa.card)==null?void 0:oa.number)}:void 0,paypal:(la=t.paypal)!=null&&la.billing_agreement_token.paypalId?{billing_agreement_token:(ca=t.paypal)==null?void 0:ca.billing_agreement_token.paypalId}:void 0,google_pay:t.googlePay&&t.googlePay.token?{cryptogram:t.googlePay.cryptogram,eci:t.googlePay.eci,exp_month:(ua=(da=t.googlePay)==null?void 0:da.card)!=null&&ua.expiry.month||(pa=t.googlePay)!=null&&pa.token.expiry.month?Number(t.googlePay.card.expiry.month||t.googlePay.token.expiry.month):void 0,exp_year:(ma=(ha=t.googlePay)==null?void 0:ha.card)!=null&&ma.expiry.year||(fa=t.googlePay)!=null&&fa.token.expiry.year?Number(t.googlePay.card.expiry.year||t.googlePay.token.expiry.year):void 0,token:(ya=(ga=t.googlePay)==null?void 0:ga.token)==null?void 0:ya.number,token_service_provider:(va=(ba=t.googlePay)==null?void 0:ba.token)==null?void 0:va.tokenServiceProvider}:void 0,apple_pay:t.applePay?{cryptogram:t.applePay.cryptogram,eci:t.applePay.eci,exp_month:(Ca=(xa=(wa=t.applePay)==null?void 0:wa.networkToken)==null?void 0:xa.expiry)!=null&&Ca.month?Number(t.applePay.networkToken.expiry.month):void 0,exp_year:(Ea=(ka=(_a=t.applePay)==null?void 0:_a.networkToken)==null?void 0:ka.expiry)!=null&&Ea.year?Number(t.applePay.networkToken.expiry.year):void 0,token:(Ta=(La=t.applePay)==null?void 0:La.networkToken)==null?void 0:Ta.number,token_service_provider:(Aa=(Ia=t.applePay)==null?void 0:Ia.networkToken)==null?void 0:Aa.tokenServiceProvider}:void 0})})).json()}),lc=(t,e="sandbox")=>b(this,null,function*(){const r=`${xr(e)}/payments/create/billing/agreement`,n=new Headers;return n.append("Content-Type","application/json"),(yield(yield fetch(r,{method:"POST",headers:n,body:JSON.stringify({client_session:t})})).json()).paypal_agreement_token_response.token_id||""}),cc=(t,e="sandbox")=>b(this,null,function*(){const r=`${xr(e)}/payments/config?client_session_id=${t}`,i=yield(yield fetch(r)).json();return i.checkout_config||(i.checkout_config=sc),i});var yi=(t=>(t.Card="CARD",t))(yi||{});class dc{constructor(e){l(this,"isAppleReady",!0);l(this,"isGoogleReady",!0);l(this,"isPayPalReady",!0);l(this,"buttons");l(this,"applePay");l(this,"googlePay");l(this,"paypal");l(this,"card");l(this,"events",{ready:new D,open:new D,error:new D,cancel:new D,success:new D});this.config=e,this.applePay=new Rl(e.service.ev),this.paypal=new ec(e.service.paypal),this.googlePay=new Ql(e.service.ev),this.card=new ic(e.state.translate),this.buttons=document.createElement("div"),this.buttons.classList.add(gr.buttons,gr.hidden)}init(){return b(this,null,function*(){this.config.state.transaction.subscribe(()=>{this.config.service.ev.isReady&&this.initPaymentMethods().catch(console.error)}),this.config.state.checkout.subscribe(()=>{this.config.service.ev.isReady&&this.initPaymentMethods().catch(console.error)}),this.config.service.ev.addEventListener("ready",()=>{this.initPaymentMethods().catch(console.error)}),this.card.addEventListener(()=>this.events.open.emit())})}initApple(){return b(this,null,function*(){this.isAppleReady=!1,this.buttons.appendChild(this.applePay.render());const e=this.config.state.transaction.getState(),{locale:r,supportedCardTypes:n}=this.config.state.checkout.getState(),i=Jl(e);try{if(!i)return;yield this.applePay.init({transaction:i,supportedCardTypes:Xl(n),locale:tc(r||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:a=>this.events.success.emit(j(E({},a),{type:"apple"}))})}catch(a){console.error(a)}finally{this.isAppleReady=!0}})}initGoogle(){return b(this,null,function*(){this.isGoogleReady=!1,this.buttons.appendChild(this.googlePay.render());const e=this.config.state.transaction.getState(),{locale:r}=this.config.state.checkout.getState(),n=Wl(e);try{if(!n)return;yield this.googlePay.init({transaction:n,locale:rc(r||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:i=>this.events.success.emit(j(E({},i),{type:"google"}))})}catch(i){console.error(i)}finally{this.isGoogleReady=!0}})}initPayPal(){return b(this,null,function*(){var i,a;this.isPayPalReady=!1,this.buttons.appendChild(this.paypal.render());const e=this.config.state.transaction.getState(),r=this.config.state.checkout.getState(),n=()=>b(this,null,function*(){return yield lc(r.clientToken,r.environment)});try{if(!e)return;yield this.paypal.init({clientId:((i=e==null?void 0:e.paypal_info)==null?void 0:i.client_id)||"",environment:((a=e==null?void 0:e.paypal_info)==null?void 0:a.environment)||"sandbox",createBillingAgreement:n,onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:s=>this.events.success.emit({paypalId:s,type:"paypal"})})}catch(s){console.error(s)}finally{this.isPayPalReady=!0}})}initCard(){return b(this,null,function*(){this.buttons.appendChild(this.card.render())})}initPaymentMethods(){return b(this,null,function*(){const e=this.config.state.transaction.getState(),n=ac(ql,(e==null?void 0:e.checkout_config)||[],(i,a)=>i.type===a.type).filter(({is_active:i})=>i).sort((i,a)=>i.order-a.order).map(({type:i})=>{switch(i){case"apple-pay":return this.initApple();case"google-pay":return this.initGoogle();case"paypal":return this.initPayPal();case"card":return this.initCard();default:throw new Error("Unknown button type")}});yield Promise.all(n),this.handleReady()})}handleReady(){this.isAppleReady&&this.isGoogleReady&&this.isPayPalReady&&this.events.ready.emit()}addEventListener(e,r){return this.events[e].addListener(r)}showButton(){this.buttons.classList.remove(gr.hidden)}render(){return this.buttons}}class uc{constructor(){l(this,"template",`
24
24
  <svg
25
25
  xmlns='http://www.w3.org/2000/svg'
26
26
  width='24'