@paynext/sdk 0.0.48 → 0.0.50

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="${Z.srOnly}">Pay with</span>
23
- `);b(this,"element",document.createElement("div"));this.element.classList.add(Z.card),this.element.innerHTML=this.template}render(){return this.element}}const Ot={button:"_button_1br9w_1",press:"_press_1br9w_21"};class pc{constructor(e){b(this,"element");b(this,"icon",new uc);this.element=document.createElement("button"),this.element.classList.add(Ot.button);const t=document.createElement("span");t.textContent=e.getState().messages.card.compact.button,this.element.append(this.icon.render(),t),this.element.addEventListener("mousedown",()=>this.element.classList.add(Ot.press)),this.element.addEventListener("mouseup",()=>this.element.classList.remove(Ot.press)),this.element.addEventListener("mouseout",()=>this.element.classList.remove(Ot.press)),e.subscribe(({messages:n})=>{t.textContent=n.card.compact.button})}addEventListener(e){return this.element.addEventListener("click",e)}render(){return this.element}}const hc=(r,e,t)=>e.concat(r.filter(n=>e.every(i=>!t(n,i)))),Cr=(r="sandbox")=>({develop:"https://api-dev.paynext.com",sandbox:"https://api-sandbox.paynext.com",production:"https://api.paynext.com"})[r],mc=[{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}],fc=(r,e,t)=>z(this,null,function*(){var o,c,l,d,u,h,p,m,f,v,y,A,T,N,w,I,L,S,B,G,q,M,F,K,J,R,W,j,g,_,k,U,E,x,C,P,V,O,H,X,le,D,te,ye,ut,pt,ht,mt,ft,vt,gt,yt,bt,Ri,Si,Mi,Di,Vi,Fi,Ui,Bi,ji,zi,Ki,qi,Hi,Wi,Gi,Yi,$i,Qi,Zi,Xi,Ji,ea,ta,ra,na,ia,aa,sa,oa,la,ca,da,ua,pa,ha,ma,fa,va,ga,ya,ba,_a,Ea,Ca,wa,Aa,Ta,Ia,xa,Oa,Na,La,Pa,ka,Ra,Sa,Ma,Da,Va;const n=`${Cr(e)}/payments/create`,i=new Headers;return i.append("Content-Type","application/json"),i.append("X-API-Version",t),yield(yield fetch(n,{method:"POST",headers:i,body:JSON.stringify({client_session:r.clientSession,three_ds_session_id:r.threeDsSessionId,type:r.googlePay?"GPAY":r.applePay?"APPLEPAY":r.paypal?"PAYPAL":"CARD",name:(c=(o=r.applePay)==null?void 0:o.billingContact)!=null&&c.givenName?((h=(u=r.applePay)==null?void 0:u.billingContact)==null?void 0:h.givenName)+" "+((m=(p=r.applePay)==null?void 0:p.billingContact)==null?void 0:m.familyName):(d=(l=r.card)==null?void 0:l.metadata)==null?void 0:d.name,phone:(v=(f=r.applePay)==null?void 0:f.shippingContact)==null?void 0:v.phoneNumber,billing_address:r.applePay||r.googlePay?{city:((A=(y=r.applePay)==null?void 0:y.billingContact)==null?void 0:A.locality)||((N=(T=r==null?void 0:r.googlePay)==null?void 0:T.billingAddress)==null?void 0:N.locality)||void 0,country:((I=(w=r.applePay)==null?void 0:w.billingContact)==null?void 0:I.countryCode)||((S=(L=r==null?void 0:r.googlePay)==null?void 0:L.billingAddress)==null?void 0:S.countryCode)||void 0,line1:((q=(G=(B=r.applePay)==null?void 0:B.billingContact)==null?void 0:G.addressLines)==null?void 0:q.at(0))||((F=(M=r==null?void 0:r.googlePay)==null?void 0:M.billingAddress)==null?void 0:F.address1)||void 0,line2:((R=(J=(K=r.applePay)==null?void 0:K.billingContact)==null?void 0:J.addressLines)==null?void 0:R.at(1))||((j=(W=r==null?void 0:r.googlePay)==null?void 0:W.billingAddress)==null?void 0:j.address2)||void 0,postal_code:((_=(g=r.applePay)==null?void 0:g.billingContact)==null?void 0:_.postalCode)||((U=(k=r==null?void 0:r.googlePay)==null?void 0:k.billingAddress)==null?void 0:U.postalCode)||void 0,state:((x=(E=r.applePay)==null?void 0:E.billingContact)==null?void 0:x.administrativeArea)||((P=(C=r==null?void 0:r.googlePay)==null?void 0:C.billingAddress)==null?void 0:P.administrativeArea)||void 0}:void 0,card:r.card||(V=r.googlePay)!=null&&V.card||(O=r.applePay)!=null&&O.card?{bin:(H=r.card)==null?void 0:H.firstSixDigits,bin_data:{brand:((X=r.card)==null?void 0:X.cardBrand)||((D=(le=r.googlePay)==null?void 0:le.card)==null?void 0:D.brand)||((ye=(te=r.applePay)==null?void 0:te.card)==null?void 0:ye.brand),country:((ut=r.card)==null?void 0:ut.country)||((ht=(pt=r.googlePay)==null?void 0:pt.card)==null?void 0:ht.country)||((ft=(mt=r.applePay)==null?void 0:mt.card)==null?void 0:ft.country),currency_code:((vt=r.card)==null?void 0:vt.currency)||((yt=(gt=r.googlePay)==null?void 0:gt.card)==null?void 0:yt.currency)||((Ri=(bt=r.applePay)==null?void 0:bt.card)==null?void 0:Ri.currency),funding:((Si=r.card)==null?void 0:Si.funding)||((Di=(Mi=r.googlePay)==null?void 0:Mi.card)==null?void 0:Di.funding)||((Fi=(Vi=r.applePay)==null?void 0:Vi.card)==null?void 0:Fi.funding),issuer:((Ui=r.card)==null?void 0:Ui.issuer)||((ji=(Bi=r.googlePay)==null?void 0:Bi.card)==null?void 0:ji.issuer)||((Ki=(zi=r.applePay)==null?void 0:zi.card)==null?void 0:Ki.issuer),type:((qi=r.card)==null?void 0:qi.type)||((Wi=(Hi=r.googlePay)==null?void 0:Hi.card)==null?void 0:Wi.segment)||((Yi=(Gi=r.applePay)==null?void 0:Gi.card)==null?void 0:Yi.segment)},cvc:($i=r.card)==null?void 0:$i.cvc,exp_month:(Qi=r.card)!=null&&Qi.expMonth||(Xi=(Zi=r.googlePay)==null?void 0:Zi.card)!=null&&Xi.expiry.month?Number(((Ji=r.card)==null?void 0:Ji.expMonth)||((ta=(ea=r.googlePay)==null?void 0:ea.card)==null?void 0:ta.expiry.month)):void 0,exp_year:(ra=r.card)!=null&&ra.expYear||(ia=(na=r.googlePay)==null?void 0:na.card)!=null&&ia.expiry.year?Number(((aa=r.card)==null?void 0:aa.expYear)||((oa=(sa=r.googlePay)==null?void 0:sa.card)==null?void 0:oa.expiry.year)):void 0,last4:((la=r.card)==null?void 0:la.lastFourDigits)||((da=(ca=r.googlePay)==null?void 0:ca.card)==null?void 0:da.lastFour)||((pa=(ua=r.applePay)==null?void 0:ua.card)==null?void 0:pa.lastFour),number:((ha=r.card)==null?void 0:ha.number)||((fa=(ma=r.googlePay)==null?void 0:ma.card)==null?void 0:fa.number)}:void 0,paypal:(va=r.paypal)!=null&&va.billing_agreement_token.paypalId?{billing_agreement_token:(ga=r.paypal)==null?void 0:ga.billing_agreement_token.paypalId}:void 0,google_pay:r.googlePay&&r.googlePay.token?{cryptogram:r.googlePay.cryptogram,eci:r.googlePay.eci,exp_month:(ba=(ya=r.googlePay)==null?void 0:ya.card)!=null&&ba.expiry.month||(_a=r.googlePay)!=null&&_a.token.expiry.month?Number(r.googlePay.card.expiry.month||r.googlePay.token.expiry.month):void 0,exp_year:(Ca=(Ea=r.googlePay)==null?void 0:Ea.card)!=null&&Ca.expiry.year||(wa=r.googlePay)!=null&&wa.token.expiry.year?Number(r.googlePay.card.expiry.year||r.googlePay.token.expiry.year):void 0,token:(Ta=(Aa=r.googlePay)==null?void 0:Aa.token)==null?void 0:Ta.number,token_service_provider:(xa=(Ia=r.googlePay)==null?void 0:Ia.token)==null?void 0:xa.tokenServiceProvider}:void 0,apple_pay:r.applePay?{cryptogram:r.applePay.cryptogram,eci:r.applePay.eci,exp_month:(La=(Na=(Oa=r.applePay)==null?void 0:Oa.networkToken)==null?void 0:Na.expiry)!=null&&La.month?Number(r.applePay.networkToken.expiry.month):void 0,exp_year:(Ra=(ka=(Pa=r.applePay)==null?void 0:Pa.networkToken)==null?void 0:ka.expiry)!=null&&Ra.year?Number(r.applePay.networkToken.expiry.year):void 0,token:(Ma=(Sa=r.applePay)==null?void 0:Sa.networkToken)==null?void 0:Ma.number,token_service_provider:(Va=(Da=r.applePay)==null?void 0:Da.networkToken)==null?void 0:Va.tokenServiceProvider}:void 0,braintree:r.braintree?{payment_method_nonce:r.braintree.nonce}:void 0})})).json()}),vc=(r,e,t)=>z(this,null,function*(){const n=`${Cr(e)}/payments/create/billing/agreement`,i=new Headers;return i.append("Content-Type","application/json"),i.append("X-API-Version",t),(yield(yield fetch(n,{method:"POST",headers:i,body:JSON.stringify({client_session:r})})).json()).paypal_agreement_token_response.token_id||""}),gc=(r,e,t)=>z(this,null,function*(){const n=`${Cr(e)}/payments/config?client_session_id=${r}`,i=new Headers;i.append("X-API-Version",t);const s=yield(yield fetch(n,{headers:i})).json();return s.checkout_config||(s.checkout_config=mc),s});var Ci=(r=>(r.Card="CARD",r))(Ci||{});const wr={venmo:"_venmo_10t25_1",hidden:"_hidden_10t25_17"},yc={display:"block",height:40,borderRadius:12};class bc{constructor(e){b(this,"isProcessing",!1);b(this,"element");b(this,"venmoButton");b(this,"events",{ready:new ie});this.braintree=e,this.element=document.createElement("div"),this.venmoButton=document.createElement("button"),this.venmoButton.classList.add(wr.venmo,wr.hidden),this.venmoButton.textContent="Venmo",this.element.appendChild(this.venmoButton)}init(e){return z(this,null,function*(){if(e){console.log("Initializing Braintree Venmo with config:",e);try{if(yield this.braintree.init({authorization:e.authorization}),yield this.braintree.createVenmo({deepLinkReturnUrl:"https://payment-staging.paynext.com"}),!this.braintree.isBrowserSupported()){console.log("Browser does not support Venmo"),this.handleVenmoError(new Error("Browser does not support Venmo"));return}if(this.displayVenmoButton(e),this.braintree.hasTokenizationResult()){yield this.handleExistingTokenization(e);return}this.element.classList.remove(wr.hidden),this.events.ready.emit()}catch(t){console.error("Error initializing Venmo:",t),this.handleVenmoError(t)}}})}displayVenmoButton(e){Object.assign(this.venmoButton.style,yc),this.venmoButton.addEventListener("click",()=>z(this,null,function*(){if(!this.isProcessing){this.isProcessing=!0,this.venmoButton.disabled=!0;try{const t=yield this.braintree.tokenize();this.handleVenmoSuccess(t,e)}catch(t){this.handleVenmoError(t,e)}finally{this.isProcessing=!1,this.venmoButton.disabled=!1}}}))}handleExistingTokenization(e){return z(this,null,function*(){try{const t=yield this.braintree.tokenize();this.handleVenmoSuccess(t,e)}catch(t){this.handleVenmoError(t,e)}})}handleVenmoSuccess(e,t){var n;console.log("Venmo payment successful:",e),(n=t.onSuccess)==null||n.call(t,e)}handleVenmoError(e,t){var n;console.error("Venmo error:",e),(n=t==null?void 0:t.onError)==null||n.call(t,e)}addEventListener(e,t){return this.events[e].addListener(t)}render(){return this.element}}class _c{constructor(e){b(this,"isAppleReady",!0);b(this,"isGoogleReady",!0);b(this,"isPayPalReady",!0);b(this,"isBraintreeReady",!0);b(this,"buttons");b(this,"applePay");b(this,"googlePay");b(this,"paypal");b(this,"card");b(this,"braintree");b(this,"events",{ready:new ie,open:new ie,error:new ie,cancel:new ie,success:new ie});this.config=e,this.applePay=new Wl(e.service.ev),this.paypal=new lc(e.service.paypal),this.googlePay=new oc(e.service.ev),this.braintree=new bc(e.service.braintree),this.card=new pc(e.state.translate),this.buttons=document.createElement("div"),this.buttons.classList.add(gr.buttons,gr.hidden)}init(){return z(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 z(this,null,function*(){this.isAppleReady=!1,this.buttons.appendChild(this.applePay.render());const e=this.config.state.transaction.getState(),{locale:t,supportedCardTypes:n}=this.config.state.checkout.getState(),i=ac(e);try{if(!i)return;yield this.applePay.init({transaction:i,supportedCardTypes:sc(n),locale:cc(t||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:a=>this.events.success.emit(ae(Q({},a),{type:"apple"}))})}catch(a){console.error(a)}finally{this.isAppleReady=!0}})}initGoogle(){return z(this,null,function*(){this.isGoogleReady=!1,this.buttons.appendChild(this.googlePay.render());const e=this.config.state.transaction.getState(),{locale:t}=this.config.state.checkout.getState(),n=ic(e);try{if(!n)return;yield this.googlePay.init({transaction:n,locale:dc(t||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:i=>this.events.success.emit(ae(Q({},i),{type:"google"}))})}catch(i){console.error(i)}finally{this.isGoogleReady=!0}})}initPayPal(){return z(this,null,function*(){var i,a;this.isPayPalReady=!1,this.buttons.appendChild(this.paypal.render());const e=this.config.state.transaction.getState(),t=this.config.state.checkout.getState(),n=()=>z(this,null,function*(){return yield vc(t.clientToken,t.environment,t.apiVersion)});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}})}initBraintreeVenmo(){return z(this,null,function*(){var t;this.isBraintreeReady=!1,this.buttons.appendChild(this.braintree.render());const e=this.config.state.transaction.getState();console.log("----- init braintree venmo: ",e);try{if(!e)return;yield this.braintree.init({authorization:((t=e==null?void 0:e.brain_tree_info)==null?void 0:t.client_token)||"",onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:n=>this.events.success.emit({nonce:n.nonce,type:"venmo"})})}catch(n){console.error(n)}finally{this.isBraintreeReady=!0}})}initCard(){return z(this,null,function*(){this.buttons.appendChild(this.card.render())})}initPaymentMethods(){return z(this,null,function*(){const e=this.config.state.transaction.getState(),n=hc(Gl,(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"venmo":return this.initBraintreeVenmo();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.isBraintreeReady&&this.events.ready.emit()}addEventListener(e,t){return this.events[e].addListener(t)}showButton(){this.buttons.classList.remove(gr.hidden)}render(){return this.buttons}}class Ec{constructor(){b(this,"template",`
23
+ `);b(this,"element",document.createElement("div"));this.element.classList.add(Z.card),this.element.innerHTML=this.template}render(){return this.element}}const Ot={button:"_button_1br9w_1",press:"_press_1br9w_21"};class pc{constructor(e){b(this,"element");b(this,"icon",new uc);this.element=document.createElement("button"),this.element.classList.add(Ot.button);const t=document.createElement("span");t.textContent=e.getState().messages.card.compact.button,this.element.append(this.icon.render(),t),this.element.addEventListener("mousedown",()=>this.element.classList.add(Ot.press)),this.element.addEventListener("mouseup",()=>this.element.classList.remove(Ot.press)),this.element.addEventListener("mouseout",()=>this.element.classList.remove(Ot.press)),e.subscribe(({messages:n})=>{t.textContent=n.card.compact.button})}addEventListener(e){return this.element.addEventListener("click",e)}render(){return this.element}}const hc=(r,e,t)=>e.concat(r.filter(n=>e.every(i=>!t(n,i)))),Cr=(r="sandbox")=>({develop:"https://api-dev.paynext.com",sandbox:"https://api-sandbox.paynext.com",staging:"https://api-staging.paynext.com",production:"https://api.paynext.com"})[r],mc=[{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}],fc=(r,e,t)=>z(this,null,function*(){var o,c,l,d,u,h,p,m,f,v,y,A,T,N,w,I,L,S,B,G,q,M,F,K,J,R,W,j,g,_,k,U,E,x,C,P,V,O,H,X,le,D,te,ye,ut,pt,ht,mt,ft,vt,gt,yt,bt,Ri,Si,Mi,Di,Vi,Fi,Ui,Bi,ji,zi,Ki,qi,Hi,Wi,Gi,Yi,$i,Qi,Zi,Xi,Ji,ea,ta,ra,na,ia,aa,sa,oa,la,ca,da,ua,pa,ha,ma,fa,va,ga,ya,ba,_a,Ea,Ca,wa,Aa,Ta,Ia,xa,Oa,Na,La,Pa,ka,Ra,Sa,Ma,Da,Va;const n=`${Cr(e)}/internal/payments/create`,i=new Headers;return i.append("Content-Type","application/json"),i.append("X-API-Version",t),yield(yield fetch(n,{method:"POST",headers:i,body:JSON.stringify({client_session:r.clientSession,three_ds_session_id:r.threeDsSessionId,type:r.googlePay?"GPAY":r.applePay?"APPLEPAY":r.paypal?"PAYPAL":"CARD",name:(c=(o=r.applePay)==null?void 0:o.billingContact)!=null&&c.givenName?((h=(u=r.applePay)==null?void 0:u.billingContact)==null?void 0:h.givenName)+" "+((m=(p=r.applePay)==null?void 0:p.billingContact)==null?void 0:m.familyName):(d=(l=r.card)==null?void 0:l.metadata)==null?void 0:d.name,phone:(v=(f=r.applePay)==null?void 0:f.shippingContact)==null?void 0:v.phoneNumber,billing_address:r.applePay||r.googlePay?{city:((A=(y=r.applePay)==null?void 0:y.billingContact)==null?void 0:A.locality)||((N=(T=r==null?void 0:r.googlePay)==null?void 0:T.billingAddress)==null?void 0:N.locality)||void 0,country:((I=(w=r.applePay)==null?void 0:w.billingContact)==null?void 0:I.countryCode)||((S=(L=r==null?void 0:r.googlePay)==null?void 0:L.billingAddress)==null?void 0:S.countryCode)||void 0,line1:((q=(G=(B=r.applePay)==null?void 0:B.billingContact)==null?void 0:G.addressLines)==null?void 0:q.at(0))||((F=(M=r==null?void 0:r.googlePay)==null?void 0:M.billingAddress)==null?void 0:F.address1)||void 0,line2:((R=(J=(K=r.applePay)==null?void 0:K.billingContact)==null?void 0:J.addressLines)==null?void 0:R.at(1))||((j=(W=r==null?void 0:r.googlePay)==null?void 0:W.billingAddress)==null?void 0:j.address2)||void 0,postal_code:((_=(g=r.applePay)==null?void 0:g.billingContact)==null?void 0:_.postalCode)||((U=(k=r==null?void 0:r.googlePay)==null?void 0:k.billingAddress)==null?void 0:U.postalCode)||void 0,state:((x=(E=r.applePay)==null?void 0:E.billingContact)==null?void 0:x.administrativeArea)||((P=(C=r==null?void 0:r.googlePay)==null?void 0:C.billingAddress)==null?void 0:P.administrativeArea)||void 0}:void 0,card:r.card||(V=r.googlePay)!=null&&V.card||(O=r.applePay)!=null&&O.card?{bin:(H=r.card)==null?void 0:H.firstSixDigits,bin_data:{brand:((X=r.card)==null?void 0:X.cardBrand)||((D=(le=r.googlePay)==null?void 0:le.card)==null?void 0:D.brand)||((ye=(te=r.applePay)==null?void 0:te.card)==null?void 0:ye.brand),country:((ut=r.card)==null?void 0:ut.country)||((ht=(pt=r.googlePay)==null?void 0:pt.card)==null?void 0:ht.country)||((ft=(mt=r.applePay)==null?void 0:mt.card)==null?void 0:ft.country),currency_code:((vt=r.card)==null?void 0:vt.currency)||((yt=(gt=r.googlePay)==null?void 0:gt.card)==null?void 0:yt.currency)||((Ri=(bt=r.applePay)==null?void 0:bt.card)==null?void 0:Ri.currency),funding:((Si=r.card)==null?void 0:Si.funding)||((Di=(Mi=r.googlePay)==null?void 0:Mi.card)==null?void 0:Di.funding)||((Fi=(Vi=r.applePay)==null?void 0:Vi.card)==null?void 0:Fi.funding),issuer:((Ui=r.card)==null?void 0:Ui.issuer)||((ji=(Bi=r.googlePay)==null?void 0:Bi.card)==null?void 0:ji.issuer)||((Ki=(zi=r.applePay)==null?void 0:zi.card)==null?void 0:Ki.issuer),type:((qi=r.card)==null?void 0:qi.type)||((Wi=(Hi=r.googlePay)==null?void 0:Hi.card)==null?void 0:Wi.segment)||((Yi=(Gi=r.applePay)==null?void 0:Gi.card)==null?void 0:Yi.segment)},cvc:($i=r.card)==null?void 0:$i.cvc,exp_month:(Qi=r.card)!=null&&Qi.expMonth||(Xi=(Zi=r.googlePay)==null?void 0:Zi.card)!=null&&Xi.expiry.month?Number(((Ji=r.card)==null?void 0:Ji.expMonth)||((ta=(ea=r.googlePay)==null?void 0:ea.card)==null?void 0:ta.expiry.month)):void 0,exp_year:(ra=r.card)!=null&&ra.expYear||(ia=(na=r.googlePay)==null?void 0:na.card)!=null&&ia.expiry.year?Number(((aa=r.card)==null?void 0:aa.expYear)||((oa=(sa=r.googlePay)==null?void 0:sa.card)==null?void 0:oa.expiry.year)):void 0,last4:((la=r.card)==null?void 0:la.lastFourDigits)||((da=(ca=r.googlePay)==null?void 0:ca.card)==null?void 0:da.lastFour)||((pa=(ua=r.applePay)==null?void 0:ua.card)==null?void 0:pa.lastFour),number:((ha=r.card)==null?void 0:ha.number)||((fa=(ma=r.googlePay)==null?void 0:ma.card)==null?void 0:fa.number)}:void 0,paypal:(va=r.paypal)!=null&&va.billing_agreement_token.paypalId?{billing_agreement_token:(ga=r.paypal)==null?void 0:ga.billing_agreement_token.paypalId}:void 0,google_pay:r.googlePay&&r.googlePay.token?{cryptogram:r.googlePay.cryptogram,eci:r.googlePay.eci,exp_month:(ba=(ya=r.googlePay)==null?void 0:ya.card)!=null&&ba.expiry.month||(_a=r.googlePay)!=null&&_a.token.expiry.month?Number(r.googlePay.card.expiry.month||r.googlePay.token.expiry.month):void 0,exp_year:(Ca=(Ea=r.googlePay)==null?void 0:Ea.card)!=null&&Ca.expiry.year||(wa=r.googlePay)!=null&&wa.token.expiry.year?Number(r.googlePay.card.expiry.year||r.googlePay.token.expiry.year):void 0,token:(Ta=(Aa=r.googlePay)==null?void 0:Aa.token)==null?void 0:Ta.number,token_service_provider:(xa=(Ia=r.googlePay)==null?void 0:Ia.token)==null?void 0:xa.tokenServiceProvider}:void 0,apple_pay:r.applePay?{cryptogram:r.applePay.cryptogram,eci:r.applePay.eci,exp_month:(La=(Na=(Oa=r.applePay)==null?void 0:Oa.networkToken)==null?void 0:Na.expiry)!=null&&La.month?Number(r.applePay.networkToken.expiry.month):void 0,exp_year:(Ra=(ka=(Pa=r.applePay)==null?void 0:Pa.networkToken)==null?void 0:ka.expiry)!=null&&Ra.year?Number(r.applePay.networkToken.expiry.year):void 0,token:(Ma=(Sa=r.applePay)==null?void 0:Sa.networkToken)==null?void 0:Ma.number,token_service_provider:(Va=(Da=r.applePay)==null?void 0:Da.networkToken)==null?void 0:Va.tokenServiceProvider}:void 0,braintree:r.braintree?{payment_method_nonce:r.braintree.nonce}:void 0})})).json()}),vc=(r,e,t)=>z(this,null,function*(){const n=`${Cr(e)}/internal/payments/create/billing/agreement`,i=new Headers;return i.append("Content-Type","application/json"),i.append("X-API-Version",t),(yield(yield fetch(n,{method:"POST",headers:i,body:JSON.stringify({client_session:r})})).json()).paypal_agreement_token_response.token_id||""}),gc=(r,e,t)=>z(this,null,function*(){const n=`${Cr(e)}/internal/payments/config?client_session_id=${r}`,i=new Headers;i.append("X-API-Version",t);const s=yield(yield fetch(n,{headers:i})).json();return s.checkout_config||(s.checkout_config=mc),s});var Ci=(r=>(r.Card="CARD",r))(Ci||{});const wr={venmo:"_venmo_10t25_1",hidden:"_hidden_10t25_17"},yc={display:"block",height:40,borderRadius:12};class bc{constructor(e){b(this,"isProcessing",!1);b(this,"element");b(this,"venmoButton");b(this,"events",{ready:new ie});this.braintree=e,this.element=document.createElement("div"),this.venmoButton=document.createElement("button"),this.venmoButton.classList.add(wr.venmo,wr.hidden),this.venmoButton.textContent="Venmo",this.element.appendChild(this.venmoButton)}init(e){return z(this,null,function*(){if(e){console.log("Initializing Braintree Venmo with config:",e);try{if(yield this.braintree.init({authorization:e.authorization}),yield this.braintree.createVenmo({deepLinkReturnUrl:"https://payment-staging.paynext.com"}),!this.braintree.isBrowserSupported()){console.log("Browser does not support Venmo"),this.handleVenmoError(new Error("Browser does not support Venmo"));return}if(this.displayVenmoButton(e),this.braintree.hasTokenizationResult()){yield this.handleExistingTokenization(e);return}this.element.classList.remove(wr.hidden),this.events.ready.emit()}catch(t){console.error("Error initializing Venmo:",t),this.handleVenmoError(t)}}})}displayVenmoButton(e){Object.assign(this.venmoButton.style,yc),this.venmoButton.addEventListener("click",()=>z(this,null,function*(){if(!this.isProcessing){this.isProcessing=!0,this.venmoButton.disabled=!0;try{const t=yield this.braintree.tokenize();this.handleVenmoSuccess(t,e)}catch(t){this.handleVenmoError(t,e)}finally{this.isProcessing=!1,this.venmoButton.disabled=!1}}}))}handleExistingTokenization(e){return z(this,null,function*(){try{const t=yield this.braintree.tokenize();this.handleVenmoSuccess(t,e)}catch(t){this.handleVenmoError(t,e)}})}handleVenmoSuccess(e,t){var n;console.log("Venmo payment successful:",e),(n=t.onSuccess)==null||n.call(t,e)}handleVenmoError(e,t){var n;console.error("Venmo error:",e),(n=t==null?void 0:t.onError)==null||n.call(t,e)}addEventListener(e,t){return this.events[e].addListener(t)}render(){return this.element}}class _c{constructor(e){b(this,"isAppleReady",!0);b(this,"isGoogleReady",!0);b(this,"isPayPalReady",!0);b(this,"isBraintreeReady",!0);b(this,"buttons");b(this,"applePay");b(this,"googlePay");b(this,"paypal");b(this,"card");b(this,"braintree");b(this,"events",{ready:new ie,open:new ie,error:new ie,cancel:new ie,success:new ie});this.config=e,this.applePay=new Wl(e.service.ev),this.paypal=new lc(e.service.paypal),this.googlePay=new oc(e.service.ev),this.braintree=new bc(e.service.braintree),this.card=new pc(e.state.translate),this.buttons=document.createElement("div"),this.buttons.classList.add(gr.buttons,gr.hidden)}init(){return z(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 z(this,null,function*(){this.isAppleReady=!1,this.buttons.appendChild(this.applePay.render());const e=this.config.state.transaction.getState(),{locale:t,supportedCardTypes:n}=this.config.state.checkout.getState(),i=ac(e);try{if(!i)return;yield this.applePay.init({transaction:i,supportedCardTypes:sc(n),locale:cc(t||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:a=>this.events.success.emit(ae(Q({},a),{type:"apple"}))})}catch(a){console.error(a)}finally{this.isAppleReady=!0}})}initGoogle(){return z(this,null,function*(){this.isGoogleReady=!1,this.buttons.appendChild(this.googlePay.render());const e=this.config.state.transaction.getState(),{locale:t}=this.config.state.checkout.getState(),n=ic(e);try{if(!n)return;yield this.googlePay.init({transaction:n,locale:dc(t||"en"),onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:i=>this.events.success.emit(ae(Q({},i),{type:"google"}))})}catch(i){console.error(i)}finally{this.isGoogleReady=!0}})}initPayPal(){return z(this,null,function*(){var i,a;this.isPayPalReady=!1,this.buttons.appendChild(this.paypal.render());const e=this.config.state.transaction.getState(),t=this.config.state.checkout.getState(),n=()=>z(this,null,function*(){return yield vc(t.clientToken,t.environment,t.apiVersion)});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}})}initBraintreeVenmo(){return z(this,null,function*(){var t;this.isBraintreeReady=!1,this.buttons.appendChild(this.braintree.render());const e=this.config.state.transaction.getState();console.log("----- init braintree venmo: ",e);try{if(!e)return;yield this.braintree.init({authorization:((t=e==null?void 0:e.brain_tree_info)==null?void 0:t.client_token)||"",onError:()=>this.events.error.emit(),onCancel:()=>this.events.cancel.emit(),onSuccess:n=>this.events.success.emit({nonce:n.nonce,type:"venmo"})})}catch(n){console.error(n)}finally{this.isBraintreeReady=!0}})}initCard(){return z(this,null,function*(){this.buttons.appendChild(this.card.render())})}initPaymentMethods(){return z(this,null,function*(){const e=this.config.state.transaction.getState(),n=hc(Gl,(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"venmo":return this.initBraintreeVenmo();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.isBraintreeReady&&this.events.ready.emit()}addEventListener(e,t){return this.events[e].addListener(t)}showButton(){this.buttons.classList.remove(gr.hidden)}render(){return this.buttons}}class Ec{constructor(){b(this,"template",`
24
24
  <svg
25
25
  xmlns='http://www.w3.org/2000/svg'
26
26
  width='24'