@bizzsv/bizz-payment 1.5.5-dev → 1.5.6-dev

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.cjs CHANGED
@@ -35,6 +35,7 @@ Por favor revisa tu información e inténtalo de nuevo`)}buildConfirmPayload(e){
35
35
  min-height: 240px;
36
36
  height: 100%;
37
37
  width: 100%;
38
+ margin: 0 auto;
38
39
  box-sizing: border-box;
39
40
  padding: 48px 16px;
40
41
  gap: 16px;
@@ -194,7 +195,7 @@ Por favor revisa tu información e inténtalo de nuevo`,code:0},Zt=[{label:`Docu
194
195
  ${u}
195
196
  ${i?`\n <template class="operation-form-template" data-operation="crypto">${i}</template>`:``}
196
197
  </div>
197
- `}function xn(e){let t=`<img src="${hn}" alt="Bizz Logo" class="bizz-logo">`,n=bn(e.cardFormHtml||``,e.submitButtonHtml,e.pointsFormHtml||``,e.installmentFormHtml||``,e.cryptoFormHtml||``);return pn.replace(`<!--STYLES-->`,`<style>${gn}</style>`).replace(`<!--BIZZ_LOGO-->`,t).replace(`<!--HEADER-->`,e.headerHtml).replace(`<!--OPERATION_SELECTION-->`,n).replace(`<!--VERSION-->`,`<div class="bizz-sdk-version">v1.5.5</div>`).replace(`<!--SCRIPT-->`,`<script>${mn}<\/script>`)}function Sn(e){let t=document.createElement(`iframe`);return t.style.border=`none`,t.style.display=`block`,t.style.overflow=`hidden`,t.srcdoc=e,t.style.width=`100%`,t.style.height=`100%`,t}var Cn=class e{static instance;request;constructor(){this.request=vt.getInstance()}static getInstance(){return e.instance||=new e,e.instance}async createCharge(e){let t=await this.request.post(`external/online_payments/orders/crypto/charge`,e);if(!t.ok){let e=typeof t.json==`function`?await t.json().catch(()=>null):null,n=e?.error||e?.message||(typeof e==`object`&&e?JSON.stringify(e):null)||`Charge creation failed with status ${t.status}`,r=Error(n);throw r.status=t.status,r.data=e,r}return await t.json()}async getChargeStatus(e){let t=await this.request.get(`external/online_payments/orders/crypto/charge/${e}/status`);if(!t.ok){let e=typeof t.json==`function`?await t.json().catch(()=>null):null,n=e?.error||e?.message||(typeof e==`object`&&e?JSON.stringify(e):null)||`Charge status failed with status ${t.status}`,r=Error(n);throw r.status=t.status,r.data=e,r}return await t.json()}},wn=3e3,Tn=`NAKA_CRYPTO`,En=`CRYPTO`,$={UNDERPAID:{title:`Pago incompleto`,message:`El monto pagado en criptomonedas fue inferior al total requerido. El cobro ha finalizado y tu reembolso ha sido gestionado a través de la pasarela.`,retryLabel:`Intentar nuevamente`},OVERPAID:{finishLabel:`Finalizar compra (Pago recibido)`},CANCELED:{title:`¡Pago cancelado!`,message:`El pago con criptomonedas fue cancelado.`},EXPIRED:{title:`¡Cobro expirado!`,message:`El tiempo para completar el pago con criptomonedas ha finalizado.`},FAILED:{title:`¡Pago fallido!`,message:`No se pudo procesar el pago con criptomonedas.`},TIMEOUT:{title:`¡Tiempo de espera agotado!`,message:`El tiempo para completar el pago con criptomonedas ha expirado.`},CONNECTION_ERROR:{title:`¡Error de conexión!`,message:`No fue posible verificar el estado del pago con criptomonedas.`},SESSION_EXPIRED:{title:`¡Sesión expirada!`,message:`Tu sesión ha expirado. Por favor, intenta de nuevo.`},ORDER_NOT_FOUND:{title:`¡Orden no encontrada!`,message:`El cobro no se encuentra disponible o fue cancelado.`},PAYMENT_UNAVAILABLE:{title:`¡Pago no disponible!`,defaultMessage:`No fue posible procesar el cobro con criptomonedas. Por favor, intenta con otro método.`},CREATE_CHARGE_ERROR:{title:`¡Error al crear cobro con Criptomonedas!`,message:`No se pudo conectar con el servicio de pagos en criptomonedas.`}},Dn=`<svg
198
+ `}function xn(e){let t=`<img src="${hn}" alt="Bizz Logo" class="bizz-logo">`,n=e.customBodyHtml??bn(e.cardFormHtml||``,e.submitButtonHtml,e.pointsFormHtml||``,e.installmentFormHtml||``,e.cryptoFormHtml||``);return pn.replace(`<!--STYLES-->`,`<style>${gn}</style>`).replace(`<!--BIZZ_LOGO-->`,t).replace(`<!--HEADER-->`,e.headerHtml).replace(`<!--OPERATION_SELECTION-->`,n).replace(`<!--VERSION-->`,`<div class="bizz-sdk-version">v1.5.6</div>`).replace(`<!--SCRIPT-->`,`<script>${mn}<\/script>`)}function Sn(e){let t=document.createElement(`iframe`);return t.style.border=`none`,t.style.display=`block`,t.style.overflow=`hidden`,t.srcdoc=e,t.style.width=`100%`,t.style.height=`100%`,t}var Cn=class e{static instance;request;constructor(){this.request=vt.getInstance()}static getInstance(){return e.instance||=new e,e.instance}async createCharge(e){let t=await this.request.post(`external/online_payments/orders/crypto/charge`,e);if(!t.ok){let e=typeof t.json==`function`?await t.json().catch(()=>null):null,n=e?.error||e?.message||(typeof e==`object`&&e?JSON.stringify(e):null)||`Charge creation failed with status ${t.status}`,r=Error(n);throw r.status=t.status,r.data=e,r}return await t.json()}async getChargeStatus(e){let t=await this.request.get(`external/online_payments/orders/crypto/charge/${e}/status`);if(!t.ok){let e=typeof t.json==`function`?await t.json().catch(()=>null):null,n=e?.error||e?.message||(typeof e==`object`&&e?JSON.stringify(e):null)||`Charge status failed with status ${t.status}`,r=Error(n);throw r.status=t.status,r.data=e,r}return await t.json()}},wn=3e3,Tn=`NAKA_CRYPTO`,En=`CRYPTO`,$={UNDERPAID:{title:`Pago incompleto`,message:`El monto pagado en criptomonedas fue inferior al total requerido. El cobro ha finalizado y tu reembolso ha sido gestionado a través de la pasarela.`,retryLabel:`Intentar nuevamente`},OVERPAID:{finishLabel:`Finalizar compra (Pago recibido)`},CANCELED:{title:`¡Pago cancelado!`,message:`El pago con criptomonedas fue cancelado.`},EXPIRED:{title:`¡Cobro expirado!`,message:`El tiempo para completar el pago con criptomonedas ha finalizado.`},FAILED:{title:`¡Pago fallido!`,message:`No se pudo procesar el pago con criptomonedas.`},TIMEOUT:{title:`¡Tiempo de espera agotado!`,message:`El tiempo para completar el pago con criptomonedas ha expirado.`},CONNECTION_ERROR:{title:`¡Error de conexión!`,message:`No fue posible verificar el estado del pago con criptomonedas.`},SESSION_EXPIRED:{title:`¡Sesión expirada!`,message:`Tu sesión ha expirado. Por favor, intenta de nuevo.`},ORDER_NOT_FOUND:{title:`¡Orden no encontrada!`,message:`El cobro no se encuentra disponible o fue cancelado.`},PAYMENT_UNAVAILABLE:{title:`¡Pago no disponible!`,defaultMessage:`No fue posible procesar el cobro con criptomonedas. Por favor, intenta con otro método.`},CREATE_CHARGE_ERROR:{title:`¡Error al crear cobro con Criptomonedas!`,message:`No se pudo conectar con el servicio de pagos en criptomonedas.`}},Dn=`<svg
198
199
  xmlns="http://www.w3.org/2000/svg"
199
200
  width="24"
200
201
  height="24"
@@ -261,4 +262,31 @@ Por favor revisa tu información e inténtalo de nuevo`,code:0},Zt=[{label:`Docu
261
262
  <path d="M12 3a12 12 0 0 0 8.5 3a12 12 0 0 1 -8.5 15a12 12 0 0 1 -8.5 -15a12 12 0 0 0 8.5 -3" />
262
263
  <path d="M11 11a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
263
264
  <path d="M12 12l0 2.5" />
264
- </svg>`,jn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-mail"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 7a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10" /><path d="M3 7l9 6l9 -6" /></svg>`,Mn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-user"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0" /><path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" /></svg>`,Nn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-message-circle"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 20l1.3 -3.9c-2.324 -3.437 -1.426 -7.872 2.1 -10.374c3.526 -2.501 8.59 -2.296 11.845 .48c3.255 2.777 3.695 7.266 1.029 10.501c-2.666 3.235 -7.615 4.215 -11.574 2.293l-4.7 1" /></svg>`,Pn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-id"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 7a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v10a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3l0 -10" /><path d="M7 10a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" /><path d="M15 8l2 0" /><path d="M15 12l2 0" /><path d="M7 16l10 0" /></svg>`,Fn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-device-mobile"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 5a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-14" /><path d="M11 4h2" /><path d="M12 17v.01" /></svg>`,In=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-map-pin"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 11a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" /><path d="M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0" /></svg>`,Ln={"currency-dollar":Dn,"credit-card":On,calendar:kn,"shield-lock":An,email:jn,user:Mn,description:Nn,document:Pn,phone:Fn,"map-pin":In};function Rn(e){let t=Ln[e];if(!t)throw Error(`Icon "${e}" not found`);return t}var zn=class e{static instance;currentDate=new Date;currentYear=this.currentDate.getFullYear();currentMonth=this.currentDate.getMonth()+1;static getInstance(){return e.instance||=new e,e.instance}validateField(e,t){return this.inputRequired(t)||({amount:e=>this.amountInput(e),cardNumber:e=>this.cardNumberInput(e),cardExpiry:e=>this.cardExpiryInput(e),cardCvc:e=>this.cardCvcInput(e),email:e=>this.emailInput(e)}[e]?.(t)??``)}inputRequired(e){return e.trim()===``?`Este campo es requerido`:``}amountInput(e){return Number(e)<=0?`El monto debe ser mayor a 0`:``}cardNumberInput(e){let t=e.replace(/\s/g,``);return/^[0-9]{16}$/.test(t)?kt(t)===`not_valid`?`Por favor ingrese una tarjeta visa, mastercard o union_pay`:``:`Por favor, ingrese un número de tarjeta válido`}cardExpiryInput(e){let[t,n]=e.split(`/`),r=Number(this.currentYear.toString().slice(-2));return Number(n)<r?`El año de expiración no puede ser anterior al año actual`:Number(t)<1||Number(t)>12?`El mes de expiración debe estar entre 01 y 12`:Number(n)===r&&Number(t)<this.currentMonth?`La tarjeta está expirada`:``}emailInput(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?``:`Por favor, ingrese un email válido`}cardCvcInput(e){return/^[0-9]{3,4}$/.test(e)?``:`Por favor, ingrese un código de seguridad válido`}},Bn=(e,t,n,r)=>Object.keys(t).map(i=>{let a=t[i],o=e.get(i);return{name:i,label:o?.label??a.label,placeholder:o?.placeholder??a.placeholder??a.label,iconSvg:Rn(a.icon),mask:a.mask,divider:a.divider,type:a.type??`text`,options:a.type===`select`?a.options:void 0,default:a.default,amountValue:n?Vt(n/100,`USD`,`decimal`):void 0,disabled:i===`amount`?r:!1,autocomplete:a.autocomplete}}),Vn=class{static version=`1.5.5`;config;iframe=null;messageHandler=null;successListeners=new Set;failureListeners=new Set;readyListeners=new Set;sizingListeners=new Set;validation=zn.getInstance();origin=u;serverErrorHandler;orchestrator=Tt.getInstance();paymentIntent=qt.getInstance();points=Jt.getInstance();countryContent=Dt.getInstance();processPayment=Ft.getInstance();stateContent=Ot.getInstance();amountEvaluation=Ut.getInstance();currentAmount;currentValues={};pointsPaymentContext=null;nakaPollingInterval=null;pendingAlert=null;currentCryptoChargeId=null;isCryptoOverpaid=!1;lastCryptoOverpaidSuccess=null;constructor(e){if(this.config={...e},!this.config.paymentOrderCode&&typeof window<`u`&&window.location?.search){let e=new URLSearchParams(window.location.search).get(`o`);e&&(this.config.paymentOrderCode=e)}if(!this.config.paymentRequestCode&&typeof window<`u`&&window.location?.search){let e=new URLSearchParams(window.location.search).get(`t`);e&&(this.config.paymentRequestCode=e)}this.currentAmount=this.config.totalAmount,this.serverErrorHandler=new Kt(this.origin)}on(e,t){e===`success`?this.successListeners.add(t):e===`failure`?this.failureListeners.add(t):e===`ready`?this.readyListeners.add(t):e===`sizing`&&this.sizingListeners.add(t)}async setup(){let e=document.querySelector(this.config.iframeTarget);if(!e)throw Error(`Element not found: ${this.config.iframeTarget}`);let t=zt(this.config.i18n?.loading);e.appendChild(t);try{await this.orchestrator.initialize({branchCode:this.config.branchCode,paymentRequestCode:this.config.paymentRequestCode,paymentOrderCode:this.config.paymentOrderCode,environment:this.config.environment})}catch(n){t.remove();let r=document.createElement(`div`);r.style.cssText=`font-family:Poppins,sans-serif;text-align:center;padding:32px;color:#DB3339;font-size:14px;`,r.textContent=n instanceof Error?n.message:`Pago no procesado`,e.appendChild(r);return}if(t.remove(),this.applyFixedAmountFromOrderTemplate(),await this.renderForm(),this.messageHandler=async e=>{if(e.source&&e.source!==this.iframe?.contentWindow&&e.source!==window)return;let t=e.data;if(t?.type){if(t.type===`payment-form:ready`&&(this.pendingAlert&&=(this.sendAlert(this.pendingAlert.title,this.pendingAlert.message),null)),t.type===`payment-form:states-loaded`&&this.stateContent.setStates(t.states),t.type===`payment-form:sizing`&&(this.iframe&&(this.iframe.style.height=`${t.height}px`),this.sendSizingEmitter(t.width,t.height)),t.type===`payment-form:validate-amount`){this.currentAmount=Ht(t.amount),this.setSubmitLoading(!0);let e=await this.amountEvaluation.validateAmount(t.amount,t.force);if(this.setSubmitLoading(!1),e&&`data`in e){let t=this.orchestrator.getConfig();t.data.secure_mode!==e.data.secure_mode&&(t.data.secure_mode=e.data.secure_mode,await this.renderForm())}}if(t.type===`payment-form:validate`){this.currentValues[t.field]=t.value;let e=this.validation.validateField(t.field,t.value);this.iframe?.contentWindow?.postMessage({type:`payment-form:validation-result`,field:t.field,error:e},this.origin)}if(t.type===`payment-form:submit`){t.value.amount&&(this.currentAmount=Ht(t.value.amount));let e=!1,n=Object.keys(t.value);for(let r of n){let n=this.validation.validateField(r,t.value[r]??``);n&&(e=!0,this.iframe?.contentWindow?.postMessage({type:`payment-form:validation-result`,field:r,error:n},this.origin))}if(!e){if(this.setSubmitLoading(!0),t.value.operation===`crypto`){await this.handleCryptoPayment(t.value);return}if(t.value.operation===`points`){await this.handlePointsBalance(t.value),this.setSubmitLoading(!1);return}if(this.orchestrator.getConfig().data.secure_mode){try{await this.processPayment.process(t.value,this.config.totalAmount,{sendAlert:(e,t)=>this.sendAlert(e,t),sendSuccess:e=>this.sendSuccess(e),resetForm:()=>this.resetForm()})}catch{let e=`No pudimos obtener información de encriptación`;this.sendAlert(`¡Error al encriptar tus datos!`,e),this.sendFailureEmitter(0,e)}finally{this.setSubmitLoading(!1)}return}let e=await this.paymentIntent.generatePaymentIntentPayload(t.value).catch(e=>{this.setSubmitLoading(!1),this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`)});if(!e)return;this.config.totalAmount&&(e.subtotal_cents=this.config.totalAmount),t.value.operation===`installments`&&(e.months=t.value.installments);let n=await this.paymentIntent.createPaymentIntent(e);if(this.setSubmitLoading(!1),`error`in n&&`code`in n){if(n.status===422&&this.serverErrorHandler.hasEncryptionPayloadErrors(n.error)){let e=`Error al encriptar tus datos.`;this.sendAlert(`¡Error al encriptar tus datos!`,e),this.sendFailureEmitter(n.status,e);return}if(n.status===422&&this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow,n.error)){this.sendFailureEmitter(n.status,`Por favor, revisa los campos`);return}n.code===`inactive_company_commerce`?this.sendAlert(`¡Comercio inactivo!`,`Tu compra no pudo ser procesada! El comercio no está disponible por el momento`):n.code===`payment_limit_exceeded`?this.sendAlert(`¡Límite de pago excedido!`,`Por favor, contacta al comercio.`):n.status===422?this.sendAlert(`¡Revisa la información!`,`Por favor, revisa los campos`):this.sendAlert(`¡Error al procesar el pago!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.sendFailureEmitter(n.status,this.serverErrorHandler.resolveServerErrorMessage(n.error));return}if(n.data.status!==`success`){let e=Xt(n.data.response_code??``);this.sendAlert(e.title,e.message),this.sendFailureEmitter(0,e.message);return}if(n.data.status===`success`){this.sendSuccess(n),this.resetForm();return}}}if(t.type===`payment-form:points-pay`&&await this.processPointsPayment(),t.type===`payment-form:load-crypto-countries`){this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let e=this.countryContent.getCountries(),t={...nn,country:{...nn.country,options:[{label:`Selecciona aquí`,value:``},...e.map(e=>({label:e.name,value:e.alpha2||e.id}))]}},n=new Map((this.config.i18n?.fields??[]).map(e=>[e.name,e])),r=!!this.config.totalAmount,i=fn(Bn(n,t,this.currentAmount,r));this.iframe?.contentWindow?.postMessage({type:`payment-form:update-forms`,forms:{crypto:i}},this.origin)}if(t.type===`payment-form:naka-callback`){this.stopNakaPolling();let e=t.chargeId||this.currentCryptoChargeId,n=Cn.getInstance(),r=t.status,i=null;if(e)try{let t=await n.getChargeStatus(e);t?.data&&(i=t.data,r=i.status)}catch(e){if(e?.status===422){let t=e?.data?.error||$.PAYMENT_UNAVAILABLE.defaultMessage;await this.handleNakaTerminalFailure($.PAYMENT_UNAVAILABLE.title,t,422);return}if(e?.status===404){await this.handleNakaTerminalFailure($.ORDER_NOT_FOUND.title,$.ORDER_NOT_FOUND.message,404);return}await this.handleNakaTerminalFailure($.CONNECTION_ERROR.title,$.CONNECTION_ERROR.message,500);return}if(r===`UNDERPAID`){this.stopNakaPolling(),this.postMessageToIframe({type:`payment-form:crypto-incomplete`,title:$.UNDERPAID.title,message:$.UNDERPAID.message,retryLabel:$.UNDERPAID.retryLabel}),this.sendFailureEmitter(422,$.UNDERPAID.message);return}if(r===`CANCELED`||r===`CANCELLED`){await this.handleNakaTerminalFailure($.CANCELED.title,$.CANCELED.message,400);return}if(r===`EXPIRED`){await this.handleNakaTerminalFailure($.EXPIRED.title,$.EXPIRED.message,410);return}if(r===`FAILED`||r===`REJECTED`){await this.handleNakaTerminalFailure($.FAILED.title,$.FAILED.message,422);return}if(r===`SUCCESS`||r===`COMPLETED`||r===`PAID`||r===`OVERPAID`){let n=this.orchestrator.getConfig()?.data?.amount_currency||`USD`,r={data:{id:e||``,status:`success`,amount_cents:this.config.totalAmount??this.currentAmount??i?.amount_cents??0,amount_currency:n,response_code:`00`,authorization_number:i?.authorization_number||i?.transaction_id||t.chargeId||`NAKA-${Date.now()}`,reference_number:i?.reference_number||i?.order_number||t.orderNumber||e||``,billing_document_number:``,description:this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:Tn,card_last_digits:En,invoice_serie:null}};this.sendSuccess(r);return}}if(t.type===`payment-form:return-initial`){if(this.stopNakaPolling(),this.isCryptoOverpaid&&this.lastCryptoOverpaidSuccess){this.sendSuccess(this.lastCryptoOverpaidSuccess);return}this.iframe&&=(this.iframe.remove(),null),await this.renderForm();return}if(t.type===`payment-form:crypto-retry`){this.stopNakaPolling(),this.iframe&&=(this.iframe.remove(),null),await this.renderForm();return}}},window.addEventListener(`message`,this.messageHandler),this.config.totalAmount&&Number(this.config.totalAmount)>0)try{this.setSubmitLoading(!0);let e=await this.amountEvaluation.validateAmount(this.config.totalAmount.toString());if(this.setSubmitLoading(!1),e&&`data`in e){let t=this.orchestrator.getConfig();t.data.secure_mode!==e.data.secure_mode&&(t.data.secure_mode=e.data.secure_mode,await this.renderForm())}}catch{this.setSubmitLoading(!1),this.sendAlert(`¡Error al validar el monto!`,`Asegúrate de que el monto a pagar sea válido`)}}applyFixedAmountFromOrderTemplate(){let e=this.orchestrator.getConfig();if(!e?.data)return;let{data:t}=e;if(t.order_template_id==null&&t.order_id==null||typeof t.amount_cents!=`number`||t.amount_cents<=0)return;let n=Vt(t.amount_cents/100,t.amount_currency||`USD`,`decimal`);this.config.description=t.description,this.config.totalAmount=Ht(n),this.currentAmount=Ht(n)}async renderForm(){let e=document.querySelector(this.config.iframeTarget);if(!e)return;let t=new Map((this.config.i18n?.fields??[]).map(e=>[e.name,e])),n=this.orchestrator.getConfig().data.secure_mode,r=this.orchestrator.getConfig().data.payment_methods,i=r.includes(`emv`),a=r.includes(`ba_puntos`),o=r.includes(`ba_plazos`),s=r.includes(`crypto`);n&&this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let c=this.countryContent.getCountries(),l=n?{...tn,country:{...tn.country,options:[{label:`Selecciona aquí`,value:``},...c.map(e=>({label:e.name,value:e.id}))]}}:en,u=en,d=!!this.config.totalAmount,f=Bn(t,l,this.currentAmount,d),p=n?Bn(t,u,this.currentAmount,d):f,m=Bn(t,{...nn,country:{...nn.country,options:[{label:`Selecciona aquí`,value:``},...c.map(e=>({label:e.name,value:e.alpha2||e.id}))]}},this.currentAmount,d);[f,p,m].forEach(e=>{e.forEach(e=>{this.currentValues[e.name]!==void 0&&e.name!==`amount`&&(e.default=this.currentValues[e.name])})});let h=rn(this.config.i18n?.submitButton),g=i?ln(f):``,_=a?un(p):``,v=o?dn(p,h):``,y=s?fn(m):``;if(this.iframe){this.iframe.contentWindow?.postMessage({type:`payment-form:update-forms`,forms:{default:g+h,points:_,installments:v,crypto:y}},this.origin),this.notifyCountriesLoadError();return}let b=this.config.totalAmount?Vt(this.config.totalAmount/100,`USD`,`decimal`):``;this.iframe=Sn(xn({headerHtml:an({logo:this.orchestrator.getConfig().data.logo_url,name:this.orchestrator.getConfig().data.name,description:this.config.description,header:this.config.header,totalAmount:b,...b?{icon:Rn(`currency-dollar`)}:{}}),cardFormHtml:g,submitButtonHtml:h,pointsFormHtml:_,installmentFormHtml:v,cryptoFormHtml:y})),e.appendChild(this.iframe),this.iframe.addEventListener(`load`,()=>{this.setToken(this.orchestrator.getAuthToken().access_token),this.notifyCountriesLoadError(),this.sendReadyEmitter()})}notifyCountriesLoadError(){let e=this.countryContent.getCountriesLoadError();e&&this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow,{country:[e]})}postMessageToIframe(e){try{this.iframe?.contentWindow?.postMessage(e,this.origin)}catch{try{this.iframe?.contentWindow?.postMessage(e,`*`)}catch{}}}resetForm(){this.postMessageToIframe({type:`payment-form:reset`})}setSubmitLoading(e){this.postMessageToIframe({type:`payment-form:set-submit-loading`,disabled:e})}setToken(e){this.postMessageToIframe({type:`payment-form:set-token`,token:e})}sendAlert(e,t){this.postMessageToIframe({type:`payment-form:alert`,title:e,message:t})}sendFailureEmitter(e,t){for(let n of this.failureListeners)n({status:e,message:t})}async processPointsPayment(){if(!this.pointsPaymentContext)return;let{value:e,points:t}=this.pointsPaymentContext,n;try{n=await this.paymentIntent.generatePaymentIntentPayload(e)}catch{this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.resetPointsPayButton();return}n.operation=`points`,n.points=t.toString(),this.config.totalAmount&&(n.subtotal_cents=this.config.totalAmount);let r=await this.paymentIntent.createPaymentIntent(n);if(`error`in r&&`code`in r){this.sendAlert(`¡Error al procesar el pago!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.sendFailureEmitter(r.status,this.serverErrorHandler.resolveServerErrorMessage(r.error)),this.resetPointsPayButton();return}if(r.data.status!==`success`){let e=Xt(r.data.response_code??``);this.sendAlert(e.title,e.message),this.sendFailureEmitter(0,e.message),this.resetPointsPayButton();return}this.sendSuccess(r)}resetPointsPayButton(){this.iframe?.contentWindow?.postMessage({type:`payment-form:points-pay-reset`},this.origin)}async handlePointsBalance(e){let t;try{t=await this.points.generatePayload(e)}catch{this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`);return}let n=await this.points.getPointsBalance(t).catch(()=>null);if(!n||`error`in n||n.data.in_dollar_cents<=0){this.sendAlert(`¡Error al consultar tus puntos!`,`Por favor, intenta nuevamente, o contacta al comercio.`);return}let r=this.config.totalAmount??this.currentAmount??Ht(e.amount),i=Math.round(r*n.data.points/n.data.in_dollar_cents);this.pointsPaymentContext={value:e,points:i},this.iframe?.contentWindow?.postMessage({type:`payment-form:points-balance`,balance:{availableCents:n.data.in_dollar_cents,availablePoints:n.data.points,currency:n.data.in_dollar_currency,purchaseCents:r,purchasePoints:i},formValues:e},this.origin)}sendReadyEmitter(){for(let e of this.readyListeners)e()}sendSizingEmitter(e,t){for(let n of this.sizingListeners)n({width:e,height:t})}sendSuccess(e){this.config.totalAmount&&(e.data.amount_cents=this.config.totalAmount),this.postMessageToIframe({type:`payment-form:success`,paymentIntent:e});let{id:t,status:n,amount_cents:r,response_code:i,authorization_number:a,reference_number:o}=e.data,s={id:t,status:n,amount_cents:r,response_code:i,authorization_number:a,reference_number:o};for(let e of this.successListeners)e(s)}async handleCryptoPayment(e){this.setSubmitLoading(!0);let t=Cn.getInstance(),n=this.config.totalAmount??this.currentAmount??Ht(e.amount||`0`);this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let r=e.country||``,i=this.countryContent.getCountries().find(e=>e.id===r||e.alpha2===r||e.name===r)?.alpha2||(r.length===2?r.toUpperCase():void 0),a={data:{branch_id:this.orchestrator.getConfig()?.data?.branch_id||this.config.branchCode,amount_cents:n,currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,description:e.description||this.config.description||`Pago con Criptomonedas`,billing_document_number:e.billingDocumentNumber||``,redirect_url:this.config.redirectUrl||(typeof window<`u`?`${window.location.origin}/paylink/crypto/callback`:void 0),kyc:{email:e.email||``,first_name:e.firstName||``,last_name:e.lastName||``,country:i||``,phone:e.phone||void 0,phone_number:e.phone||void 0,nationality:e.nationality?.toUpperCase()||i||void 0,city:e.city||void 0,postal_code:e.postalCode||void 0,zip_code:e.postalCode||e.zipCode||void 0,address:e.address||void 0}}};try{let r=await t.createCharge(a);this.currentCryptoChargeId=r.data.charge_id,this.setSubmitLoading(!1),this.postMessageToIframe({type:`payment-form:naka-checkout`,redirectUrl:r.data.redirect_url,chargeId:r.data.charge_id}),this.startNakaPolling(r.data.charge_id,n,e)}catch(e){this.setSubmitLoading(!1),this.sendAlert($.CREATE_CHARGE_ERROR.title,$.CREATE_CHARGE_ERROR.message),this.sendFailureEmitter(500,e instanceof Error?e.message:`Error en servicio de criptomonedas`)}}async handleNakaTerminalFailure(e,t,n){this.stopNakaPolling(),this.iframe&&=(this.iframe.remove(),null),this.pendingAlert={title:e,message:t},await this.renderForm(),this.sendFailureEmitter(n,t)}startNakaPolling(e,t,n){this.stopNakaPolling();let r=Cn.getInstance(),i=0,a=Date.now();this.nakaPollingInterval=setInterval(async()=>{try{if(Date.now()-a>=18e5){await this.handleNakaTerminalFailure($.TIMEOUT.title,$.TIMEOUT.message,408);return}let o=await r.getChargeStatus(e);i=0;let s=o.data,c=s?.status;if(c===`SUCCESS`||c===`COMPLETED`||c===`PAID`){this.stopNakaPolling();let r={data:{id:e,status:`success`,amount_cents:t,amount_currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,response_code:`00`,authorization_number:s.authorization_number||s.transaction_id||`NAKA-${Date.now()}`,reference_number:s.reference_number||s.order_number||e,billing_document_number:n.billingDocumentNumber||``,description:n.description||this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:Tn,card_last_digits:En,invoice_serie:null}};this.sendSuccess(r);return}if(c===`CANCELED`||c===`CANCELLED`){await this.handleNakaTerminalFailure($.CANCELED.title,$.CANCELED.message,400);return}if(c===`EXPIRED`){await this.handleNakaTerminalFailure($.EXPIRED.title,$.EXPIRED.message,410);return}if(c===`FAILED`||c===`REJECTED`){await this.handleNakaTerminalFailure($.FAILED.title,$.FAILED.message,422);return}if(c===`OVERPAID`){this.isCryptoOverpaid=!0,this.lastCryptoOverpaidSuccess={data:{id:e,status:`success`,amount_cents:t,amount_currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,response_code:`00`,authorization_number:s.authorization_number||s.transaction_id||`NAKA-${Date.now()}`,reference_number:s.reference_number||s.order_number||e,billing_document_number:n.billingDocumentNumber||``,description:n.description||this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:Tn,card_last_digits:En,invoice_serie:null}},this.postMessageToIframe({type:`payment-form:crypto-overpaid`,label:$.OVERPAID.finishLabel});return}if(c===`PENDING`||c===`IN_PROGRESS`||c===`OPEN`||c===`UNDERPAID`)return}catch(e){if(e?.status===422){let t=e?.data?.error||$.PAYMENT_UNAVAILABLE.defaultMessage;await this.handleNakaTerminalFailure($.PAYMENT_UNAVAILABLE.title,t,422);return}if(e?.status===404){await this.handleNakaTerminalFailure($.ORDER_NOT_FOUND.title,$.ORDER_NOT_FOUND.message,404);return}if(e?.status===401||e?.status===403){await this.handleNakaTerminalFailure($.SESSION_EXPIRED.title,$.SESSION_EXPIRED.message,e.status);return}if(i++,i>=5){await this.handleNakaTerminalFailure($.CONNECTION_ERROR.title,$.CONNECTION_ERROR.message,500);return}}},wn)}stopNakaPolling(){this.nakaPollingInterval&&=(clearInterval(this.nakaPollingInterval),null)}destroy(){this.stopNakaPolling(),this.pendingAlert=null,this.currentCryptoChargeId=null,this.isCryptoOverpaid=!1,this.lastCryptoOverpaidSuccess=null,this.messageHandler&&=(window.removeEventListener(`message`,this.messageHandler),null),this.successListeners.clear(),this.failureListeners.clear(),this.readyListeners.clear(),this.sizingListeners.clear(),this.iframe&&=(this.iframe.remove(),null)}},Hn=`1.5.5`;exports.BizzPaymentForm=Vn,exports.VERSION=Hn;
265
+ </svg>`,jn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-mail"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 7a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10" /><path d="M3 7l9 6l9 -6" /></svg>`,Mn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-user"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0" /><path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" /></svg>`,Nn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-message-circle"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 20l1.3 -3.9c-2.324 -3.437 -1.426 -7.872 2.1 -10.374c3.526 -2.501 8.59 -2.296 11.845 .48c3.255 2.777 3.695 7.266 1.029 10.501c-2.666 3.235 -7.615 4.215 -11.574 2.293l-4.7 1" /></svg>`,Pn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-id"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 7a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v10a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3l0 -10" /><path d="M7 10a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" /><path d="M15 8l2 0" /><path d="M15 12l2 0" /><path d="M7 16l10 0" /></svg>`,Fn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-device-mobile"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 5a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-14" /><path d="M11 4h2" /><path d="M12 17v.01" /></svg>`,In=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-map-pin"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 11a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" /><path d="M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0" /></svg>`,Ln={"currency-dollar":Dn,"credit-card":On,calendar:kn,"shield-lock":An,email:jn,user:Mn,description:Nn,document:Pn,phone:Fn,"map-pin":In};function Rn(e){let t=Ln[e];if(!t)throw Error(`Icon "${e}" not found`);return t}var zn=class e{static instance;currentDate=new Date;currentYear=this.currentDate.getFullYear();currentMonth=this.currentDate.getMonth()+1;static getInstance(){return e.instance||=new e,e.instance}validateField(e,t){return this.inputRequired(t)||({amount:e=>this.amountInput(e),cardNumber:e=>this.cardNumberInput(e),cardExpiry:e=>this.cardExpiryInput(e),cardCvc:e=>this.cardCvcInput(e),email:e=>this.emailInput(e)}[e]?.(t)??``)}inputRequired(e){return e.trim()===``?`Este campo es requerido`:``}amountInput(e){return Number(e)<=0?`El monto debe ser mayor a 0`:``}cardNumberInput(e){let t=e.replace(/\s/g,``);return/^[0-9]{16}$/.test(t)?kt(t)===`not_valid`?`Por favor ingrese una tarjeta visa, mastercard o union_pay`:``:`Por favor, ingrese un número de tarjeta válido`}cardExpiryInput(e){let[t,n]=e.split(`/`),r=Number(this.currentYear.toString().slice(-2));return Number(n)<r?`El año de expiración no puede ser anterior al año actual`:Number(t)<1||Number(t)>12?`El mes de expiración debe estar entre 01 y 12`:Number(n)===r&&Number(t)<this.currentMonth?`La tarjeta está expirada`:``}emailInput(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?``:`Por favor, ingrese un email válido`}cardCvcInput(e){return/^[0-9]{3,4}$/.test(e)?``:`Por favor, ingrese un código de seguridad válido`}},Bn=(e,t,n,r)=>Object.keys(t).map(i=>{let a=t[i],o=e.get(i);return{name:i,label:o?.label??a.label,placeholder:o?.placeholder??a.placeholder??a.label,iconSvg:Rn(a.icon),mask:a.mask,divider:a.divider,type:a.type??`text`,options:a.type===`select`?a.options:void 0,default:a.default,amountValue:n?Vt(n/100,`USD`,`decimal`):void 0,disabled:i===`amount`?r:!1,autocomplete:a.autocomplete}}),Vn=class{static version=`1.5.6`;config;iframe=null;messageHandler=null;successListeners=new Set;failureListeners=new Set;readyListeners=new Set;sizingListeners=new Set;validation=zn.getInstance();origin=u;serverErrorHandler;orchestrator=Tt.getInstance();paymentIntent=qt.getInstance();points=Jt.getInstance();countryContent=Dt.getInstance();processPayment=Ft.getInstance();stateContent=Ot.getInstance();amountEvaluation=Ut.getInstance();currentAmount;currentValues={};pointsPaymentContext=null;nakaPollingInterval=null;pendingAlert=null;currentCryptoChargeId=null;isCryptoOverpaid=!1;lastCryptoOverpaidSuccess=null;constructor(e){if(this.config={...e},!this.config.paymentOrderCode&&typeof window<`u`&&window.location?.search){let e=new URLSearchParams(window.location.search).get(`o`);e&&(this.config.paymentOrderCode=e)}if(!this.config.paymentRequestCode&&typeof window<`u`&&window.location?.search){let e=new URLSearchParams(window.location.search).get(`t`);e&&(this.config.paymentRequestCode=e)}this.currentAmount=this.config.totalAmount,this.serverErrorHandler=new Kt(this.origin)}on(e,t){e===`success`?this.successListeners.add(t):e===`failure`?this.failureListeners.add(t):e===`ready`?this.readyListeners.add(t):e===`sizing`&&this.sizingListeners.add(t)}async setup(){let e=document.querySelector(this.config.iframeTarget);if(!e)throw Error(`Element not found: ${this.config.iframeTarget}`);let t=zt(this.config.i18n?.loading);e.appendChild(t);try{await this.orchestrator.initialize({branchCode:this.config.branchCode,paymentRequestCode:this.config.paymentRequestCode,paymentOrderCode:this.config.paymentOrderCode,environment:this.config.environment})}catch(n){t.remove();let r=document.createElement(`div`);r.style.cssText=`font-family:Poppins,sans-serif;text-align:center;padding:32px;color:#DB3339;font-size:14px;`,r.textContent=n instanceof Error?n.message:`Pago no procesado`,e.appendChild(r);return}t.remove(),this.setupMessageHandler();let n=this.orchestrator.getConfig()?.data?.status;if(n===`completed`){await this.renderCompletedOrderView();return}if(n===`cancelled`){await this.renderCancelledOrderView();return}if(this.applyFixedAmountFromOrderTemplate(),await this.renderForm(),this.config.totalAmount&&Number(this.config.totalAmount)>0)try{this.setSubmitLoading(!0);let e=await this.amountEvaluation.validateAmount(this.config.totalAmount.toString());if(this.setSubmitLoading(!1),e&&`data`in e){let t=this.orchestrator.getConfig();t.data.secure_mode!==e.data.secure_mode&&(t.data.secure_mode=e.data.secure_mode,await this.renderForm())}}catch{this.setSubmitLoading(!1),this.sendAlert(`¡Error al validar el monto!`,`Asegúrate de que el monto a pagar sea válido`)}}setupMessageHandler(){this.messageHandler&&window.removeEventListener(`message`,this.messageHandler),this.messageHandler=async e=>{if(e.source&&e.source!==this.iframe?.contentWindow&&e.source!==window)return;let t=e.data;if(t?.type){if(t.type===`payment-form:ready`&&(this.pendingAlert&&=(this.sendAlert(this.pendingAlert.title,this.pendingAlert.message),null)),t.type===`payment-form:states-loaded`&&this.stateContent.setStates(t.states),t.type===`payment-form:sizing`&&(this.iframe&&(this.iframe.style.height=`${t.height}px`),this.sendSizingEmitter(t.width,t.height)),t.type===`payment-form:validate-amount`){this.currentAmount=Ht(t.amount),this.setSubmitLoading(!0);let e=await this.amountEvaluation.validateAmount(t.amount,t.force);if(this.setSubmitLoading(!1),e&&`data`in e){let t=this.orchestrator.getConfig();t.data.secure_mode!==e.data.secure_mode&&(t.data.secure_mode=e.data.secure_mode,await this.renderForm())}}if(t.type===`payment-form:validate`){this.currentValues[t.field]=t.value;let e=this.validation.validateField(t.field,t.value);this.iframe?.contentWindow?.postMessage({type:`payment-form:validation-result`,field:t.field,error:e},this.origin)}if(t.type===`payment-form:submit`){t.value.amount&&(this.currentAmount=Ht(t.value.amount));let e=!1,n=Object.keys(t.value);for(let r of n){let n=this.validation.validateField(r,t.value[r]??``);n&&(e=!0,this.iframe?.contentWindow?.postMessage({type:`payment-form:validation-result`,field:r,error:n},this.origin))}if(!e){if(this.setSubmitLoading(!0),t.value.operation===`crypto`){await this.handleCryptoPayment(t.value);return}if(t.value.operation===`points`){await this.handlePointsBalance(t.value),this.setSubmitLoading(!1);return}if(this.orchestrator.getConfig().data.secure_mode){try{await this.processPayment.process(t.value,this.config.totalAmount,{sendAlert:(e,t)=>this.sendAlert(e,t),sendSuccess:e=>this.sendSuccess(e),resetForm:()=>this.resetForm()})}catch{let e=`No pudimos obtener información de encriptación`;this.sendAlert(`¡Error al encriptar tus datos!`,e),this.sendFailureEmitter(0,e)}finally{this.setSubmitLoading(!1)}return}let e=await this.paymentIntent.generatePaymentIntentPayload(t.value).catch(e=>{this.setSubmitLoading(!1),this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`)});if(!e)return;this.config.totalAmount&&(e.subtotal_cents=this.config.totalAmount),t.value.operation===`installments`&&(e.months=t.value.installments);let n=await this.paymentIntent.createPaymentIntent(e);if(this.setSubmitLoading(!1),`error`in n&&`code`in n){if(n.status===422&&this.serverErrorHandler.hasEncryptionPayloadErrors(n.error)){let e=`Error al encriptar tus datos.`;this.sendAlert(`¡Error al encriptar tus datos!`,e),this.sendFailureEmitter(n.status,e);return}if(n.status===422&&this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow,n.error)){this.sendFailureEmitter(n.status,`Por favor, revisa los campos`);return}n.code===`inactive_company_commerce`?this.sendAlert(`¡Comercio inactivo!`,`Tu compra no pudo ser procesada! El comercio no está disponible por el momento`):n.code===`payment_limit_exceeded`?this.sendAlert(`¡Límite de pago excedido!`,`Por favor, contacta al comercio.`):n.status===422?this.sendAlert(`¡Revisa la información!`,`Por favor, revisa los campos`):this.sendAlert(`¡Error al procesar el pago!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.sendFailureEmitter(n.status,this.serverErrorHandler.resolveServerErrorMessage(n.error));return}if(n.data.status!==`success`){let e=Xt(n.data.response_code??``);this.sendAlert(e.title,e.message),this.sendFailureEmitter(0,e.message);return}if(n.data.status===`success`){this.sendSuccess(n),this.resetForm();return}}}if(t.type===`payment-form:points-pay`&&await this.processPointsPayment(),t.type===`payment-form:load-crypto-countries`){this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let e=this.countryContent.getCountries(),t={...nn,country:{...nn.country,options:[{label:`Selecciona aquí`,value:``},...e.map(e=>({label:e.name,value:e.alpha2||e.id}))]}},n=new Map((this.config.i18n?.fields??[]).map(e=>[e.name,e])),r=!!this.config.totalAmount,i=fn(Bn(n,t,this.currentAmount,r));this.iframe?.contentWindow?.postMessage({type:`payment-form:update-forms`,forms:{crypto:i}},this.origin)}if(t.type===`payment-form:naka-callback`){this.stopNakaPolling();let e=t.chargeId||this.currentCryptoChargeId,n=Cn.getInstance(),r=t.status,i=null;if(e)try{let t=await n.getChargeStatus(e);t?.data&&(i=t.data,r=i.status)}catch(e){if(e?.status===422){let t=e?.data?.error||$.PAYMENT_UNAVAILABLE.defaultMessage;await this.handleNakaTerminalFailure($.PAYMENT_UNAVAILABLE.title,t,422);return}if(e?.status===404){await this.handleNakaTerminalFailure($.ORDER_NOT_FOUND.title,$.ORDER_NOT_FOUND.message,404);return}await this.handleNakaTerminalFailure($.CONNECTION_ERROR.title,$.CONNECTION_ERROR.message,500);return}if(r===`UNDERPAID`){this.stopNakaPolling(),this.postMessageToIframe({type:`payment-form:crypto-incomplete`,title:$.UNDERPAID.title,message:$.UNDERPAID.message,retryLabel:$.UNDERPAID.retryLabel}),this.sendFailureEmitter(422,$.UNDERPAID.message);return}if(r===`CANCELED`||r===`CANCELLED`){await this.handleNakaTerminalFailure($.CANCELED.title,$.CANCELED.message,400);return}if(r===`EXPIRED`){await this.handleNakaTerminalFailure($.EXPIRED.title,$.EXPIRED.message,410);return}if(r===`FAILED`||r===`REJECTED`){await this.handleNakaTerminalFailure($.FAILED.title,$.FAILED.message,422);return}if(r===`SUCCESS`||r===`COMPLETED`||r===`PAID`||r===`OVERPAID`){let n=this.orchestrator.getConfig()?.data?.amount_currency||`USD`,r={data:{id:e||``,status:`success`,amount_cents:this.config.totalAmount??this.currentAmount??i?.amount_cents??0,amount_currency:n,response_code:`00`,authorization_number:i?.authorization_number||i?.transaction_id||t.chargeId||`NAKA-${Date.now()}`,reference_number:i?.reference_number||i?.order_number||t.orderNumber||e||``,billing_document_number:``,description:this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:Tn,card_last_digits:En,invoice_serie:null}};this.sendSuccess(r);return}}if(t.type===`payment-form:return-initial`){if(this.stopNakaPolling(),this.isCryptoOverpaid&&this.lastCryptoOverpaidSuccess){this.sendSuccess(this.lastCryptoOverpaidSuccess);return}this.iframe&&=(this.iframe.remove(),null),await this.renderForm();return}if(t.type===`payment-form:crypto-retry`){this.stopNakaPolling(),this.iframe&&=(this.iframe.remove(),null),await this.renderForm();return}}},window.addEventListener(`message`,this.messageHandler)}applyFixedAmountFromOrderTemplate(){let e=this.orchestrator.getConfig();if(!e?.data)return;let{data:t}=e;if(t.order_template_id==null&&t.order_id==null||typeof t.amount_cents!=`number`||t.amount_cents<=0)return;let n=Vt(t.amount_cents/100,t.amount_currency||`USD`,`decimal`);this.config.description=t.description,this.config.totalAmount=Ht(n),this.currentAmount=Ht(n)}async renderForm(){let e=document.querySelector(this.config.iframeTarget);if(!e)return;let t=new Map((this.config.i18n?.fields??[]).map(e=>[e.name,e])),n=this.orchestrator.getConfig().data.secure_mode,r=this.orchestrator.getConfig().data.payment_methods,i=r.includes(`emv`),a=r.includes(`ba_puntos`),o=r.includes(`ba_plazos`),s=r.includes(`crypto`);n&&this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let c=this.countryContent.getCountries(),l=n?{...tn,country:{...tn.country,options:[{label:`Selecciona aquí`,value:``},...c.map(e=>({label:e.name,value:e.id}))]}}:en,u=en,d=!!this.config.totalAmount,f=Bn(t,l,this.currentAmount,d),p=n?Bn(t,u,this.currentAmount,d):f,m=Bn(t,{...nn,country:{...nn.country,options:[{label:`Selecciona aquí`,value:``},...c.map(e=>({label:e.name,value:e.alpha2||e.id}))]}},this.currentAmount,d);[f,p,m].forEach(e=>{e.forEach(e=>{this.currentValues[e.name]!==void 0&&e.name!==`amount`&&(e.default=this.currentValues[e.name])})});let h=rn(this.config.i18n?.submitButton),g=i?ln(f):``,_=a?un(p):``,v=o?dn(p,h):``,y=s?fn(m):``;if(this.iframe){this.iframe.contentWindow?.postMessage({type:`payment-form:update-forms`,forms:{default:g+h,points:_,installments:v,crypto:y}},this.origin),this.notifyCountriesLoadError();return}let b=this.config.totalAmount?Vt(this.config.totalAmount/100,`USD`,`decimal`):``;this.iframe=Sn(xn({headerHtml:an({logo:this.orchestrator.getConfig().data.logo_url,name:this.orchestrator.getConfig().data.name,description:this.config.description,header:this.config.header,totalAmount:b,...b?{icon:Rn(`currency-dollar`)}:{}}),cardFormHtml:g,submitButtonHtml:h,pointsFormHtml:_,installmentFormHtml:v,cryptoFormHtml:y})),e.appendChild(this.iframe),this.iframe.addEventListener(`load`,()=>{this.setToken(this.orchestrator.getAuthToken().access_token),this.notifyCountriesLoadError(),this.sendReadyEmitter()})}async renderCompletedOrderView(){let e=document.querySelector(this.config.iframeTarget);if(!e)return;let t=this.orchestrator.getConfig().data,n=`
266
+ <div class="payment-success">
267
+ <p class="payment-success__amount">${Vt(t.amount_cents/100,t.amount_currency||`USD`)}</p>
268
+ <div class="payment-success__blocks">
269
+ <div class="payment-success__block">
270
+ <span class="payment-success__label">Número de orden</span>
271
+ <span class="payment-success__value">${t.order_id||``}</span>
272
+ </div>
273
+ </div>
274
+ <div class="payment-success__footer">
275
+ <h3 class="payment-success__done">¡Orden completada!</h3>
276
+ <p class="payment-success__message" style="font-family:Poppins,sans-serif;font-size:0.875rem;color:#6c757d;margin-top:8px;">Esta orden ya fue pagada exitosamente.</p>
277
+ </div>
278
+ </div>
279
+ `;this.iframe=Sn(xn({headerHtml:`
280
+ <header class="form-header">
281
+ ${t.logo_url?`<img src="${t.logo_url}" alt="${t.name} Logo" class="commerce-logo">`:``}
282
+ </header>
283
+ `,submitButtonHtml:``,customBodyHtml:n})),e.appendChild(this.iframe),this.iframe.addEventListener(`load`,()=>{this.sendReadyEmitter()})}async renderCancelledOrderView(){let e=document.querySelector(this.config.iframeTarget);if(!e)return;let t=this.orchestrator.getConfig().data;this.iframe=Sn(xn({headerHtml:`
284
+ <header class="form-header">
285
+ ${t.logo_url?`<img src="${t.logo_url}" alt="${t.name} Logo" class="commerce-logo">`:``}
286
+ </header>
287
+ `,submitButtonHtml:``,customBodyHtml:`
288
+ <div class="form-alert visible" style="display:block;">
289
+ <h3>Orden cancelada</h3>
290
+ <p>Esta orden de pago ha sido cancelada o no está disponible para pago.</p>
291
+ </div>
292
+ `})),e.appendChild(this.iframe),this.iframe.addEventListener(`load`,()=>{this.sendReadyEmitter()})}notifyCountriesLoadError(){let e=this.countryContent.getCountriesLoadError();e&&this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow,{country:[e]})}postMessageToIframe(e){try{this.iframe?.contentWindow?.postMessage(e,this.origin)}catch{try{this.iframe?.contentWindow?.postMessage(e,`*`)}catch{}}}resetForm(){this.postMessageToIframe({type:`payment-form:reset`})}setSubmitLoading(e){this.postMessageToIframe({type:`payment-form:set-submit-loading`,disabled:e})}setToken(e){this.postMessageToIframe({type:`payment-form:set-token`,token:e})}sendAlert(e,t){this.postMessageToIframe({type:`payment-form:alert`,title:e,message:t})}sendFailureEmitter(e,t){for(let n of this.failureListeners)n({status:e,message:t})}async processPointsPayment(){if(!this.pointsPaymentContext)return;let{value:e,points:t}=this.pointsPaymentContext,n;try{n=await this.paymentIntent.generatePaymentIntentPayload(e)}catch{this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.resetPointsPayButton();return}n.operation=`points`,n.points=t.toString(),this.config.totalAmount&&(n.subtotal_cents=this.config.totalAmount);let r=await this.paymentIntent.createPaymentIntent(n);if(`error`in r&&`code`in r){this.sendAlert(`¡Error al procesar el pago!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.sendFailureEmitter(r.status,this.serverErrorHandler.resolveServerErrorMessage(r.error)),this.resetPointsPayButton();return}if(r.data.status!==`success`){let e=Xt(r.data.response_code??``);this.sendAlert(e.title,e.message),this.sendFailureEmitter(0,e.message),this.resetPointsPayButton();return}this.sendSuccess(r)}resetPointsPayButton(){this.iframe?.contentWindow?.postMessage({type:`payment-form:points-pay-reset`},this.origin)}async handlePointsBalance(e){let t;try{t=await this.points.generatePayload(e)}catch{this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`);return}let n=await this.points.getPointsBalance(t).catch(()=>null);if(!n||`error`in n||n.data.in_dollar_cents<=0){this.sendAlert(`¡Error al consultar tus puntos!`,`Por favor, intenta nuevamente, o contacta al comercio.`);return}let r=this.config.totalAmount??this.currentAmount??Ht(e.amount),i=Math.round(r*n.data.points/n.data.in_dollar_cents);this.pointsPaymentContext={value:e,points:i},this.iframe?.contentWindow?.postMessage({type:`payment-form:points-balance`,balance:{availableCents:n.data.in_dollar_cents,availablePoints:n.data.points,currency:n.data.in_dollar_currency,purchaseCents:r,purchasePoints:i},formValues:e},this.origin)}sendReadyEmitter(){for(let e of this.readyListeners)e()}sendSizingEmitter(e,t){for(let n of this.sizingListeners)n({width:e,height:t})}sendSuccess(e){this.config.totalAmount&&(e.data.amount_cents=this.config.totalAmount),this.postMessageToIframe({type:`payment-form:success`,paymentIntent:e});let{id:t,status:n,amount_cents:r,response_code:i,authorization_number:a,reference_number:o}=e.data,s={id:t,status:n,amount_cents:r,response_code:i,authorization_number:a,reference_number:o};for(let e of this.successListeners)e(s)}async handleCryptoPayment(e){this.setSubmitLoading(!0);let t=Cn.getInstance(),n=this.config.totalAmount??this.currentAmount??Ht(e.amount||`0`);this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let r=e.country||``,i=this.countryContent.getCountries().find(e=>e.id===r||e.alpha2===r||e.name===r)?.alpha2||(r.length===2?r.toUpperCase():void 0),a={data:{branch_id:this.orchestrator.getConfig()?.data?.branch_id||this.config.branchCode,amount_cents:n,currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,description:e.description||this.config.description||`Pago con Criptomonedas`,billing_document_number:e.billingDocumentNumber||``,redirect_url:this.config.redirectUrl||(typeof window<`u`?`${window.location.origin}/paylink/crypto/callback`:void 0),kyc:{email:e.email||``,first_name:e.firstName||``,last_name:e.lastName||``,country:i||``,phone:e.phone||void 0,phone_number:e.phone||void 0,nationality:e.nationality?.toUpperCase()||i||void 0,city:e.city||void 0,postal_code:e.postalCode||void 0,zip_code:e.postalCode||e.zipCode||void 0,address:e.address||void 0}}};try{let r=await t.createCharge(a);this.currentCryptoChargeId=r.data.charge_id,this.setSubmitLoading(!1),this.postMessageToIframe({type:`payment-form:naka-checkout`,redirectUrl:r.data.redirect_url,chargeId:r.data.charge_id}),this.startNakaPolling(r.data.charge_id,n,e)}catch(e){this.setSubmitLoading(!1),this.sendAlert($.CREATE_CHARGE_ERROR.title,$.CREATE_CHARGE_ERROR.message),this.sendFailureEmitter(500,e instanceof Error?e.message:`Error en servicio de criptomonedas`)}}async handleNakaTerminalFailure(e,t,n){this.stopNakaPolling(),this.iframe&&=(this.iframe.remove(),null),this.pendingAlert={title:e,message:t},await this.renderForm(),this.sendFailureEmitter(n,t)}startNakaPolling(e,t,n){this.stopNakaPolling();let r=Cn.getInstance(),i=0,a=Date.now();this.nakaPollingInterval=setInterval(async()=>{try{if(Date.now()-a>=18e5){await this.handleNakaTerminalFailure($.TIMEOUT.title,$.TIMEOUT.message,408);return}let o=await r.getChargeStatus(e);i=0;let s=o.data,c=s?.status;if(c===`SUCCESS`||c===`COMPLETED`||c===`PAID`){this.stopNakaPolling();let r={data:{id:e,status:`success`,amount_cents:t,amount_currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,response_code:`00`,authorization_number:s.authorization_number||s.transaction_id||`NAKA-${Date.now()}`,reference_number:s.reference_number||s.order_number||e,billing_document_number:n.billingDocumentNumber||``,description:n.description||this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:Tn,card_last_digits:En,invoice_serie:null}};this.sendSuccess(r);return}if(c===`CANCELED`||c===`CANCELLED`){await this.handleNakaTerminalFailure($.CANCELED.title,$.CANCELED.message,400);return}if(c===`EXPIRED`){await this.handleNakaTerminalFailure($.EXPIRED.title,$.EXPIRED.message,410);return}if(c===`FAILED`||c===`REJECTED`){await this.handleNakaTerminalFailure($.FAILED.title,$.FAILED.message,422);return}if(c===`OVERPAID`){this.isCryptoOverpaid=!0,this.lastCryptoOverpaidSuccess={data:{id:e,status:`success`,amount_cents:t,amount_currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,response_code:`00`,authorization_number:s.authorization_number||s.transaction_id||`NAKA-${Date.now()}`,reference_number:s.reference_number||s.order_number||e,billing_document_number:n.billingDocumentNumber||``,description:n.description||this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:Tn,card_last_digits:En,invoice_serie:null}},this.postMessageToIframe({type:`payment-form:crypto-overpaid`,label:$.OVERPAID.finishLabel});return}if(c===`PENDING`||c===`IN_PROGRESS`||c===`OPEN`||c===`UNDERPAID`)return}catch(e){if(e?.status===422){let t=e?.data?.error||$.PAYMENT_UNAVAILABLE.defaultMessage;await this.handleNakaTerminalFailure($.PAYMENT_UNAVAILABLE.title,t,422);return}if(e?.status===404){await this.handleNakaTerminalFailure($.ORDER_NOT_FOUND.title,$.ORDER_NOT_FOUND.message,404);return}if(e?.status===401||e?.status===403){await this.handleNakaTerminalFailure($.SESSION_EXPIRED.title,$.SESSION_EXPIRED.message,e.status);return}if(i++,i>=5){await this.handleNakaTerminalFailure($.CONNECTION_ERROR.title,$.CONNECTION_ERROR.message,500);return}}},wn)}stopNakaPolling(){this.nakaPollingInterval&&=(clearInterval(this.nakaPollingInterval),null)}destroy(){this.stopNakaPolling(),this.pendingAlert=null,this.currentCryptoChargeId=null,this.isCryptoOverpaid=!1,this.lastCryptoOverpaidSuccess=null,this.messageHandler&&=(window.removeEventListener(`message`,this.messageHandler),null),this.successListeners.clear(),this.failureListeners.clear(),this.readyListeners.clear(),this.sizingListeners.clear(),this.iframe&&=(this.iframe.remove(),null)}},Hn=`1.5.6`;exports.BizzPaymentForm=Vn,exports.VERSION=Hn;
package/dist/index.d.ts CHANGED
@@ -31,12 +31,15 @@ export declare class BizzPaymentForm {
31
31
  */
32
32
  on<E extends keyof PaymentFormEventMap>(event: E, listener: (data: PaymentFormEventMap[E]) => void): void;
33
33
  setup(): Promise<void>;
34
+ private setupMessageHandler;
34
35
  /**
35
36
  * When loading configuration by order (`paymentOrderCode`) or template (`paymentRequestCode`),
36
37
  * the amount is fixed from `amount_cents` and input is locked.
37
38
  */
38
39
  private applyFixedAmountFromOrderTemplate;
39
40
  private renderForm;
41
+ private renderCompletedOrderView;
42
+ private renderCancelledOrderView;
40
43
  private notifyCountriesLoadError;
41
44
  private postMessageToIframe;
42
45
  private resetForm;
@@ -35,6 +35,7 @@ Por favor revisa tu información e inténtalo de nuevo`)}buildConfirmPayload(e){
35
35
  min-height: 240px;
36
36
  height: 100%;
37
37
  width: 100%;
38
+ margin: 0 auto;
38
39
  box-sizing: border-box;
39
40
  padding: 48px 16px;
40
41
  gap: 16px;
@@ -194,7 +195,7 @@ Por favor revisa tu información e inténtalo de nuevo`,code:0},Qt=[{label:`Docu
194
195
  ${u}
195
196
  ${i?`\n <template class="operation-form-template" data-operation="crypto">${i}</template>`:``}
196
197
  </div>
197
- `}function Sn(e){let t=`<img src="${gn}" alt="Bizz Logo" class="bizz-logo">`,n=xn(e.cardFormHtml||``,e.submitButtonHtml,e.pointsFormHtml||``,e.installmentFormHtml||``,e.cryptoFormHtml||``);return mn.replace(`<!--STYLES-->`,`<style>${_n}</style>`).replace(`<!--BIZZ_LOGO-->`,t).replace(`<!--HEADER-->`,e.headerHtml).replace(`<!--OPERATION_SELECTION-->`,n).replace(`<!--VERSION-->`,`<div class="bizz-sdk-version">v1.5.5</div>`).replace(`<!--SCRIPT-->`,`<script>${hn}<\/script>`)}function Cn(e){let t=document.createElement(`iframe`);return t.style.border=`none`,t.style.display=`block`,t.style.overflow=`hidden`,t.srcdoc=e,t.style.width=`100%`,t.style.height=`100%`,t}var wn=class e{static instance;request;constructor(){this.request=yt.getInstance()}static getInstance(){return e.instance||=new e,e.instance}async createCharge(e){let t=await this.request.post(`external/online_payments/orders/crypto/charge`,e);if(!t.ok){let e=typeof t.json==`function`?await t.json().catch(()=>null):null,n=e?.error||e?.message||(typeof e==`object`&&e?JSON.stringify(e):null)||`Charge creation failed with status ${t.status}`,r=Error(n);throw r.status=t.status,r.data=e,r}return await t.json()}async getChargeStatus(e){let t=await this.request.get(`external/online_payments/orders/crypto/charge/${e}/status`);if(!t.ok){let e=typeof t.json==`function`?await t.json().catch(()=>null):null,n=e?.error||e?.message||(typeof e==`object`&&e?JSON.stringify(e):null)||`Charge status failed with status ${t.status}`,r=Error(n);throw r.status=t.status,r.data=e,r}return await t.json()}},Tn=3e3,En=`NAKA_CRYPTO`,Dn=`CRYPTO`,$={UNDERPAID:{title:`Pago incompleto`,message:`El monto pagado en criptomonedas fue inferior al total requerido. El cobro ha finalizado y tu reembolso ha sido gestionado a través de la pasarela.`,retryLabel:`Intentar nuevamente`},OVERPAID:{finishLabel:`Finalizar compra (Pago recibido)`},CANCELED:{title:`¡Pago cancelado!`,message:`El pago con criptomonedas fue cancelado.`},EXPIRED:{title:`¡Cobro expirado!`,message:`El tiempo para completar el pago con criptomonedas ha finalizado.`},FAILED:{title:`¡Pago fallido!`,message:`No se pudo procesar el pago con criptomonedas.`},TIMEOUT:{title:`¡Tiempo de espera agotado!`,message:`El tiempo para completar el pago con criptomonedas ha expirado.`},CONNECTION_ERROR:{title:`¡Error de conexión!`,message:`No fue posible verificar el estado del pago con criptomonedas.`},SESSION_EXPIRED:{title:`¡Sesión expirada!`,message:`Tu sesión ha expirado. Por favor, intenta de nuevo.`},ORDER_NOT_FOUND:{title:`¡Orden no encontrada!`,message:`El cobro no se encuentra disponible o fue cancelado.`},PAYMENT_UNAVAILABLE:{title:`¡Pago no disponible!`,defaultMessage:`No fue posible procesar el cobro con criptomonedas. Por favor, intenta con otro método.`},CREATE_CHARGE_ERROR:{title:`¡Error al crear cobro con Criptomonedas!`,message:`No se pudo conectar con el servicio de pagos en criptomonedas.`}},On=`<svg
198
+ `}function Sn(e){let t=`<img src="${gn}" alt="Bizz Logo" class="bizz-logo">`,n=e.customBodyHtml??xn(e.cardFormHtml||``,e.submitButtonHtml,e.pointsFormHtml||``,e.installmentFormHtml||``,e.cryptoFormHtml||``);return mn.replace(`<!--STYLES-->`,`<style>${_n}</style>`).replace(`<!--BIZZ_LOGO-->`,t).replace(`<!--HEADER-->`,e.headerHtml).replace(`<!--OPERATION_SELECTION-->`,n).replace(`<!--VERSION-->`,`<div class="bizz-sdk-version">v1.5.6</div>`).replace(`<!--SCRIPT-->`,`<script>${hn}<\/script>`)}function Cn(e){let t=document.createElement(`iframe`);return t.style.border=`none`,t.style.display=`block`,t.style.overflow=`hidden`,t.srcdoc=e,t.style.width=`100%`,t.style.height=`100%`,t}var wn=class e{static instance;request;constructor(){this.request=yt.getInstance()}static getInstance(){return e.instance||=new e,e.instance}async createCharge(e){let t=await this.request.post(`external/online_payments/orders/crypto/charge`,e);if(!t.ok){let e=typeof t.json==`function`?await t.json().catch(()=>null):null,n=e?.error||e?.message||(typeof e==`object`&&e?JSON.stringify(e):null)||`Charge creation failed with status ${t.status}`,r=Error(n);throw r.status=t.status,r.data=e,r}return await t.json()}async getChargeStatus(e){let t=await this.request.get(`external/online_payments/orders/crypto/charge/${e}/status`);if(!t.ok){let e=typeof t.json==`function`?await t.json().catch(()=>null):null,n=e?.error||e?.message||(typeof e==`object`&&e?JSON.stringify(e):null)||`Charge status failed with status ${t.status}`,r=Error(n);throw r.status=t.status,r.data=e,r}return await t.json()}},Tn=3e3,En=`NAKA_CRYPTO`,Dn=`CRYPTO`,$={UNDERPAID:{title:`Pago incompleto`,message:`El monto pagado en criptomonedas fue inferior al total requerido. El cobro ha finalizado y tu reembolso ha sido gestionado a través de la pasarela.`,retryLabel:`Intentar nuevamente`},OVERPAID:{finishLabel:`Finalizar compra (Pago recibido)`},CANCELED:{title:`¡Pago cancelado!`,message:`El pago con criptomonedas fue cancelado.`},EXPIRED:{title:`¡Cobro expirado!`,message:`El tiempo para completar el pago con criptomonedas ha finalizado.`},FAILED:{title:`¡Pago fallido!`,message:`No se pudo procesar el pago con criptomonedas.`},TIMEOUT:{title:`¡Tiempo de espera agotado!`,message:`El tiempo para completar el pago con criptomonedas ha expirado.`},CONNECTION_ERROR:{title:`¡Error de conexión!`,message:`No fue posible verificar el estado del pago con criptomonedas.`},SESSION_EXPIRED:{title:`¡Sesión expirada!`,message:`Tu sesión ha expirado. Por favor, intenta de nuevo.`},ORDER_NOT_FOUND:{title:`¡Orden no encontrada!`,message:`El cobro no se encuentra disponible o fue cancelado.`},PAYMENT_UNAVAILABLE:{title:`¡Pago no disponible!`,defaultMessage:`No fue posible procesar el cobro con criptomonedas. Por favor, intenta con otro método.`},CREATE_CHARGE_ERROR:{title:`¡Error al crear cobro con Criptomonedas!`,message:`No se pudo conectar con el servicio de pagos en criptomonedas.`}},On=`<svg
198
199
  xmlns="http://www.w3.org/2000/svg"
199
200
  width="24"
200
201
  height="24"
@@ -261,4 +262,31 @@ Por favor revisa tu información e inténtalo de nuevo`,code:0},Qt=[{label:`Docu
261
262
  <path d="M12 3a12 12 0 0 0 8.5 3a12 12 0 0 1 -8.5 15a12 12 0 0 1 -8.5 -15a12 12 0 0 0 8.5 -3" />
262
263
  <path d="M11 11a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
263
264
  <path d="M12 12l0 2.5" />
264
- </svg>`,Mn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-mail"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 7a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10" /><path d="M3 7l9 6l9 -6" /></svg>`,Nn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-user"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0" /><path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" /></svg>`,Pn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-message-circle"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 20l1.3 -3.9c-2.324 -3.437 -1.426 -7.872 2.1 -10.374c3.526 -2.501 8.59 -2.296 11.845 .48c3.255 2.777 3.695 7.266 1.029 10.501c-2.666 3.235 -7.615 4.215 -11.574 2.293l-4.7 1" /></svg>`,Fn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-id"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 7a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v10a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3l0 -10" /><path d="M7 10a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" /><path d="M15 8l2 0" /><path d="M15 12l2 0" /><path d="M7 16l10 0" /></svg>`,In=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-device-mobile"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 5a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-14" /><path d="M11 4h2" /><path d="M12 17v.01" /></svg>`,Ln=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-map-pin"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 11a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" /><path d="M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0" /></svg>`,Rn={"currency-dollar":On,"credit-card":kn,calendar:An,"shield-lock":jn,email:Mn,user:Nn,description:Pn,document:Fn,phone:In,"map-pin":Ln};function zn(e){let t=Rn[e];if(!t)throw Error(`Icon "${e}" not found`);return t}var Bn=class e{static instance;currentDate=new Date;currentYear=this.currentDate.getFullYear();currentMonth=this.currentDate.getMonth()+1;static getInstance(){return e.instance||=new e,e.instance}validateField(e,t){return this.inputRequired(t)||({amount:e=>this.amountInput(e),cardNumber:e=>this.cardNumberInput(e),cardExpiry:e=>this.cardExpiryInput(e),cardCvc:e=>this.cardCvcInput(e),email:e=>this.emailInput(e)}[e]?.(t)??``)}inputRequired(e){return e.trim()===``?`Este campo es requerido`:``}amountInput(e){return Number(e)<=0?`El monto debe ser mayor a 0`:``}cardNumberInput(e){let t=e.replace(/\s/g,``);return/^[0-9]{16}$/.test(t)?At(t)===`not_valid`?`Por favor ingrese una tarjeta visa, mastercard o union_pay`:``:`Por favor, ingrese un número de tarjeta válido`}cardExpiryInput(e){let[t,n]=e.split(`/`),r=Number(this.currentYear.toString().slice(-2));return Number(n)<r?`El año de expiración no puede ser anterior al año actual`:Number(t)<1||Number(t)>12?`El mes de expiración debe estar entre 01 y 12`:Number(n)===r&&Number(t)<this.currentMonth?`La tarjeta está expirada`:``}emailInput(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?``:`Por favor, ingrese un email válido`}cardCvcInput(e){return/^[0-9]{3,4}$/.test(e)?``:`Por favor, ingrese un código de seguridad válido`}},Vn=(e,t,n,r)=>Object.keys(t).map(i=>{let a=t[i],o=e.get(i);return{name:i,label:o?.label??a.label,placeholder:o?.placeholder??a.placeholder??a.label,iconSvg:zn(a.icon),mask:a.mask,divider:a.divider,type:a.type??`text`,options:a.type===`select`?a.options:void 0,default:a.default,amountValue:n?Ht(n/100,`USD`,`decimal`):void 0,disabled:i===`amount`?r:!1,autocomplete:a.autocomplete}});return e.BizzPaymentForm=class{static version=`1.5.5`;config;iframe=null;messageHandler=null;successListeners=new Set;failureListeners=new Set;readyListeners=new Set;sizingListeners=new Set;validation=Bn.getInstance();origin=d;serverErrorHandler;orchestrator=Et.getInstance();paymentIntent=Jt.getInstance();points=Yt.getInstance();countryContent=Ot.getInstance();processPayment=It.getInstance();stateContent=kt.getInstance();amountEvaluation=Wt.getInstance();currentAmount;currentValues={};pointsPaymentContext=null;nakaPollingInterval=null;pendingAlert=null;currentCryptoChargeId=null;isCryptoOverpaid=!1;lastCryptoOverpaidSuccess=null;constructor(e){if(this.config={...e},!this.config.paymentOrderCode&&typeof window<`u`&&window.location?.search){let e=new URLSearchParams(window.location.search).get(`o`);e&&(this.config.paymentOrderCode=e)}if(!this.config.paymentRequestCode&&typeof window<`u`&&window.location?.search){let e=new URLSearchParams(window.location.search).get(`t`);e&&(this.config.paymentRequestCode=e)}this.currentAmount=this.config.totalAmount,this.serverErrorHandler=new qt(this.origin)}on(e,t){e===`success`?this.successListeners.add(t):e===`failure`?this.failureListeners.add(t):e===`ready`?this.readyListeners.add(t):e===`sizing`&&this.sizingListeners.add(t)}async setup(){let e=document.querySelector(this.config.iframeTarget);if(!e)throw Error(`Element not found: ${this.config.iframeTarget}`);let t=Bt(this.config.i18n?.loading);e.appendChild(t);try{await this.orchestrator.initialize({branchCode:this.config.branchCode,paymentRequestCode:this.config.paymentRequestCode,paymentOrderCode:this.config.paymentOrderCode,environment:this.config.environment})}catch(n){t.remove();let r=document.createElement(`div`);r.style.cssText=`font-family:Poppins,sans-serif;text-align:center;padding:32px;color:#DB3339;font-size:14px;`,r.textContent=n instanceof Error?n.message:`Pago no procesado`,e.appendChild(r);return}if(t.remove(),this.applyFixedAmountFromOrderTemplate(),await this.renderForm(),this.messageHandler=async e=>{if(e.source&&e.source!==this.iframe?.contentWindow&&e.source!==window)return;let t=e.data;if(t?.type){if(t.type===`payment-form:ready`&&(this.pendingAlert&&=(this.sendAlert(this.pendingAlert.title,this.pendingAlert.message),null)),t.type===`payment-form:states-loaded`&&this.stateContent.setStates(t.states),t.type===`payment-form:sizing`&&(this.iframe&&(this.iframe.style.height=`${t.height}px`),this.sendSizingEmitter(t.width,t.height)),t.type===`payment-form:validate-amount`){this.currentAmount=Ut(t.amount),this.setSubmitLoading(!0);let e=await this.amountEvaluation.validateAmount(t.amount,t.force);if(this.setSubmitLoading(!1),e&&`data`in e){let t=this.orchestrator.getConfig();t.data.secure_mode!==e.data.secure_mode&&(t.data.secure_mode=e.data.secure_mode,await this.renderForm())}}if(t.type===`payment-form:validate`){this.currentValues[t.field]=t.value;let e=this.validation.validateField(t.field,t.value);this.iframe?.contentWindow?.postMessage({type:`payment-form:validation-result`,field:t.field,error:e},this.origin)}if(t.type===`payment-form:submit`){t.value.amount&&(this.currentAmount=Ut(t.value.amount));let e=!1,n=Object.keys(t.value);for(let r of n){let n=this.validation.validateField(r,t.value[r]??``);n&&(e=!0,this.iframe?.contentWindow?.postMessage({type:`payment-form:validation-result`,field:r,error:n},this.origin))}if(!e){if(this.setSubmitLoading(!0),t.value.operation===`crypto`){await this.handleCryptoPayment(t.value);return}if(t.value.operation===`points`){await this.handlePointsBalance(t.value),this.setSubmitLoading(!1);return}if(this.orchestrator.getConfig().data.secure_mode){try{await this.processPayment.process(t.value,this.config.totalAmount,{sendAlert:(e,t)=>this.sendAlert(e,t),sendSuccess:e=>this.sendSuccess(e),resetForm:()=>this.resetForm()})}catch{let e=`No pudimos obtener información de encriptación`;this.sendAlert(`¡Error al encriptar tus datos!`,e),this.sendFailureEmitter(0,e)}finally{this.setSubmitLoading(!1)}return}let e=await this.paymentIntent.generatePaymentIntentPayload(t.value).catch(e=>{this.setSubmitLoading(!1),this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`)});if(!e)return;this.config.totalAmount&&(e.subtotal_cents=this.config.totalAmount),t.value.operation===`installments`&&(e.months=t.value.installments);let n=await this.paymentIntent.createPaymentIntent(e);if(this.setSubmitLoading(!1),`error`in n&&`code`in n){if(n.status===422&&this.serverErrorHandler.hasEncryptionPayloadErrors(n.error)){let e=`Error al encriptar tus datos.`;this.sendAlert(`¡Error al encriptar tus datos!`,e),this.sendFailureEmitter(n.status,e);return}if(n.status===422&&this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow,n.error)){this.sendFailureEmitter(n.status,`Por favor, revisa los campos`);return}n.code===`inactive_company_commerce`?this.sendAlert(`¡Comercio inactivo!`,`Tu compra no pudo ser procesada! El comercio no está disponible por el momento`):n.code===`payment_limit_exceeded`?this.sendAlert(`¡Límite de pago excedido!`,`Por favor, contacta al comercio.`):n.status===422?this.sendAlert(`¡Revisa la información!`,`Por favor, revisa los campos`):this.sendAlert(`¡Error al procesar el pago!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.sendFailureEmitter(n.status,this.serverErrorHandler.resolveServerErrorMessage(n.error));return}if(n.data.status!==`success`){let e=Zt(n.data.response_code??``);this.sendAlert(e.title,e.message),this.sendFailureEmitter(0,e.message);return}if(n.data.status===`success`){this.sendSuccess(n),this.resetForm();return}}}if(t.type===`payment-form:points-pay`&&await this.processPointsPayment(),t.type===`payment-form:load-crypto-countries`){this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let e=this.countryContent.getCountries(),t={...rn,country:{...rn.country,options:[{label:`Selecciona aquí`,value:``},...e.map(e=>({label:e.name,value:e.alpha2||e.id}))]}},n=new Map((this.config.i18n?.fields??[]).map(e=>[e.name,e])),r=!!this.config.totalAmount,i=pn(Vn(n,t,this.currentAmount,r));this.iframe?.contentWindow?.postMessage({type:`payment-form:update-forms`,forms:{crypto:i}},this.origin)}if(t.type===`payment-form:naka-callback`){this.stopNakaPolling();let e=t.chargeId||this.currentCryptoChargeId,n=wn.getInstance(),r=t.status,i=null;if(e)try{let t=await n.getChargeStatus(e);t?.data&&(i=t.data,r=i.status)}catch(e){if(e?.status===422){let t=e?.data?.error||$.PAYMENT_UNAVAILABLE.defaultMessage;await this.handleNakaTerminalFailure($.PAYMENT_UNAVAILABLE.title,t,422);return}if(e?.status===404){await this.handleNakaTerminalFailure($.ORDER_NOT_FOUND.title,$.ORDER_NOT_FOUND.message,404);return}await this.handleNakaTerminalFailure($.CONNECTION_ERROR.title,$.CONNECTION_ERROR.message,500);return}if(r===`UNDERPAID`){this.stopNakaPolling(),this.postMessageToIframe({type:`payment-form:crypto-incomplete`,title:$.UNDERPAID.title,message:$.UNDERPAID.message,retryLabel:$.UNDERPAID.retryLabel}),this.sendFailureEmitter(422,$.UNDERPAID.message);return}if(r===`CANCELED`||r===`CANCELLED`){await this.handleNakaTerminalFailure($.CANCELED.title,$.CANCELED.message,400);return}if(r===`EXPIRED`){await this.handleNakaTerminalFailure($.EXPIRED.title,$.EXPIRED.message,410);return}if(r===`FAILED`||r===`REJECTED`){await this.handleNakaTerminalFailure($.FAILED.title,$.FAILED.message,422);return}if(r===`SUCCESS`||r===`COMPLETED`||r===`PAID`||r===`OVERPAID`){let n=this.orchestrator.getConfig()?.data?.amount_currency||`USD`,r={data:{id:e||``,status:`success`,amount_cents:this.config.totalAmount??this.currentAmount??i?.amount_cents??0,amount_currency:n,response_code:`00`,authorization_number:i?.authorization_number||i?.transaction_id||t.chargeId||`NAKA-${Date.now()}`,reference_number:i?.reference_number||i?.order_number||t.orderNumber||e||``,billing_document_number:``,description:this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:En,card_last_digits:Dn,invoice_serie:null}};this.sendSuccess(r);return}}if(t.type===`payment-form:return-initial`){if(this.stopNakaPolling(),this.isCryptoOverpaid&&this.lastCryptoOverpaidSuccess){this.sendSuccess(this.lastCryptoOverpaidSuccess);return}this.iframe&&=(this.iframe.remove(),null),await this.renderForm();return}if(t.type===`payment-form:crypto-retry`){this.stopNakaPolling(),this.iframe&&=(this.iframe.remove(),null),await this.renderForm();return}}},window.addEventListener(`message`,this.messageHandler),this.config.totalAmount&&Number(this.config.totalAmount)>0)try{this.setSubmitLoading(!0);let e=await this.amountEvaluation.validateAmount(this.config.totalAmount.toString());if(this.setSubmitLoading(!1),e&&`data`in e){let t=this.orchestrator.getConfig();t.data.secure_mode!==e.data.secure_mode&&(t.data.secure_mode=e.data.secure_mode,await this.renderForm())}}catch{this.setSubmitLoading(!1),this.sendAlert(`¡Error al validar el monto!`,`Asegúrate de que el monto a pagar sea válido`)}}applyFixedAmountFromOrderTemplate(){let e=this.orchestrator.getConfig();if(!e?.data)return;let{data:t}=e;if(t.order_template_id==null&&t.order_id==null||typeof t.amount_cents!=`number`||t.amount_cents<=0)return;let n=Ht(t.amount_cents/100,t.amount_currency||`USD`,`decimal`);this.config.description=t.description,this.config.totalAmount=Ut(n),this.currentAmount=Ut(n)}async renderForm(){let e=document.querySelector(this.config.iframeTarget);if(!e)return;let t=new Map((this.config.i18n?.fields??[]).map(e=>[e.name,e])),n=this.orchestrator.getConfig().data.secure_mode,r=this.orchestrator.getConfig().data.payment_methods,i=r.includes(`emv`),a=r.includes(`ba_puntos`),o=r.includes(`ba_plazos`),s=r.includes(`crypto`);n&&this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let c=this.countryContent.getCountries(),l=n?{...nn,country:{...nn.country,options:[{label:`Selecciona aquí`,value:``},...c.map(e=>({label:e.name,value:e.id}))]}}:tn,u=tn,d=!!this.config.totalAmount,f=Vn(t,l,this.currentAmount,d),p=n?Vn(t,u,this.currentAmount,d):f,m=Vn(t,{...rn,country:{...rn.country,options:[{label:`Selecciona aquí`,value:``},...c.map(e=>({label:e.name,value:e.alpha2||e.id}))]}},this.currentAmount,d);[f,p,m].forEach(e=>{e.forEach(e=>{this.currentValues[e.name]!==void 0&&e.name!==`amount`&&(e.default=this.currentValues[e.name])})});let h=an(this.config.i18n?.submitButton),g=i?un(f):``,_=a?dn(p):``,v=o?fn(p,h):``,y=s?pn(m):``;if(this.iframe){this.iframe.contentWindow?.postMessage({type:`payment-form:update-forms`,forms:{default:g+h,points:_,installments:v,crypto:y}},this.origin),this.notifyCountriesLoadError();return}let b=this.config.totalAmount?Ht(this.config.totalAmount/100,`USD`,`decimal`):``;this.iframe=Cn(Sn({headerHtml:on({logo:this.orchestrator.getConfig().data.logo_url,name:this.orchestrator.getConfig().data.name,description:this.config.description,header:this.config.header,totalAmount:b,...b?{icon:zn(`currency-dollar`)}:{}}),cardFormHtml:g,submitButtonHtml:h,pointsFormHtml:_,installmentFormHtml:v,cryptoFormHtml:y})),e.appendChild(this.iframe),this.iframe.addEventListener(`load`,()=>{this.setToken(this.orchestrator.getAuthToken().access_token),this.notifyCountriesLoadError(),this.sendReadyEmitter()})}notifyCountriesLoadError(){let e=this.countryContent.getCountriesLoadError();e&&this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow,{country:[e]})}postMessageToIframe(e){try{this.iframe?.contentWindow?.postMessage(e,this.origin)}catch{try{this.iframe?.contentWindow?.postMessage(e,`*`)}catch{}}}resetForm(){this.postMessageToIframe({type:`payment-form:reset`})}setSubmitLoading(e){this.postMessageToIframe({type:`payment-form:set-submit-loading`,disabled:e})}setToken(e){this.postMessageToIframe({type:`payment-form:set-token`,token:e})}sendAlert(e,t){this.postMessageToIframe({type:`payment-form:alert`,title:e,message:t})}sendFailureEmitter(e,t){for(let n of this.failureListeners)n({status:e,message:t})}async processPointsPayment(){if(!this.pointsPaymentContext)return;let{value:e,points:t}=this.pointsPaymentContext,n;try{n=await this.paymentIntent.generatePaymentIntentPayload(e)}catch{this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.resetPointsPayButton();return}n.operation=`points`,n.points=t.toString(),this.config.totalAmount&&(n.subtotal_cents=this.config.totalAmount);let r=await this.paymentIntent.createPaymentIntent(n);if(`error`in r&&`code`in r){this.sendAlert(`¡Error al procesar el pago!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.sendFailureEmitter(r.status,this.serverErrorHandler.resolveServerErrorMessage(r.error)),this.resetPointsPayButton();return}if(r.data.status!==`success`){let e=Zt(r.data.response_code??``);this.sendAlert(e.title,e.message),this.sendFailureEmitter(0,e.message),this.resetPointsPayButton();return}this.sendSuccess(r)}resetPointsPayButton(){this.iframe?.contentWindow?.postMessage({type:`payment-form:points-pay-reset`},this.origin)}async handlePointsBalance(e){let t;try{t=await this.points.generatePayload(e)}catch{this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`);return}let n=await this.points.getPointsBalance(t).catch(()=>null);if(!n||`error`in n||n.data.in_dollar_cents<=0){this.sendAlert(`¡Error al consultar tus puntos!`,`Por favor, intenta nuevamente, o contacta al comercio.`);return}let r=this.config.totalAmount??this.currentAmount??Ut(e.amount),i=Math.round(r*n.data.points/n.data.in_dollar_cents);this.pointsPaymentContext={value:e,points:i},this.iframe?.contentWindow?.postMessage({type:`payment-form:points-balance`,balance:{availableCents:n.data.in_dollar_cents,availablePoints:n.data.points,currency:n.data.in_dollar_currency,purchaseCents:r,purchasePoints:i},formValues:e},this.origin)}sendReadyEmitter(){for(let e of this.readyListeners)e()}sendSizingEmitter(e,t){for(let n of this.sizingListeners)n({width:e,height:t})}sendSuccess(e){this.config.totalAmount&&(e.data.amount_cents=this.config.totalAmount),this.postMessageToIframe({type:`payment-form:success`,paymentIntent:e});let{id:t,status:n,amount_cents:r,response_code:i,authorization_number:a,reference_number:o}=e.data,s={id:t,status:n,amount_cents:r,response_code:i,authorization_number:a,reference_number:o};for(let e of this.successListeners)e(s)}async handleCryptoPayment(e){this.setSubmitLoading(!0);let t=wn.getInstance(),n=this.config.totalAmount??this.currentAmount??Ut(e.amount||`0`);this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let r=e.country||``,i=this.countryContent.getCountries().find(e=>e.id===r||e.alpha2===r||e.name===r)?.alpha2||(r.length===2?r.toUpperCase():void 0),a={data:{branch_id:this.orchestrator.getConfig()?.data?.branch_id||this.config.branchCode,amount_cents:n,currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,description:e.description||this.config.description||`Pago con Criptomonedas`,billing_document_number:e.billingDocumentNumber||``,redirect_url:this.config.redirectUrl||(typeof window<`u`?`${window.location.origin}/paylink/crypto/callback`:void 0),kyc:{email:e.email||``,first_name:e.firstName||``,last_name:e.lastName||``,country:i||``,phone:e.phone||void 0,phone_number:e.phone||void 0,nationality:e.nationality?.toUpperCase()||i||void 0,city:e.city||void 0,postal_code:e.postalCode||void 0,zip_code:e.postalCode||e.zipCode||void 0,address:e.address||void 0}}};try{let r=await t.createCharge(a);this.currentCryptoChargeId=r.data.charge_id,this.setSubmitLoading(!1),this.postMessageToIframe({type:`payment-form:naka-checkout`,redirectUrl:r.data.redirect_url,chargeId:r.data.charge_id}),this.startNakaPolling(r.data.charge_id,n,e)}catch(e){this.setSubmitLoading(!1),this.sendAlert($.CREATE_CHARGE_ERROR.title,$.CREATE_CHARGE_ERROR.message),this.sendFailureEmitter(500,e instanceof Error?e.message:`Error en servicio de criptomonedas`)}}async handleNakaTerminalFailure(e,t,n){this.stopNakaPolling(),this.iframe&&=(this.iframe.remove(),null),this.pendingAlert={title:e,message:t},await this.renderForm(),this.sendFailureEmitter(n,t)}startNakaPolling(e,t,n){this.stopNakaPolling();let r=wn.getInstance(),i=0,a=Date.now();this.nakaPollingInterval=setInterval(async()=>{try{if(Date.now()-a>=18e5){await this.handleNakaTerminalFailure($.TIMEOUT.title,$.TIMEOUT.message,408);return}let o=await r.getChargeStatus(e);i=0;let s=o.data,c=s?.status;if(c===`SUCCESS`||c===`COMPLETED`||c===`PAID`){this.stopNakaPolling();let r={data:{id:e,status:`success`,amount_cents:t,amount_currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,response_code:`00`,authorization_number:s.authorization_number||s.transaction_id||`NAKA-${Date.now()}`,reference_number:s.reference_number||s.order_number||e,billing_document_number:n.billingDocumentNumber||``,description:n.description||this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:En,card_last_digits:Dn,invoice_serie:null}};this.sendSuccess(r);return}if(c===`CANCELED`||c===`CANCELLED`){await this.handleNakaTerminalFailure($.CANCELED.title,$.CANCELED.message,400);return}if(c===`EXPIRED`){await this.handleNakaTerminalFailure($.EXPIRED.title,$.EXPIRED.message,410);return}if(c===`FAILED`||c===`REJECTED`){await this.handleNakaTerminalFailure($.FAILED.title,$.FAILED.message,422);return}if(c===`OVERPAID`){this.isCryptoOverpaid=!0,this.lastCryptoOverpaidSuccess={data:{id:e,status:`success`,amount_cents:t,amount_currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,response_code:`00`,authorization_number:s.authorization_number||s.transaction_id||`NAKA-${Date.now()}`,reference_number:s.reference_number||s.order_number||e,billing_document_number:n.billingDocumentNumber||``,description:n.description||this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:En,card_last_digits:Dn,invoice_serie:null}},this.postMessageToIframe({type:`payment-form:crypto-overpaid`,label:$.OVERPAID.finishLabel});return}if(c===`PENDING`||c===`IN_PROGRESS`||c===`OPEN`||c===`UNDERPAID`)return}catch(e){if(e?.status===422){let t=e?.data?.error||$.PAYMENT_UNAVAILABLE.defaultMessage;await this.handleNakaTerminalFailure($.PAYMENT_UNAVAILABLE.title,t,422);return}if(e?.status===404){await this.handleNakaTerminalFailure($.ORDER_NOT_FOUND.title,$.ORDER_NOT_FOUND.message,404);return}if(e?.status===401||e?.status===403){await this.handleNakaTerminalFailure($.SESSION_EXPIRED.title,$.SESSION_EXPIRED.message,e.status);return}if(i++,i>=5){await this.handleNakaTerminalFailure($.CONNECTION_ERROR.title,$.CONNECTION_ERROR.message,500);return}}},Tn)}stopNakaPolling(){this.nakaPollingInterval&&=(clearInterval(this.nakaPollingInterval),null)}destroy(){this.stopNakaPolling(),this.pendingAlert=null,this.currentCryptoChargeId=null,this.isCryptoOverpaid=!1,this.lastCryptoOverpaidSuccess=null,this.messageHandler&&=(window.removeEventListener(`message`,this.messageHandler),null),this.successListeners.clear(),this.failureListeners.clear(),this.readyListeners.clear(),this.sizingListeners.clear(),this.iframe&&=(this.iframe.remove(),null)}},e.VERSION=`1.5.5`,e})({});
265
+ </svg>`,Mn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-mail"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 7a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10" /><path d="M3 7l9 6l9 -6" /></svg>`,Nn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-user"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0" /><path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" /></svg>`,Pn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-message-circle"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 20l1.3 -3.9c-2.324 -3.437 -1.426 -7.872 2.1 -10.374c3.526 -2.501 8.59 -2.296 11.845 .48c3.255 2.777 3.695 7.266 1.029 10.501c-2.666 3.235 -7.615 4.215 -11.574 2.293l-4.7 1" /></svg>`,Fn=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-id"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 7a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v10a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3l0 -10" /><path d="M7 10a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" /><path d="M15 8l2 0" /><path d="M15 12l2 0" /><path d="M7 16l10 0" /></svg>`,In=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-device-mobile"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 5a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-14" /><path d="M11 4h2" /><path d="M12 17v.01" /></svg>`,Ln=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-map-pin"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 11a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" /><path d="M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0" /></svg>`,Rn={"currency-dollar":On,"credit-card":kn,calendar:An,"shield-lock":jn,email:Mn,user:Nn,description:Pn,document:Fn,phone:In,"map-pin":Ln};function zn(e){let t=Rn[e];if(!t)throw Error(`Icon "${e}" not found`);return t}var Bn=class e{static instance;currentDate=new Date;currentYear=this.currentDate.getFullYear();currentMonth=this.currentDate.getMonth()+1;static getInstance(){return e.instance||=new e,e.instance}validateField(e,t){return this.inputRequired(t)||({amount:e=>this.amountInput(e),cardNumber:e=>this.cardNumberInput(e),cardExpiry:e=>this.cardExpiryInput(e),cardCvc:e=>this.cardCvcInput(e),email:e=>this.emailInput(e)}[e]?.(t)??``)}inputRequired(e){return e.trim()===``?`Este campo es requerido`:``}amountInput(e){return Number(e)<=0?`El monto debe ser mayor a 0`:``}cardNumberInput(e){let t=e.replace(/\s/g,``);return/^[0-9]{16}$/.test(t)?At(t)===`not_valid`?`Por favor ingrese una tarjeta visa, mastercard o union_pay`:``:`Por favor, ingrese un número de tarjeta válido`}cardExpiryInput(e){let[t,n]=e.split(`/`),r=Number(this.currentYear.toString().slice(-2));return Number(n)<r?`El año de expiración no puede ser anterior al año actual`:Number(t)<1||Number(t)>12?`El mes de expiración debe estar entre 01 y 12`:Number(n)===r&&Number(t)<this.currentMonth?`La tarjeta está expirada`:``}emailInput(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?``:`Por favor, ingrese un email válido`}cardCvcInput(e){return/^[0-9]{3,4}$/.test(e)?``:`Por favor, ingrese un código de seguridad válido`}},Vn=(e,t,n,r)=>Object.keys(t).map(i=>{let a=t[i],o=e.get(i);return{name:i,label:o?.label??a.label,placeholder:o?.placeholder??a.placeholder??a.label,iconSvg:zn(a.icon),mask:a.mask,divider:a.divider,type:a.type??`text`,options:a.type===`select`?a.options:void 0,default:a.default,amountValue:n?Ht(n/100,`USD`,`decimal`):void 0,disabled:i===`amount`?r:!1,autocomplete:a.autocomplete}});return e.BizzPaymentForm=class{static version=`1.5.6`;config;iframe=null;messageHandler=null;successListeners=new Set;failureListeners=new Set;readyListeners=new Set;sizingListeners=new Set;validation=Bn.getInstance();origin=d;serverErrorHandler;orchestrator=Et.getInstance();paymentIntent=Jt.getInstance();points=Yt.getInstance();countryContent=Ot.getInstance();processPayment=It.getInstance();stateContent=kt.getInstance();amountEvaluation=Wt.getInstance();currentAmount;currentValues={};pointsPaymentContext=null;nakaPollingInterval=null;pendingAlert=null;currentCryptoChargeId=null;isCryptoOverpaid=!1;lastCryptoOverpaidSuccess=null;constructor(e){if(this.config={...e},!this.config.paymentOrderCode&&typeof window<`u`&&window.location?.search){let e=new URLSearchParams(window.location.search).get(`o`);e&&(this.config.paymentOrderCode=e)}if(!this.config.paymentRequestCode&&typeof window<`u`&&window.location?.search){let e=new URLSearchParams(window.location.search).get(`t`);e&&(this.config.paymentRequestCode=e)}this.currentAmount=this.config.totalAmount,this.serverErrorHandler=new qt(this.origin)}on(e,t){e===`success`?this.successListeners.add(t):e===`failure`?this.failureListeners.add(t):e===`ready`?this.readyListeners.add(t):e===`sizing`&&this.sizingListeners.add(t)}async setup(){let e=document.querySelector(this.config.iframeTarget);if(!e)throw Error(`Element not found: ${this.config.iframeTarget}`);let t=Bt(this.config.i18n?.loading);e.appendChild(t);try{await this.orchestrator.initialize({branchCode:this.config.branchCode,paymentRequestCode:this.config.paymentRequestCode,paymentOrderCode:this.config.paymentOrderCode,environment:this.config.environment})}catch(n){t.remove();let r=document.createElement(`div`);r.style.cssText=`font-family:Poppins,sans-serif;text-align:center;padding:32px;color:#DB3339;font-size:14px;`,r.textContent=n instanceof Error?n.message:`Pago no procesado`,e.appendChild(r);return}t.remove(),this.setupMessageHandler();let n=this.orchestrator.getConfig()?.data?.status;if(n===`completed`){await this.renderCompletedOrderView();return}if(n===`cancelled`){await this.renderCancelledOrderView();return}if(this.applyFixedAmountFromOrderTemplate(),await this.renderForm(),this.config.totalAmount&&Number(this.config.totalAmount)>0)try{this.setSubmitLoading(!0);let e=await this.amountEvaluation.validateAmount(this.config.totalAmount.toString());if(this.setSubmitLoading(!1),e&&`data`in e){let t=this.orchestrator.getConfig();t.data.secure_mode!==e.data.secure_mode&&(t.data.secure_mode=e.data.secure_mode,await this.renderForm())}}catch{this.setSubmitLoading(!1),this.sendAlert(`¡Error al validar el monto!`,`Asegúrate de que el monto a pagar sea válido`)}}setupMessageHandler(){this.messageHandler&&window.removeEventListener(`message`,this.messageHandler),this.messageHandler=async e=>{if(e.source&&e.source!==this.iframe?.contentWindow&&e.source!==window)return;let t=e.data;if(t?.type){if(t.type===`payment-form:ready`&&(this.pendingAlert&&=(this.sendAlert(this.pendingAlert.title,this.pendingAlert.message),null)),t.type===`payment-form:states-loaded`&&this.stateContent.setStates(t.states),t.type===`payment-form:sizing`&&(this.iframe&&(this.iframe.style.height=`${t.height}px`),this.sendSizingEmitter(t.width,t.height)),t.type===`payment-form:validate-amount`){this.currentAmount=Ut(t.amount),this.setSubmitLoading(!0);let e=await this.amountEvaluation.validateAmount(t.amount,t.force);if(this.setSubmitLoading(!1),e&&`data`in e){let t=this.orchestrator.getConfig();t.data.secure_mode!==e.data.secure_mode&&(t.data.secure_mode=e.data.secure_mode,await this.renderForm())}}if(t.type===`payment-form:validate`){this.currentValues[t.field]=t.value;let e=this.validation.validateField(t.field,t.value);this.iframe?.contentWindow?.postMessage({type:`payment-form:validation-result`,field:t.field,error:e},this.origin)}if(t.type===`payment-form:submit`){t.value.amount&&(this.currentAmount=Ut(t.value.amount));let e=!1,n=Object.keys(t.value);for(let r of n){let n=this.validation.validateField(r,t.value[r]??``);n&&(e=!0,this.iframe?.contentWindow?.postMessage({type:`payment-form:validation-result`,field:r,error:n},this.origin))}if(!e){if(this.setSubmitLoading(!0),t.value.operation===`crypto`){await this.handleCryptoPayment(t.value);return}if(t.value.operation===`points`){await this.handlePointsBalance(t.value),this.setSubmitLoading(!1);return}if(this.orchestrator.getConfig().data.secure_mode){try{await this.processPayment.process(t.value,this.config.totalAmount,{sendAlert:(e,t)=>this.sendAlert(e,t),sendSuccess:e=>this.sendSuccess(e),resetForm:()=>this.resetForm()})}catch{let e=`No pudimos obtener información de encriptación`;this.sendAlert(`¡Error al encriptar tus datos!`,e),this.sendFailureEmitter(0,e)}finally{this.setSubmitLoading(!1)}return}let e=await this.paymentIntent.generatePaymentIntentPayload(t.value).catch(e=>{this.setSubmitLoading(!1),this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`)});if(!e)return;this.config.totalAmount&&(e.subtotal_cents=this.config.totalAmount),t.value.operation===`installments`&&(e.months=t.value.installments);let n=await this.paymentIntent.createPaymentIntent(e);if(this.setSubmitLoading(!1),`error`in n&&`code`in n){if(n.status===422&&this.serverErrorHandler.hasEncryptionPayloadErrors(n.error)){let e=`Error al encriptar tus datos.`;this.sendAlert(`¡Error al encriptar tus datos!`,e),this.sendFailureEmitter(n.status,e);return}if(n.status===422&&this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow,n.error)){this.sendFailureEmitter(n.status,`Por favor, revisa los campos`);return}n.code===`inactive_company_commerce`?this.sendAlert(`¡Comercio inactivo!`,`Tu compra no pudo ser procesada! El comercio no está disponible por el momento`):n.code===`payment_limit_exceeded`?this.sendAlert(`¡Límite de pago excedido!`,`Por favor, contacta al comercio.`):n.status===422?this.sendAlert(`¡Revisa la información!`,`Por favor, revisa los campos`):this.sendAlert(`¡Error al procesar el pago!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.sendFailureEmitter(n.status,this.serverErrorHandler.resolveServerErrorMessage(n.error));return}if(n.data.status!==`success`){let e=Zt(n.data.response_code??``);this.sendAlert(e.title,e.message),this.sendFailureEmitter(0,e.message);return}if(n.data.status===`success`){this.sendSuccess(n),this.resetForm();return}}}if(t.type===`payment-form:points-pay`&&await this.processPointsPayment(),t.type===`payment-form:load-crypto-countries`){this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let e=this.countryContent.getCountries(),t={...rn,country:{...rn.country,options:[{label:`Selecciona aquí`,value:``},...e.map(e=>({label:e.name,value:e.alpha2||e.id}))]}},n=new Map((this.config.i18n?.fields??[]).map(e=>[e.name,e])),r=!!this.config.totalAmount,i=pn(Vn(n,t,this.currentAmount,r));this.iframe?.contentWindow?.postMessage({type:`payment-form:update-forms`,forms:{crypto:i}},this.origin)}if(t.type===`payment-form:naka-callback`){this.stopNakaPolling();let e=t.chargeId||this.currentCryptoChargeId,n=wn.getInstance(),r=t.status,i=null;if(e)try{let t=await n.getChargeStatus(e);t?.data&&(i=t.data,r=i.status)}catch(e){if(e?.status===422){let t=e?.data?.error||$.PAYMENT_UNAVAILABLE.defaultMessage;await this.handleNakaTerminalFailure($.PAYMENT_UNAVAILABLE.title,t,422);return}if(e?.status===404){await this.handleNakaTerminalFailure($.ORDER_NOT_FOUND.title,$.ORDER_NOT_FOUND.message,404);return}await this.handleNakaTerminalFailure($.CONNECTION_ERROR.title,$.CONNECTION_ERROR.message,500);return}if(r===`UNDERPAID`){this.stopNakaPolling(),this.postMessageToIframe({type:`payment-form:crypto-incomplete`,title:$.UNDERPAID.title,message:$.UNDERPAID.message,retryLabel:$.UNDERPAID.retryLabel}),this.sendFailureEmitter(422,$.UNDERPAID.message);return}if(r===`CANCELED`||r===`CANCELLED`){await this.handleNakaTerminalFailure($.CANCELED.title,$.CANCELED.message,400);return}if(r===`EXPIRED`){await this.handleNakaTerminalFailure($.EXPIRED.title,$.EXPIRED.message,410);return}if(r===`FAILED`||r===`REJECTED`){await this.handleNakaTerminalFailure($.FAILED.title,$.FAILED.message,422);return}if(r===`SUCCESS`||r===`COMPLETED`||r===`PAID`||r===`OVERPAID`){let n=this.orchestrator.getConfig()?.data?.amount_currency||`USD`,r={data:{id:e||``,status:`success`,amount_cents:this.config.totalAmount??this.currentAmount??i?.amount_cents??0,amount_currency:n,response_code:`00`,authorization_number:i?.authorization_number||i?.transaction_id||t.chargeId||`NAKA-${Date.now()}`,reference_number:i?.reference_number||i?.order_number||t.orderNumber||e||``,billing_document_number:``,description:this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:En,card_last_digits:Dn,invoice_serie:null}};this.sendSuccess(r);return}}if(t.type===`payment-form:return-initial`){if(this.stopNakaPolling(),this.isCryptoOverpaid&&this.lastCryptoOverpaidSuccess){this.sendSuccess(this.lastCryptoOverpaidSuccess);return}this.iframe&&=(this.iframe.remove(),null),await this.renderForm();return}if(t.type===`payment-form:crypto-retry`){this.stopNakaPolling(),this.iframe&&=(this.iframe.remove(),null),await this.renderForm();return}}},window.addEventListener(`message`,this.messageHandler)}applyFixedAmountFromOrderTemplate(){let e=this.orchestrator.getConfig();if(!e?.data)return;let{data:t}=e;if(t.order_template_id==null&&t.order_id==null||typeof t.amount_cents!=`number`||t.amount_cents<=0)return;let n=Ht(t.amount_cents/100,t.amount_currency||`USD`,`decimal`);this.config.description=t.description,this.config.totalAmount=Ut(n),this.currentAmount=Ut(n)}async renderForm(){let e=document.querySelector(this.config.iframeTarget);if(!e)return;let t=new Map((this.config.i18n?.fields??[]).map(e=>[e.name,e])),n=this.orchestrator.getConfig().data.secure_mode,r=this.orchestrator.getConfig().data.payment_methods,i=r.includes(`emv`),a=r.includes(`ba_puntos`),o=r.includes(`ba_plazos`),s=r.includes(`crypto`);n&&this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let c=this.countryContent.getCountries(),l=n?{...nn,country:{...nn.country,options:[{label:`Selecciona aquí`,value:``},...c.map(e=>({label:e.name,value:e.id}))]}}:tn,u=tn,d=!!this.config.totalAmount,f=Vn(t,l,this.currentAmount,d),p=n?Vn(t,u,this.currentAmount,d):f,m=Vn(t,{...rn,country:{...rn.country,options:[{label:`Selecciona aquí`,value:``},...c.map(e=>({label:e.name,value:e.alpha2||e.id}))]}},this.currentAmount,d);[f,p,m].forEach(e=>{e.forEach(e=>{this.currentValues[e.name]!==void 0&&e.name!==`amount`&&(e.default=this.currentValues[e.name])})});let h=an(this.config.i18n?.submitButton),g=i?un(f):``,_=a?dn(p):``,v=o?fn(p,h):``,y=s?pn(m):``;if(this.iframe){this.iframe.contentWindow?.postMessage({type:`payment-form:update-forms`,forms:{default:g+h,points:_,installments:v,crypto:y}},this.origin),this.notifyCountriesLoadError();return}let b=this.config.totalAmount?Ht(this.config.totalAmount/100,`USD`,`decimal`):``;this.iframe=Cn(Sn({headerHtml:on({logo:this.orchestrator.getConfig().data.logo_url,name:this.orchestrator.getConfig().data.name,description:this.config.description,header:this.config.header,totalAmount:b,...b?{icon:zn(`currency-dollar`)}:{}}),cardFormHtml:g,submitButtonHtml:h,pointsFormHtml:_,installmentFormHtml:v,cryptoFormHtml:y})),e.appendChild(this.iframe),this.iframe.addEventListener(`load`,()=>{this.setToken(this.orchestrator.getAuthToken().access_token),this.notifyCountriesLoadError(),this.sendReadyEmitter()})}async renderCompletedOrderView(){let e=document.querySelector(this.config.iframeTarget);if(!e)return;let t=this.orchestrator.getConfig().data,n=`
266
+ <div class="payment-success">
267
+ <p class="payment-success__amount">${Ht(t.amount_cents/100,t.amount_currency||`USD`)}</p>
268
+ <div class="payment-success__blocks">
269
+ <div class="payment-success__block">
270
+ <span class="payment-success__label">Número de orden</span>
271
+ <span class="payment-success__value">${t.order_id||``}</span>
272
+ </div>
273
+ </div>
274
+ <div class="payment-success__footer">
275
+ <h3 class="payment-success__done">¡Orden completada!</h3>
276
+ <p class="payment-success__message" style="font-family:Poppins,sans-serif;font-size:0.875rem;color:#6c757d;margin-top:8px;">Esta orden ya fue pagada exitosamente.</p>
277
+ </div>
278
+ </div>
279
+ `;this.iframe=Cn(Sn({headerHtml:`
280
+ <header class="form-header">
281
+ ${t.logo_url?`<img src="${t.logo_url}" alt="${t.name} Logo" class="commerce-logo">`:``}
282
+ </header>
283
+ `,submitButtonHtml:``,customBodyHtml:n})),e.appendChild(this.iframe),this.iframe.addEventListener(`load`,()=>{this.sendReadyEmitter()})}async renderCancelledOrderView(){let e=document.querySelector(this.config.iframeTarget);if(!e)return;let t=this.orchestrator.getConfig().data;this.iframe=Cn(Sn({headerHtml:`
284
+ <header class="form-header">
285
+ ${t.logo_url?`<img src="${t.logo_url}" alt="${t.name} Logo" class="commerce-logo">`:``}
286
+ </header>
287
+ `,submitButtonHtml:``,customBodyHtml:`
288
+ <div class="form-alert visible" style="display:block;">
289
+ <h3>Orden cancelada</h3>
290
+ <p>Esta orden de pago ha sido cancelada o no está disponible para pago.</p>
291
+ </div>
292
+ `})),e.appendChild(this.iframe),this.iframe.addEventListener(`load`,()=>{this.sendReadyEmitter()})}notifyCountriesLoadError(){let e=this.countryContent.getCountriesLoadError();e&&this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow,{country:[e]})}postMessageToIframe(e){try{this.iframe?.contentWindow?.postMessage(e,this.origin)}catch{try{this.iframe?.contentWindow?.postMessage(e,`*`)}catch{}}}resetForm(){this.postMessageToIframe({type:`payment-form:reset`})}setSubmitLoading(e){this.postMessageToIframe({type:`payment-form:set-submit-loading`,disabled:e})}setToken(e){this.postMessageToIframe({type:`payment-form:set-token`,token:e})}sendAlert(e,t){this.postMessageToIframe({type:`payment-form:alert`,title:e,message:t})}sendFailureEmitter(e,t){for(let n of this.failureListeners)n({status:e,message:t})}async processPointsPayment(){if(!this.pointsPaymentContext)return;let{value:e,points:t}=this.pointsPaymentContext,n;try{n=await this.paymentIntent.generatePaymentIntentPayload(e)}catch{this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.resetPointsPayButton();return}n.operation=`points`,n.points=t.toString(),this.config.totalAmount&&(n.subtotal_cents=this.config.totalAmount);let r=await this.paymentIntent.createPaymentIntent(n);if(`error`in r&&`code`in r){this.sendAlert(`¡Error al procesar el pago!`,`Por favor, intenta nuevamente, o contacta al comercio.`),this.sendFailureEmitter(r.status,this.serverErrorHandler.resolveServerErrorMessage(r.error)),this.resetPointsPayButton();return}if(r.data.status!==`success`){let e=Zt(r.data.response_code??``);this.sendAlert(e.title,e.message),this.sendFailureEmitter(0,e.message),this.resetPointsPayButton();return}this.sendSuccess(r)}resetPointsPayButton(){this.iframe?.contentWindow?.postMessage({type:`payment-form:points-pay-reset`},this.origin)}async handlePointsBalance(e){let t;try{t=await this.points.generatePayload(e)}catch{this.sendAlert(`¡Error al cifrar tus datos!`,`Por favor, intenta nuevamente, o contacta al comercio.`);return}let n=await this.points.getPointsBalance(t).catch(()=>null);if(!n||`error`in n||n.data.in_dollar_cents<=0){this.sendAlert(`¡Error al consultar tus puntos!`,`Por favor, intenta nuevamente, o contacta al comercio.`);return}let r=this.config.totalAmount??this.currentAmount??Ut(e.amount),i=Math.round(r*n.data.points/n.data.in_dollar_cents);this.pointsPaymentContext={value:e,points:i},this.iframe?.contentWindow?.postMessage({type:`payment-form:points-balance`,balance:{availableCents:n.data.in_dollar_cents,availablePoints:n.data.points,currency:n.data.in_dollar_currency,purchaseCents:r,purchasePoints:i},formValues:e},this.origin)}sendReadyEmitter(){for(let e of this.readyListeners)e()}sendSizingEmitter(e,t){for(let n of this.sizingListeners)n({width:e,height:t})}sendSuccess(e){this.config.totalAmount&&(e.data.amount_cents=this.config.totalAmount),this.postMessageToIframe({type:`payment-form:success`,paymentIntent:e});let{id:t,status:n,amount_cents:r,response_code:i,authorization_number:a,reference_number:o}=e.data,s={id:t,status:n,amount_cents:r,response_code:i,authorization_number:a,reference_number:o};for(let e of this.successListeners)e(s)}async handleCryptoPayment(e){this.setSubmitLoading(!0);let t=wn.getInstance(),n=this.config.totalAmount??this.currentAmount??Ut(e.amount||`0`);this.countryContent.getCountries().length===0&&await this.countryContent.fetchCountries();let r=e.country||``,i=this.countryContent.getCountries().find(e=>e.id===r||e.alpha2===r||e.name===r)?.alpha2||(r.length===2?r.toUpperCase():void 0),a={data:{branch_id:this.orchestrator.getConfig()?.data?.branch_id||this.config.branchCode,amount_cents:n,currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,description:e.description||this.config.description||`Pago con Criptomonedas`,billing_document_number:e.billingDocumentNumber||``,redirect_url:this.config.redirectUrl||(typeof window<`u`?`${window.location.origin}/paylink/crypto/callback`:void 0),kyc:{email:e.email||``,first_name:e.firstName||``,last_name:e.lastName||``,country:i||``,phone:e.phone||void 0,phone_number:e.phone||void 0,nationality:e.nationality?.toUpperCase()||i||void 0,city:e.city||void 0,postal_code:e.postalCode||void 0,zip_code:e.postalCode||e.zipCode||void 0,address:e.address||void 0}}};try{let r=await t.createCharge(a);this.currentCryptoChargeId=r.data.charge_id,this.setSubmitLoading(!1),this.postMessageToIframe({type:`payment-form:naka-checkout`,redirectUrl:r.data.redirect_url,chargeId:r.data.charge_id}),this.startNakaPolling(r.data.charge_id,n,e)}catch(e){this.setSubmitLoading(!1),this.sendAlert($.CREATE_CHARGE_ERROR.title,$.CREATE_CHARGE_ERROR.message),this.sendFailureEmitter(500,e instanceof Error?e.message:`Error en servicio de criptomonedas`)}}async handleNakaTerminalFailure(e,t,n){this.stopNakaPolling(),this.iframe&&=(this.iframe.remove(),null),this.pendingAlert={title:e,message:t},await this.renderForm(),this.sendFailureEmitter(n,t)}startNakaPolling(e,t,n){this.stopNakaPolling();let r=wn.getInstance(),i=0,a=Date.now();this.nakaPollingInterval=setInterval(async()=>{try{if(Date.now()-a>=18e5){await this.handleNakaTerminalFailure($.TIMEOUT.title,$.TIMEOUT.message,408);return}let o=await r.getChargeStatus(e);i=0;let s=o.data,c=s?.status;if(c===`SUCCESS`||c===`COMPLETED`||c===`PAID`){this.stopNakaPolling();let r={data:{id:e,status:`success`,amount_cents:t,amount_currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,response_code:`00`,authorization_number:s.authorization_number||s.transaction_id||`NAKA-${Date.now()}`,reference_number:s.reference_number||s.order_number||e,billing_document_number:n.billingDocumentNumber||``,description:n.description||this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:En,card_last_digits:Dn,invoice_serie:null}};this.sendSuccess(r);return}if(c===`CANCELED`||c===`CANCELLED`){await this.handleNakaTerminalFailure($.CANCELED.title,$.CANCELED.message,400);return}if(c===`EXPIRED`){await this.handleNakaTerminalFailure($.EXPIRED.title,$.EXPIRED.message,410);return}if(c===`FAILED`||c===`REJECTED`){await this.handleNakaTerminalFailure($.FAILED.title,$.FAILED.message,422);return}if(c===`OVERPAID`){this.isCryptoOverpaid=!0,this.lastCryptoOverpaidSuccess={data:{id:e,status:`success`,amount_cents:t,amount_currency:this.orchestrator.getConfig()?.data?.amount_currency||`USD`,response_code:`00`,authorization_number:s.authorization_number||s.transaction_id||`NAKA-${Date.now()}`,reference_number:s.reference_number||s.order_number||e,billing_document_number:n.billingDocumentNumber||``,description:n.description||this.config.description||`Pago con Criptomonedas`,date:new Date().toISOString().split(`T`)[0],time:new Date().toTimeString().split(` `)[0],commerce_name:this.orchestrator.getConfig()?.data?.name||``,branch_name:this.orchestrator.getConfig()?.data?.branch_name||``,card_network:En,card_last_digits:Dn,invoice_serie:null}},this.postMessageToIframe({type:`payment-form:crypto-overpaid`,label:$.OVERPAID.finishLabel});return}if(c===`PENDING`||c===`IN_PROGRESS`||c===`OPEN`||c===`UNDERPAID`)return}catch(e){if(e?.status===422){let t=e?.data?.error||$.PAYMENT_UNAVAILABLE.defaultMessage;await this.handleNakaTerminalFailure($.PAYMENT_UNAVAILABLE.title,t,422);return}if(e?.status===404){await this.handleNakaTerminalFailure($.ORDER_NOT_FOUND.title,$.ORDER_NOT_FOUND.message,404);return}if(e?.status===401||e?.status===403){await this.handleNakaTerminalFailure($.SESSION_EXPIRED.title,$.SESSION_EXPIRED.message,e.status);return}if(i++,i>=5){await this.handleNakaTerminalFailure($.CONNECTION_ERROR.title,$.CONNECTION_ERROR.message,500);return}}},Tn)}stopNakaPolling(){this.nakaPollingInterval&&=(clearInterval(this.nakaPollingInterval),null)}destroy(){this.stopNakaPolling(),this.pendingAlert=null,this.currentCryptoChargeId=null,this.isCryptoOverpaid=!1,this.lastCryptoOverpaidSuccess=null,this.messageHandler&&=(window.removeEventListener(`message`,this.messageHandler),null),this.successListeners.clear(),this.failureListeners.clear(),this.readyListeners.clear(),this.sizingListeners.clear(),this.iframe&&=(this.iframe.remove(),null)}},e.VERSION=`1.5.6`,e})({});
package/dist/index.js CHANGED
@@ -11339,6 +11339,7 @@ function zt(e) {
11339
11339
  min-height: 240px;
11340
11340
  height: 100%;
11341
11341
  width: 100%;
11342
+ margin: 0 auto;
11342
11343
  box-sizing: border-box;
11343
11344
  padding: 48px 16px;
11344
11345
  gap: 16px;
@@ -11996,8 +11997,8 @@ function bn(e, t, n, r, i) {
11996
11997
  //#endregion
11997
11998
  //#region src/content/html/iframeTemplate.ts
11998
11999
  function xn(e) {
11999
- let t = `<img src="${hn}" alt="Bizz Logo" class="bizz-logo">`, n = bn(e.cardFormHtml || "", e.submitButtonHtml, e.pointsFormHtml || "", e.installmentFormHtml || "", e.cryptoFormHtml || "");
12000
- return pn.replace("<!--STYLES-->", `<style>${gn}</style>`).replace("<!--BIZZ_LOGO-->", t).replace("<!--HEADER-->", e.headerHtml).replace("<!--OPERATION_SELECTION-->", n).replace("<!--VERSION-->", "<div class=\"bizz-sdk-version\">v1.5.5</div>").replace("<!--SCRIPT-->", `<script>${mn}<\/script>`);
12000
+ let t = `<img src="${hn}" alt="Bizz Logo" class="bizz-logo">`, n = e.customBodyHtml ?? bn(e.cardFormHtml || "", e.submitButtonHtml, e.pointsFormHtml || "", e.installmentFormHtml || "", e.cryptoFormHtml || "");
12001
+ return pn.replace("<!--STYLES-->", `<style>${gn}</style>`).replace("<!--BIZZ_LOGO-->", t).replace("<!--HEADER-->", e.headerHtml).replace("<!--OPERATION_SELECTION-->", n).replace("<!--VERSION-->", "<div class=\"bizz-sdk-version\">v1.5.6</div>").replace("<!--SCRIPT-->", `<script>${mn}<\/script>`);
12001
12002
  }
12002
12003
  function Sn(e) {
12003
12004
  let t = document.createElement("iframe");
@@ -12146,7 +12147,7 @@ var zn = class e {
12146
12147
  autocomplete: a.autocomplete
12147
12148
  };
12148
12149
  }), Vn = class {
12149
- static version = "1.5.5";
12150
+ static version = "1.5.6";
12150
12151
  config;
12151
12152
  iframe = null;
12152
12153
  messageHandler = null;
@@ -12204,7 +12205,29 @@ var zn = class e {
12204
12205
  r.style.cssText = "font-family:Poppins,sans-serif;text-align:center;padding:32px;color:#DB3339;font-size:14px;", r.textContent = n instanceof Error ? n.message : "Pago no procesado", e.appendChild(r);
12205
12206
  return;
12206
12207
  }
12207
- if (t.remove(), this.applyFixedAmountFromOrderTemplate(), await this.renderForm(), this.messageHandler = async (e) => {
12208
+ t.remove(), this.setupMessageHandler();
12209
+ let n = this.orchestrator.getConfig()?.data?.status;
12210
+ if (n === "completed") {
12211
+ await this.renderCompletedOrderView();
12212
+ return;
12213
+ }
12214
+ if (n === "cancelled") {
12215
+ await this.renderCancelledOrderView();
12216
+ return;
12217
+ }
12218
+ if (this.applyFixedAmountFromOrderTemplate(), await this.renderForm(), this.config.totalAmount && Number(this.config.totalAmount) > 0) try {
12219
+ this.setSubmitLoading(!0);
12220
+ let e = await this.amountEvaluation.validateAmount(this.config.totalAmount.toString());
12221
+ if (this.setSubmitLoading(!1), e && "data" in e) {
12222
+ let t = this.orchestrator.getConfig();
12223
+ t.data.secure_mode !== e.data.secure_mode && (t.data.secure_mode = e.data.secure_mode, await this.renderForm());
12224
+ }
12225
+ } catch {
12226
+ this.setSubmitLoading(!1), this.sendAlert("¡Error al validar el monto!", "Asegúrate de que el monto a pagar sea válido");
12227
+ }
12228
+ }
12229
+ setupMessageHandler() {
12230
+ this.messageHandler && window.removeEventListener("message", this.messageHandler), this.messageHandler = async (e) => {
12208
12231
  if (e.source && e.source !== this.iframe?.contentWindow && e.source !== window) return;
12209
12232
  let t = e.data;
12210
12233
  if (t?.type) {
@@ -12386,16 +12409,7 @@ var zn = class e {
12386
12409
  return;
12387
12410
  }
12388
12411
  }
12389
- }, window.addEventListener("message", this.messageHandler), this.config.totalAmount && Number(this.config.totalAmount) > 0) try {
12390
- this.setSubmitLoading(!0);
12391
- let e = await this.amountEvaluation.validateAmount(this.config.totalAmount.toString());
12392
- if (this.setSubmitLoading(!1), e && "data" in e) {
12393
- let t = this.orchestrator.getConfig();
12394
- t.data.secure_mode !== e.data.secure_mode && (t.data.secure_mode = e.data.secure_mode, await this.renderForm());
12395
- }
12396
- } catch {
12397
- this.setSubmitLoading(!1), this.sendAlert("¡Error al validar el monto!", "Asegúrate de que el monto a pagar sea válido");
12398
- }
12412
+ }, window.addEventListener("message", this.messageHandler);
12399
12413
  }
12400
12414
  applyFixedAmountFromOrderTemplate() {
12401
12415
  let e = this.orchestrator.getConfig();
@@ -12476,6 +12490,52 @@ var zn = class e {
12476
12490
  this.setToken(this.orchestrator.getAuthToken().access_token), this.notifyCountriesLoadError(), this.sendReadyEmitter();
12477
12491
  });
12478
12492
  }
12493
+ async renderCompletedOrderView() {
12494
+ let e = document.querySelector(this.config.iframeTarget);
12495
+ if (!e) return;
12496
+ let t = this.orchestrator.getConfig().data, n = `
12497
+ <div class="payment-success">
12498
+ <p class="payment-success__amount">${Vt(t.amount_cents / 100, t.amount_currency || "USD")}</p>
12499
+ <div class="payment-success__blocks">
12500
+ <div class="payment-success__block">
12501
+ <span class="payment-success__label">Número de orden</span>
12502
+ <span class="payment-success__value">${t.order_id || ""}</span>
12503
+ </div>
12504
+ </div>
12505
+ <div class="payment-success__footer">
12506
+ <h3 class="payment-success__done">¡Orden completada!</h3>
12507
+ <p class="payment-success__message" style="font-family:Poppins,sans-serif;font-size:0.875rem;color:#6c757d;margin-top:8px;">Esta orden ya fue pagada exitosamente.</p>
12508
+ </div>
12509
+ </div>
12510
+ `;
12511
+ this.iframe = Sn(xn({
12512
+ headerHtml: `
12513
+ <header class="form-header">
12514
+ ${t.logo_url ? `<img src="${t.logo_url}" alt="${t.name} Logo" class="commerce-logo">` : ""}
12515
+ </header>
12516
+ `,
12517
+ submitButtonHtml: "",
12518
+ customBodyHtml: n
12519
+ })), e.appendChild(this.iframe), this.iframe.addEventListener("load", () => {
12520
+ this.sendReadyEmitter();
12521
+ });
12522
+ }
12523
+ async renderCancelledOrderView() {
12524
+ let e = document.querySelector(this.config.iframeTarget);
12525
+ if (!e) return;
12526
+ let t = this.orchestrator.getConfig().data;
12527
+ this.iframe = Sn(xn({
12528
+ headerHtml: `
12529
+ <header class="form-header">
12530
+ ${t.logo_url ? `<img src="${t.logo_url}" alt="${t.name} Logo" class="commerce-logo">` : ""}
12531
+ </header>
12532
+ `,
12533
+ submitButtonHtml: "",
12534
+ customBodyHtml: "\n <div class=\"form-alert visible\" style=\"display:block;\">\n <h3>Orden cancelada</h3>\n <p>Esta orden de pago ha sido cancelada o no está disponible para pago.</p>\n </div>\n "
12535
+ })), e.appendChild(this.iframe), this.iframe.addEventListener("load", () => {
12536
+ this.sendReadyEmitter();
12537
+ });
12538
+ }
12479
12539
  notifyCountriesLoadError() {
12480
12540
  let e = this.countryContent.getCountriesLoadError();
12481
12541
  e && this.serverErrorHandler.sendServerValidationErrors(this.iframe?.contentWindow, { country: [e] });
@@ -12736,6 +12796,6 @@ var zn = class e {
12736
12796
  destroy() {
12737
12797
  this.stopNakaPolling(), this.pendingAlert = null, this.currentCryptoChargeId = null, this.isCryptoOverpaid = !1, this.lastCryptoOverpaidSuccess = null, this.messageHandler &&= (window.removeEventListener("message", this.messageHandler), null), this.successListeners.clear(), this.failureListeners.clear(), this.readyListeners.clear(), this.sizingListeners.clear(), this.iframe &&= (this.iframe.remove(), null);
12738
12798
  }
12739
- }, Hn = "1.5.5";
12799
+ }, Hn = "1.5.6";
12740
12800
  //#endregion
12741
12801
  export { Vn as BizzPaymentForm, Hn as VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bizzsv/bizz-payment",
3
- "version": "1.5.5-dev",
3
+ "version": "1.5.6-dev",
4
4
  "description": "The Biz Payment SDK is designed to provide a secure, isolated form for payment integration.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",