@paynext/sdk 0.0.39 → 0.0.40
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.es.js +7 -7
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
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="${T.srOnly}">Pay with</span>
|
|
23
|
-
`);l(this,"element",document.createElement("div"));this.element.classList.add(T.card),this.element.innerHTML=this.template}render(){return this.element}}const Tt={button:"_button_1br9w_1",press:"_press_1br9w_21"};class nc{constructor(e){l(this,"element");l(this,"icon",new rc);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 ic=(t,e,r)=>e.concat(t.filter(n=>e.every(i=>!r(n,i)))),xr={apiBase:"https://api-dev.paynext.com/v1"},ac=[{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}],sc=t=>w(this,null,function*(){var a,s,o,c,u,d,p,m,f,h,g,b,v,E,y,I,x,A,V,_,O,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,Ri,Oi,qi,Ki,Bi,zi,Fi,$i,Gi,Ui,Yi,Hi,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;const e=`${xr.apiBase}/payments/create`,r=new Headers;return r.append("Content-Type","application/json"),console.log("----- payment data: ",t),yield(yield fetch(e,{method:"POST",headers:r,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:(s=(a=t.applePay)==null?void 0:a.billingContact)!=null&&s.givenName?((d=(u=t.applePay)==null?void 0:u.billingContact)==null?void 0:d.givenName)+" "+((m=(p=t.applePay)==null?void 0:p.billingContact)==null?void 0:m.familyName):(c=(o=t.card)==null?void 0:o.metadata)==null?void 0:c.name,phone:(h=(f=t.applePay)==null?void 0:f.shippingContact)==null?void 0:h.phoneNumber,billing_address:t.applePay||t.googlePay?{city:((b=(g=t.applePay)==null?void 0:g.billingContact)==null?void 0:b.locality)||((E=(v=t==null?void 0:t.googlePay)==null?void 0:v.billingAddress)==null?void 0:E.locality),country:((I=(y=t.applePay)==null?void 0:y.billingContact)==null?void 0:I.countryCode)||((A=(x=t==null?void 0:t.googlePay)==null?void 0:x.billingAddress)==null?void 0:A.countryCode),line1:((O=(_=(V=t.applePay)==null?void 0:V.billingContact)==null?void 0:_.addressLines)==null?void 0:O.at(0))||((q=(B=t==null?void 0:t.googlePay)==null?void 0:B.billingAddress)==null?void 0:q.address1),line2:((fe=(W=(me=t.applePay)==null?void 0:me.billingContact)==null?void 0:W.addressLines)==null?void 0:fe.at(1))||((Ke=(re=t==null?void 0:t.googlePay)==null?void 0:re.billingAddress)==null?void 0:Ke.address2),postal_code:((Ae=(Be=t.applePay)==null?void 0:Be.billingContact)==null?void 0:Ae.postalCode)||((G=(J=t==null?void 0:t.googlePay)==null?void 0:J.billingAddress)==null?void 0:G.postalCode),state:((be=(ye=t.applePay)==null?void 0:ye.billingContact)==null?void 0:be.administrativeArea)||((we=(ve=t==null?void 0:t.googlePay)==null?void 0:ve.billingAddress)==null?void 0:we.administrativeArea)}:void 0,card:t.card||(xe=t.googlePay)!=null&&xe.card||(Ce=t.applePay)!=null&&Ce.card?{bin:(_e=t.card)==null?void 0:_e.firstSixDigits,bin_data:{brand:((ne=t.card)==null?void 0:ne.cardBrand)||((ce=(le=t.googlePay)==null?void 0:le.card)==null?void 0:ce.brand)||((ae=(ie=t.applePay)==null?void 0:ie.card)==null?void 0:ae.brand),country:((lt=t.card)==null?void 0:lt.country)||((dt=(ct=t.googlePay)==null?void 0:ct.card)==null?void 0:dt.country)||((pt=(ut=t.applePay)==null?void 0:ut.card)==null?void 0:pt.country),currency_code:((ht=t.card)==null?void 0:ht.currency)||((ft=(mt=t.googlePay)==null?void 0:mt.card)==null?void 0:ft.currency)||((yt=(gt=t.applePay)==null?void 0:gt.card)==null?void 0:yt.currency),funding:((bt=t.card)==null?void 0:bt.funding)||((Ti=(Li=t.googlePay)==null?void 0:Li.card)==null?void 0:Ti.funding)||((Ai=(Ii=t.applePay)==null?void 0:Ii.card)==null?void 0:Ai.funding),issuer:((Vi=t.card)==null?void 0:Vi.issuer)||((Mi=(Si=t.googlePay)==null?void 0:Si.card)==null?void 0:Mi.issuer)||((ji=(Pi=t.applePay)==null?void 0:Pi.card)==null?void 0:ji.issuer),type:((Di=t.card)==null?void 0:Di.type)||((Ri=(Ni=t.googlePay)==null?void 0:Ni.card)==null?void 0:Ri.segment)||((qi=(Oi=t.applePay)==null?void 0:Oi.card)==null?void 0:qi.segment)},cvc:(Ki=t.card)==null?void 0:Ki.cvc,exp_month:(Bi=t.card)!=null&&Bi.expMonth||(Fi=(zi=t.googlePay)==null?void 0:zi.card)!=null&&Fi.expiry.month?Number((($i=t.card)==null?void 0:$i.expMonth)||((Ui=(Gi=t.googlePay)==null?void 0:Gi.card)==null?void 0:Ui.expiry.month)):void 0,exp_year:(Yi=t.card)!=null&&Yi.expYear||(Zi=(Hi=t.googlePay)==null?void 0:Hi.card)!=null&&Zi.expiry.year?Number(((Wi=t.card)==null?void 0:Wi.expYear)||((Xi=(Ji=t.googlePay)==null?void 0:Ji.card)==null?void 0:Xi.expiry.year)):void 0,last4:((Qi=t.card)==null?void 0:Qi.lastFourDigits)||((ta=(ea=t.googlePay)==null?void 0:ea.card)==null?void 0:ta.lastFour)||((na=(ra=t.applePay)==null?void 0:ra.card)==null?void 0:na.lastFour),number:((ia=t.card)==null?void 0:ia.number)||((sa=(aa=t.googlePay)==null?void 0:aa.card)==null?void 0:sa.number)}:void 0,paypal:(oa=t.paypal)!=null&&oa.billing_agreement_token.paypalId?{billing_agreement_token:(la=t.paypal)==null?void 0:la.billing_agreement_token.paypalId}:void 0,google_pay:t.googlePay?{cryptogram:t.googlePay.cryptogram,eci:t.googlePay.eci,exp_month:(da=(ca=t.googlePay)==null?void 0:ca.card)!=null&&da.expiry.month||(ua=t.googlePay)!=null&&ua.token.expiry.month?Number(t.googlePay.card.expiry.month||t.googlePay.token.expiry.month):void 0,exp_year:(ha=(pa=t.googlePay)==null?void 0:pa.card)!=null&&ha.expiry.year||(ma=t.googlePay)!=null&&ma.token.expiry.year?Number(t.googlePay.card.expiry.year||t.googlePay.token.expiry.year):void 0,token:(ga=(fa=t.googlePay)==null?void 0:fa.token)==null?void 0:ga.number,token_service_provider:(ba=(ya=t.googlePay)==null?void 0:ya.token)==null?void 0:ba.tokenServiceProvider}:void 0,apple_pay:t.applePay?{cryptogram:t.applePay.cryptogram,eci:t.applePay.eci,exp_month:(xa=(wa=(va=t.applePay)==null?void 0:va.networkToken)==null?void 0:wa.expiry)!=null&&xa.month?Number(t.applePay.networkToken.expiry.month):void 0,exp_year:(ka=(_a=(Ca=t.applePay)==null?void 0:Ca.networkToken)==null?void 0:_a.expiry)!=null&&ka.year?Number(t.applePay.networkToken.expiry.year):void 0,token:(La=(Ea=t.applePay)==null?void 0:Ea.networkToken)==null?void 0:La.number,token_service_provider:(Ia=(Ta=t.applePay)==null?void 0:Ta.networkToken)==null?void 0:Ia.tokenServiceProvider}:void 0})})).json()}),oc=t=>w(this,null,function*(){const e=`${xr.apiBase}/payments/create/billing/agreement`,r=new Headers;return r.append("Content-Type","application/json"),(yield(yield fetch(e,{method:"POST",headers:r,body:JSON.stringify({client_session:t})})).json()).paypal_agreement_token_response.token_id||""}),lc=t=>w(this,null,function*(){const e=`${xr.apiBase}/payments/config?client_session_id=${t}`,n=yield(yield fetch(e)).json();return n.checkout_config||(n.checkout_config=ac),n});var yi=(t=>(t.Card="CARD",t))(yi||{});class cc{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 Ql(e.service.paypal),this.googlePay=new Xl(e.service.ev),this.card=new nc(e.state.translate),this.buttons=document.createElement("div"),this.buttons.classList.add(gr.buttons,gr.hidden)}init(){return w(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 w(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=Wl(e);try{if(!i)return;yield this.applePay.init({transaction:i,supportedCardTypes:Jl(n),locale:ec(r||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:a=>this.events.success.emit(j(L({},a),{type:"apple"}))})}catch(a){console.error(a)}finally{this.isAppleReady=!0}})}initGoogle(){return w(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=Zl(e);try{if(!n)return;yield this.googlePay.init({transaction:n,locale:tc(r||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:i=>this.events.success.emit(j(L({},i),{type:"google"}))})}catch(i){console.error(i)}finally{this.isGoogleReady=!0}})}initPayPal(){return w(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().clientToken,n=()=>w(this,null,function*(){return yield oc(r)});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 w(this,null,function*(){this.buttons.appendChild(this.card.render())})}initPaymentMethods(){return w(this,null,function*(){const e=this.config.state.transaction.getState(),n=ic(Ol,(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 dc{constructor(){l(this,"template",`
|
|
23
|
+
`);l(this,"element",document.createElement("div"));this.element.classList.add(T.card),this.element.innerHTML=this.template}render(){return this.element}}const Tt={button:"_button_1br9w_1",press:"_press_1br9w_21"};class nc{constructor(e){l(this,"element");l(this,"icon",new rc);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 ic=(t,e,r)=>e.concat(t.filter(n=>e.every(i=>!r(n,i)))),xr={apiBase:"https://api-dev.paynext.com/v1"},ac=[{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}],sc=t=>w(this,null,function*(){var a,s,o,c,u,d,p,m,f,h,g,b,v,E,y,I,x,A,V,_,O,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,Ri,Oi,qi,Ki,Bi,zi,Fi,$i,Gi,Ui,Yi,Hi,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;const e=`${xr.apiBase}/payments/create`,r=new Headers;return r.append("Content-Type","application/json"),console.log("----- payment data: ",t),yield(yield fetch(e,{method:"POST",headers:r,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:(s=(a=t.applePay)==null?void 0:a.billingContact)!=null&&s.givenName?((d=(u=t.applePay)==null?void 0:u.billingContact)==null?void 0:d.givenName)+" "+((m=(p=t.applePay)==null?void 0:p.billingContact)==null?void 0:m.familyName):(c=(o=t.card)==null?void 0:o.metadata)==null?void 0:c.name,phone:(h=(f=t.applePay)==null?void 0:f.shippingContact)==null?void 0:h.phoneNumber,billing_address:t.applePay||t.googlePay?{city:((b=(g=t.applePay)==null?void 0:g.billingContact)==null?void 0:b.locality)||((E=(v=t==null?void 0:t.googlePay)==null?void 0:v.billingAddress)==null?void 0:E.locality)||void 0,country:((I=(y=t.applePay)==null?void 0:y.billingContact)==null?void 0:I.countryCode)||((A=(x=t==null?void 0:t.googlePay)==null?void 0:x.billingAddress)==null?void 0:A.countryCode)||void 0,line1:((O=(_=(V=t.applePay)==null?void 0:V.billingContact)==null?void 0:_.addressLines)==null?void 0:O.at(0))||((q=(B=t==null?void 0:t.googlePay)==null?void 0:B.billingAddress)==null?void 0:q.address1)||void 0,line2:((fe=(W=(me=t.applePay)==null?void 0:me.billingContact)==null?void 0:W.addressLines)==null?void 0:fe.at(1))||((Ke=(re=t==null?void 0:t.googlePay)==null?void 0:re.billingAddress)==null?void 0:Ke.address2)||void 0,postal_code:((Ae=(Be=t.applePay)==null?void 0:Be.billingContact)==null?void 0:Ae.postalCode)||((G=(J=t==null?void 0:t.googlePay)==null?void 0:J.billingAddress)==null?void 0:G.postalCode)||void 0,state:((be=(ye=t.applePay)==null?void 0:ye.billingContact)==null?void 0:be.administrativeArea)||((we=(ve=t==null?void 0:t.googlePay)==null?void 0:ve.billingAddress)==null?void 0:we.administrativeArea)||void 0}:void 0,card:t.card||(xe=t.googlePay)!=null&&xe.card||(Ce=t.applePay)!=null&&Ce.card?{bin:(_e=t.card)==null?void 0:_e.firstSixDigits,bin_data:{brand:((ne=t.card)==null?void 0:ne.cardBrand)||((ce=(le=t.googlePay)==null?void 0:le.card)==null?void 0:ce.brand)||((ae=(ie=t.applePay)==null?void 0:ie.card)==null?void 0:ae.brand),country:((lt=t.card)==null?void 0:lt.country)||((dt=(ct=t.googlePay)==null?void 0:ct.card)==null?void 0:dt.country)||((pt=(ut=t.applePay)==null?void 0:ut.card)==null?void 0:pt.country),currency_code:((ht=t.card)==null?void 0:ht.currency)||((ft=(mt=t.googlePay)==null?void 0:mt.card)==null?void 0:ft.currency)||((yt=(gt=t.applePay)==null?void 0:gt.card)==null?void 0:yt.currency),funding:((bt=t.card)==null?void 0:bt.funding)||((Ti=(Li=t.googlePay)==null?void 0:Li.card)==null?void 0:Ti.funding)||((Ai=(Ii=t.applePay)==null?void 0:Ii.card)==null?void 0:Ai.funding),issuer:((Vi=t.card)==null?void 0:Vi.issuer)||((Mi=(Si=t.googlePay)==null?void 0:Si.card)==null?void 0:Mi.issuer)||((ji=(Pi=t.applePay)==null?void 0:Pi.card)==null?void 0:ji.issuer),type:((Di=t.card)==null?void 0:Di.type)||((Ri=(Ni=t.googlePay)==null?void 0:Ni.card)==null?void 0:Ri.segment)||((qi=(Oi=t.applePay)==null?void 0:Oi.card)==null?void 0:qi.segment)},cvc:(Ki=t.card)==null?void 0:Ki.cvc,exp_month:(Bi=t.card)!=null&&Bi.expMonth||(Fi=(zi=t.googlePay)==null?void 0:zi.card)!=null&&Fi.expiry.month?Number((($i=t.card)==null?void 0:$i.expMonth)||((Ui=(Gi=t.googlePay)==null?void 0:Gi.card)==null?void 0:Ui.expiry.month)):void 0,exp_year:(Yi=t.card)!=null&&Yi.expYear||(Zi=(Hi=t.googlePay)==null?void 0:Hi.card)!=null&&Zi.expiry.year?Number(((Wi=t.card)==null?void 0:Wi.expYear)||((Xi=(Ji=t.googlePay)==null?void 0:Ji.card)==null?void 0:Xi.expiry.year)):void 0,last4:((Qi=t.card)==null?void 0:Qi.lastFourDigits)||((ta=(ea=t.googlePay)==null?void 0:ea.card)==null?void 0:ta.lastFour)||((na=(ra=t.applePay)==null?void 0:ra.card)==null?void 0:na.lastFour),number:((ia=t.card)==null?void 0:ia.number)||((sa=(aa=t.googlePay)==null?void 0:aa.card)==null?void 0:sa.number)}:void 0,paypal:(oa=t.paypal)!=null&&oa.billing_agreement_token.paypalId?{billing_agreement_token:(la=t.paypal)==null?void 0:la.billing_agreement_token.paypalId}:void 0,google_pay:t.googlePay&&t.googlePay.token?{cryptogram:t.googlePay.cryptogram,eci:t.googlePay.eci,exp_month:(da=(ca=t.googlePay)==null?void 0:ca.card)!=null&&da.expiry.month||(ua=t.googlePay)!=null&&ua.token.expiry.month?Number(t.googlePay.card.expiry.month||t.googlePay.token.expiry.month):void 0,exp_year:(ha=(pa=t.googlePay)==null?void 0:pa.card)!=null&&ha.expiry.year||(ma=t.googlePay)!=null&&ma.token.expiry.year?Number(t.googlePay.card.expiry.year||t.googlePay.token.expiry.year):void 0,token:(ga=(fa=t.googlePay)==null?void 0:fa.token)==null?void 0:ga.number,token_service_provider:(ba=(ya=t.googlePay)==null?void 0:ya.token)==null?void 0:ba.tokenServiceProvider}:void 0,apple_pay:t.applePay?{cryptogram:t.applePay.cryptogram,eci:t.applePay.eci,exp_month:(xa=(wa=(va=t.applePay)==null?void 0:va.networkToken)==null?void 0:wa.expiry)!=null&&xa.month?Number(t.applePay.networkToken.expiry.month):void 0,exp_year:(ka=(_a=(Ca=t.applePay)==null?void 0:Ca.networkToken)==null?void 0:_a.expiry)!=null&&ka.year?Number(t.applePay.networkToken.expiry.year):void 0,token:(La=(Ea=t.applePay)==null?void 0:Ea.networkToken)==null?void 0:La.number,token_service_provider:(Ia=(Ta=t.applePay)==null?void 0:Ta.networkToken)==null?void 0:Ia.tokenServiceProvider}:void 0})})).json()}),oc=t=>w(this,null,function*(){const e=`${xr.apiBase}/payments/create/billing/agreement`,r=new Headers;return r.append("Content-Type","application/json"),(yield(yield fetch(e,{method:"POST",headers:r,body:JSON.stringify({client_session:t})})).json()).paypal_agreement_token_response.token_id||""}),lc=t=>w(this,null,function*(){const e=`${xr.apiBase}/payments/config?client_session_id=${t}`,n=yield(yield fetch(e)).json();return n.checkout_config||(n.checkout_config=ac),n});var yi=(t=>(t.Card="CARD",t))(yi||{});class cc{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 Ql(e.service.paypal),this.googlePay=new Xl(e.service.ev),this.card=new nc(e.state.translate),this.buttons=document.createElement("div"),this.buttons.classList.add(gr.buttons,gr.hidden)}init(){return w(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 w(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=Wl(e);try{if(!i)return;yield this.applePay.init({transaction:i,supportedCardTypes:Jl(n),locale:ec(r||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:a=>this.events.success.emit(j(L({},a),{type:"apple"}))})}catch(a){console.error(a)}finally{this.isAppleReady=!0}})}initGoogle(){return w(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=Zl(e);try{if(!n)return;yield this.googlePay.init({transaction:n,locale:tc(r||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:i=>this.events.success.emit(j(L({},i),{type:"google"}))})}catch(i){console.error(i)}finally{this.isGoogleReady=!0}})}initPayPal(){return w(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().clientToken,n=()=>w(this,null,function*(){return yield oc(r)});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 w(this,null,function*(){this.buttons.appendChild(this.card.render())})}initPaymentMethods(){return w(this,null,function*(){const e=this.config.state.transaction.getState(),n=ic(Ol,(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 dc{constructor(){l(this,"template",`
|
|
24
24
|
<svg
|
|
25
25
|
xmlns='http://www.w3.org/2000/svg'
|
|
26
26
|
width='24'
|