@paynext/sdk 0.0.89 → 0.0.90

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
@@ -48,7 +48,7 @@ React keys must be passed directly to JSX without using spread:
48
48
  ✓ Rendered - Button successfully initialized and rendered
49
49
  ✗ Not supported - Button not supported on this device/browser
50
50
  ✗ Error - Initialization error occurred
51
- Skipped - Button not configured`,"color: #666;"),console.groupEnd()}init(){return Y(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)})})}initApple(t){return Y(this,null,function*(){const e=performance.now(),n="Apple Pay";if(!this.applePay){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isAppleReady=!1;try{if(yield this.applePay.init({onError:i=>{this.events.error.emit(i),this.attempted.delete(K.APPLE_PAY)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(K.APPLE_PAY)},onSuccess:i=>{this.events.success.emit(J(H({},i),{type:"apple"})),this.attempted.delete(K.APPLE_PAY)}})){const i=this.applePay.render();t==null||t.appendChild(i);const s=()=>{this.attempted.has(K.APPLE_PAY)||(this.attempted.add(K.APPLE_PAY),this.events.onPaymentAttempt.emit(K.APPLE_PAY))};i.addEventListener("pointerdown",s,{capture:!0}),i.addEventListener("click",s,{capture:!0}),i.addEventListener("keydown",c=>{((c==null?void 0:c.key)==="Enter"||(c==null?void 0:c.key)===" ")&&s()},{capture:!0}),i.addEventListener("focusin",s,{capture:!0}),t==null||t.addEventListener("pointerdown",s,{capture:!0}),t==null||t.addEventListener("click",s,{capture:!0}),t==null||t.addEventListener("focusin",s,{capture:!0});const o=performance.now();this.performanceMetrics.set(n,{start:e,end:o,duration:o-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isAppleReady=!0}})}initGoogle(t){return Y(this,null,function*(){const e=performance.now(),n="Google Pay";if(!this.googlePay){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isGoogleReady=!1;try{if(yield this.googlePay.init({onError:i=>{this.events.error.emit(i),this.attempted.delete(K.GOOGLE_PAY)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(K.GOOGLE_PAY)},onSuccess:i=>{this.events.success.emit(J(H({},i),{type:"google"})),this.attempted.delete(K.GOOGLE_PAY)}})){const i=this.googlePay.render();t==null||t.appendChild(i);const s=()=>{this.attempted.has(K.GOOGLE_PAY)||(this.attempted.add(K.GOOGLE_PAY),this.events.onPaymentAttempt.emit(K.GOOGLE_PAY))};i.addEventListener("pointerdown",s,{capture:!0}),i.addEventListener("click",s,{capture:!0}),i.addEventListener("keydown",c=>{((c==null?void 0:c.key)==="Enter"||(c==null?void 0:c.key)===" ")&&s()},{capture:!0}),i.addEventListener("focusin",s,{capture:!0}),t==null||t.addEventListener("pointerdown",s,{capture:!0}),t==null||t.addEventListener("click",s,{capture:!0}),t==null||t.addEventListener("focusin",s,{capture:!0});const o=performance.now();this.performanceMetrics.set(n,{start:e,end:o,duration:o-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isGoogleReady=!0}})}initPayPal(t){return Y(this,null,function*(){const e=performance.now(),n="PayPal";if(!this.paypal){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isPayPalReady=!1;try{const a=this.paypal.render();if(t==null||t.appendChild(a),yield this.paypal.init({onError:s=>this.events.error.emit(s),onCancel:()=>this.events.cancel.emit(),onSuccess:s=>{this.events.success.emit({paypalId:s,type:"paypal"})}})){const s=performance.now();this.performanceMetrics.set(n,{start:e,end:s,duration:s-e,status:"✓ Rendered"})}else{t==null||t.remove();const s=performance.now();this.performanceMetrics.set(n,{start:e,end:s,duration:s-e,status:"✗ Not supported"})}}catch(a){t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isPayPalReady=!0}})}initBraintreeVenmo(t){return Y(this,null,function*(){const e=performance.now(),n="Venmo";if(!this.braintree){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isBraintreeReady=!1;try{if(yield this.braintree.init({onError:i=>this.events.error.emit(i),onCancel:()=>this.events.cancel.emit(),onSuccess:i=>{this.events.success.emit({nonce:i==null?void 0:i.nonce,type:"venmo"})}})){const i=this.braintree.render();t==null||t.appendChild(i);const s=performance.now();this.performanceMetrics.set(n,{start:e,end:s,duration:s-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isBraintreeReady=!0}})}initCard(t){return Y(this,null,function*(){const e=performance.now(),n="Card";if(!this.card){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}t==null||t.appendChild(this.card.render());const a=performance.now();this.performanceMetrics.set(n,{start:e,end:a,duration:a-e,status:"✓ Rendered"})})}waitForElementVisible(t,e=2e3){return!t||!(t instanceof HTMLElement)?Promise.resolve():new Promise(n=>{const a=performance.now(),i=()=>{const s=t.getBoundingClientRect();if(s.width>0&&s.height>0||performance.now()-a>=e)return n();requestAnimationFrame(i)};requestAnimationFrame(i)})}initPaymentMethods(){return Y(this,null,function*(){const t=this.config.state.transaction.getState(),e=Vc(Rc,(t==null?void 0:t.checkout_config)||[],(l,d)=>l.type===d.type),n=this.config.state.checkout.getState();let a=e.filter(({is_active:l})=>l);(n==null?void 0:n.variant)==="default"&&(a=a.filter(({type:l})=>l!==K.CARD)),this.initializeButtonInstances(a),this.buttons.innerHTML="";const i=a.sort((l,d)=>l.order-d.order),s=new Map;for(const{type:l}of i){const d=document.createElement("div");this.buttons.appendChild(d),s.set(l,d)}const o=i.map(({type:l})=>{const d=s.get(l);switch(l){case K.APPLE_PAY:return this.initApple(d);case K.GOOGLE_PAY:return this.initGoogle(d);case K.PAYPAL:return this.initPayPal(d);case K.VENMO:return this.initBraintreeVenmo(d);case K.CARD:return this.initCard(d);default:throw new Error("Unknown button type")}});yield Promise.all(o);const c=[];for(const l of s.values()){const d=l.firstElementChild;d&&c.push(this.waitForElementVisible(d))}yield Promise.all(c),this.handleReady()})}initializeButtonInstances(t){const e=t.map(({type:n})=>n);e.includes(K.APPLE_PAY)&&!this.applePay&&(this.applePay=new Lc(this.config)),e.includes(K.GOOGLE_PAY)&&!this.googlePay&&(this.googlePay=new kc(this.config)),e.includes(K.PAYPAL)&&!this.paypal&&(this.paypal=new Sc(this.config),this.paypal.addEventListener("onPaymentAttempt",n=>this.events.onPaymentAttempt.emit(n))),e.includes(K.VENMO)&&!this.braintree&&(this.braintree=new Bc(this.config),this.braintree.addEventListener("onPaymentAttempt",n=>this.events.onPaymentAttempt.emit(n))),e.includes(K.CARD)&&!this.card&&(this.card=new Dc(this.config),this.card.addEventListener(()=>{this.events.open.emit()}))}handleReady(){this.isAppleReady&&this.isGoogleReady&&this.isPayPalReady&&this.isBraintreeReady&&(this.logPerformanceMetrics(),this.events.ready.emit())}addEventListener(t,e){return this.events[t].addListener(e)}showButton(){this.buttons.classList.remove(yr.hidden)}render(){return this.buttons}}class jc{constructor(){C(this,"template",`
51
+ Skipped - Button not configured`,"color: #666;"),console.groupEnd()}init(){return Y(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)})})}initApple(t){return Y(this,null,function*(){const e=performance.now(),n="Apple Pay";if(!this.applePay){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isAppleReady=!1;try{if(yield this.applePay.init({onError:i=>{this.events.error.emit(i),this.attempted.delete(K.APPLE_PAY)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(K.APPLE_PAY)},onSuccess:i=>{this.events.success.emit(J(H({},i),{type:"apple"})),this.attempted.delete(K.APPLE_PAY)}})){const i=this.applePay.render();t==null||t.appendChild(i);const s=()=>{this.attempted.has(K.APPLE_PAY)||(this.attempted.add(K.APPLE_PAY),this.events.onPaymentAttempt.emit(K.APPLE_PAY))};i.addEventListener("pointerdown",s,{capture:!0}),i.addEventListener("click",s,{capture:!0}),i.addEventListener("keydown",c=>{((c==null?void 0:c.key)==="Enter"||(c==null?void 0:c.key)===" ")&&s()},{capture:!0}),i.addEventListener("focusin",s,{capture:!0}),t==null||t.addEventListener("pointerdown",s,{capture:!0}),t==null||t.addEventListener("click",s,{capture:!0}),t==null||t.addEventListener("focusin",s,{capture:!0});const o=performance.now();this.performanceMetrics.set(n,{start:e,end:o,duration:o-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isAppleReady=!0}})}initGoogle(t){return Y(this,null,function*(){const e=performance.now(),n="Google Pay";if(!this.googlePay){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isGoogleReady=!1;try{if(yield this.googlePay.init({onError:i=>{this.events.error.emit(i),this.attempted.delete(K.GOOGLE_PAY)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(K.GOOGLE_PAY)},onSuccess:i=>{this.events.success.emit(J(H({},i),{type:"google"})),this.attempted.delete(K.GOOGLE_PAY)}})){const i=this.googlePay.render();t==null||t.appendChild(i);const s=()=>{this.attempted.has(K.GOOGLE_PAY)||(this.attempted.add(K.GOOGLE_PAY),this.events.onPaymentAttempt.emit(K.GOOGLE_PAY))};i.addEventListener("pointerdown",s,{capture:!0}),i.addEventListener("click",s,{capture:!0}),i.addEventListener("keydown",c=>{((c==null?void 0:c.key)==="Enter"||(c==null?void 0:c.key)===" ")&&s()},{capture:!0}),i.addEventListener("focusin",s,{capture:!0}),t==null||t.addEventListener("pointerdown",s,{capture:!0}),t==null||t.addEventListener("click",s,{capture:!0}),t==null||t.addEventListener("focusin",s,{capture:!0});const o=performance.now();this.performanceMetrics.set(n,{start:e,end:o,duration:o-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isGoogleReady=!0}})}initPayPal(t){return Y(this,null,function*(){const e=performance.now(),n="PayPal";if(!this.paypal){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isPayPalReady=!1;try{const a=this.paypal.render();if(t==null||t.appendChild(a),yield this.paypal.init({onError:s=>this.events.error.emit(s),onCancel:()=>this.events.cancel.emit(),onSuccess:s=>{this.events.success.emit({paypalId:s,type:"paypal"})}})){const s=performance.now();this.performanceMetrics.set(n,{start:e,end:s,duration:s-e,status:"✓ Rendered"})}else{t==null||t.remove();const s=performance.now();this.performanceMetrics.set(n,{start:e,end:s,duration:s-e,status:"✗ Not supported"})}}catch(a){t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isPayPalReady=!0}})}initBraintreeVenmo(t){return Y(this,null,function*(){const e=performance.now(),n="Venmo";if(!this.braintree){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isBraintreeReady=!1;try{if(yield this.braintree.init({onError:i=>this.events.error.emit(i),onCancel:()=>this.events.cancel.emit(),onSuccess:i=>{this.events.success.emit({nonce:i==null?void 0:i.nonce,type:"venmo"})}})){const i=this.braintree.render();t==null||t.appendChild(i);const s=performance.now();this.performanceMetrics.set(n,{start:e,end:s,duration:s-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(n,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isBraintreeReady=!0}})}initCard(t){return Y(this,null,function*(){const e=performance.now(),n="Card";if(!this.card){t==null||t.remove(),this.performanceMetrics.set(n,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}t==null||t.appendChild(this.card.render());const a=performance.now();this.performanceMetrics.set(n,{start:e,end:a,duration:a-e,status:"✓ Rendered"})})}waitForElementVisible(t,e=150){return!t||!(t instanceof HTMLElement)?Promise.resolve():new Promise(n=>{const a=performance.now(),i=()=>{const s=t.getBoundingClientRect();if(s.width>0&&s.height>0||performance.now()-a>=e)return n();requestAnimationFrame(i)};requestAnimationFrame(i)})}initPaymentMethods(){return Y(this,null,function*(){const t=this.config.state.transaction.getState(),e=Vc(Rc,(t==null?void 0:t.checkout_config)||[],(l,d)=>l.type===d.type),n=this.config.state.checkout.getState();let a=e.filter(({is_active:l})=>l);(n==null?void 0:n.variant)==="default"&&(a=a.filter(({type:l})=>l!==K.CARD)),this.initializeButtonInstances(a),this.buttons.innerHTML="";const i=a.sort((l,d)=>l.order-d.order),s=new Map;for(const{type:l}of i){const d=document.createElement("div");this.buttons.appendChild(d),s.set(l,d)}const o=i.map(({type:l})=>{const d=s.get(l);switch(l){case K.APPLE_PAY:return this.initApple(d);case K.GOOGLE_PAY:return this.initGoogle(d);case K.PAYPAL:return this.initPayPal(d);case K.VENMO:return this.initBraintreeVenmo(d);case K.CARD:return this.initCard(d);default:throw new Error("Unknown button type")}});yield Promise.all(o);const c=[];for(const l of s.values()){const d=l.firstElementChild;d&&c.push(this.waitForElementVisible(d))}yield Promise.all(c),this.handleReady()})}initializeButtonInstances(t){const e=t.map(({type:n})=>n);e.includes(K.APPLE_PAY)&&!this.applePay&&(this.applePay=new Lc(this.config)),e.includes(K.GOOGLE_PAY)&&!this.googlePay&&(this.googlePay=new kc(this.config)),e.includes(K.PAYPAL)&&!this.paypal&&(this.paypal=new Sc(this.config),this.paypal.addEventListener("onPaymentAttempt",n=>this.events.onPaymentAttempt.emit(n))),e.includes(K.VENMO)&&!this.braintree&&(this.braintree=new Bc(this.config),this.braintree.addEventListener("onPaymentAttempt",n=>this.events.onPaymentAttempt.emit(n))),e.includes(K.CARD)&&!this.card&&(this.card=new Dc(this.config),this.card.addEventListener(()=>{this.events.open.emit()}))}handleReady(){this.isAppleReady&&this.isGoogleReady&&this.isPayPalReady&&this.isBraintreeReady&&(this.logPerformanceMetrics(),this.events.ready.emit())}addEventListener(t,e){return this.events[t].addListener(e)}showButton(){this.buttons.classList.remove(yr.hidden)}render(){return this.buttons}}class jc{constructor(){C(this,"template",`
52
52
  <svg
53
53
  xmlns='http://www.w3.org/2000/svg'
54
54
  width='24'