1class MPEventHandler{REMOVE_LOAD_SPINNER_DELAY=500;MAX_ORDER_PAY_RETRIES=5;constructor(e,r){this.cardForm=e,this.threeDSHandler=r,this.triggeredPaymentMethodSelectedEvent=!1,this.mercado_pago_submit=!1,this.hasToken=!1,this.mpFormId="checkout"}bindEvents(){jQuery("form.checkout").on("checkout_place_order_woo-mercado-pago-custom",((e,r)=>this.mercadoPagoFormHandler(e,r))),jQuery("body").on("payment_method_selected",this.handlePaymentMethodSelected.bind(this)),jQuery("form#order_review").submit(this.handleOrderReviewSubmit.bind(this)),jQuery(document.body).on("checkout_error",this.handleCheckoutError.bind(this)),jQuery(document).on("updated_checkout",this.handleUpdatedCheckout.bind(this)),jQuery(document).ready((()=>{this.threeDSHandler.set3dsStatusValidationListener(),wc_mercadopago_custom_event_handler_params.is_mobile||this.initCardFormWhenReady()}))}initCardFormWhenReady(){const e=document.querySelector(".mp-checkout-custom-container"),r=document.querySelector("#payment_method_woo-mercado-pago-custom"),o=this.isOrderPayPage();if(r?.checked)if(e){if(!this.cardForm.formMounted)return o?(this.cardForm.createLoadSpinner(),void Promise.resolve(this.cardForm.initCardForm()).finally((()=>this.cardForm.removeLoadSpinner()))):void(null!==e.offsetParent&&this.cardForm.initCardForm())}else o&&this.scheduleOrderPayInitRetry()}scheduleOrderPayInitRetry(){this.orderPayInitRetries=(this.orderPayInitRetries||0)+1,this.orderPayInitRetries>this.MAX_ORDER_PAY_RETRIES||setTimeout((()=>this.initCardFormWhenReady()),300)}isOrderPayPage(){const e=document.body?.classList?.contains("woocommerce-order-pay"),r=!!document.querySelector("form#order_review");return e||r}getCheckoutForm(){return this.isOrderPayPage()?jQuery("form#order_review"):jQuery("form.checkout")}showCheckoutClassicLoader(){this.getCheckoutForm()?.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}hideCheckoutClassicLoader(){this.getCheckoutForm()?.unblock()}mercadoPagoFormHandler(e,r){return this.setMercadoPagoSessionId(),window.mpSuperTokenPaymentMethods?.hideSuperTokenError(),!!this.mercado_pago_submit||("wallet_button"===jQuery("#mp_checkout_type").val()||("super_token"===jQuery("#mp_checkout_type").val()?(window.mpSuperTokenMetrics?.registerClickOnPlaceOrderButton(),this.hasWooCommerceValidationErrors()?!this.isOrderPayPage()||(document.getElementById("order_review").submit(),!1):(this.handleWithSuperTokenSubmit(e,r),!1)):(jQuery("#mp_checkout_type").val("custom"),this.hasWooCommerceValidationErrors()&&this.isOrderPayPage()?(document.getElementById("order_review").submit(),!1):!this.hasToken&&(this.setPayerIdentificationInfo(),this.createToken()))))}async handleWithSuperTokenSubmit(e,r){try{e.preventDefault(),this.showCheckoutClassicLoader();const o=window.mpSuperTokenPaymentMethods,t=window.mpSuperTokenAuthenticator;if(!o)throw new Error(MPSuperTokenErrorCodes.SUPER_TOKEN_PAYMENT_METHODS_NOT_FOUND);if(!t)throw new Error(MPSuperTokenErrorCodes.SUPER_TOKEN_AUTHENTICATOR_NOT_FOUND);const i=o.getActivePaymentMethod(),n=i&&o.isSelectedPaymentMethodValid();if(!i)throw new Error(MPSuperTokenErrorCodes.SELECT_PAYMENT_METHOD_ERROR);if(!n)throw new Error(MPSuperTokenErrorCodes.SELECT_PAYMENT_METHOD_NOT_VALID);this.isOrderPayPage()&&o.unmountCardForm(),await o.updateSecurityCode(),await t.authorizePayment(i.token),this.mercado_pago_submit=!0,window.mpSuperTokenAuthenticator?.setSuperTokenValidation(!0),this.isOrderPayPage()?this.handle3dsPayOrderFormSubmission():r.$checkout_form.trigger("submit")}catch(e){if(e?.message===MPSuperTokenErrorCodes.SELECT_PAYMENT_METHOD_NOT_VALID)return window.mpSuperTokenErrorHandler.handleError(e),this.cardForm.removeLoadSpinner(),void this.hideCheckoutClassicLoader();window.mpSuperTokenTriggerHandler?.resetSuperTokenOnError(),window.mpSuperTokenTriggerHandler?.setLastException(e),window.mpSuperTokenAuthenticator?.setSuperTokenValidation(!1)}}isInsideHiddenContainer(e){const r=[".shipping_address",".billing_address",".woocommerce-shipping-fields",".woocommerce-billing-fields",".form-row",".create-account"];for(const o of r){const r=e.closest(o);if(r&&"none"===window.getComputedStyle(r).display)return!0}return!1}hasWooCommerceValidationErrors(){const e=document.querySelectorAll(".woocommerce-invalid, .woocommerce-invalid-required-field, .validate-required.woocommerce-invalid"),r=Array.from(e).filter((e=>!this.isInsideHiddenContainer(e))),o=this.isOrderPayPage()?"#order_review":".woocommerce-checkout",t=document.querySelectorAll(`${o} .validate-required input, ${o} .validate-required select`),i=Array.from(t).some((e=>"hidden"!==e.type&&!e.disabled&&(!this.isInsideHiddenContainer(e)&&("checkbox"===e.type&&"terms"===e.id&&"terms"===e.name?!e.checked:!e.value.trim()))));return r.length>0||i}createToken(){return"undefined"==typeof CheckoutPage||"function"!=typeof CheckoutPage.installmentsWasSelected||CheckoutPage.installmentsWasSelected()?(this.cardForm.form.createCardToken().then((e=>{if(!e.token)throw new Error("cardToken is empty");if(!this.hasToken)return document.querySelector("#cardTokenId").value=e.token,this.mercado_pago_submit=!0,this.hasToken=!0,"order_review"===this.mpFormId?(this.handle3dsPayOrderFormSubmission(),!1):void jQuery("form.checkout").submit()})).catch((e=>{console.warn("Token creation error: ",e),this.cardForm.scrollToCardForm(),this.cardForm.removeLoadSpinner()})),!1):(CheckoutPage.setInstallmentsErrorState(!0),CheckoutPage.scrollToCheckoutCustomContainer(),this.cardForm.removeLoadSpinner(),!1)}setMercadoPagoSessionId(){if("undefined"!=typeof MP_DEVICE_SESSION_ID&&MP_DEVICE_SESSION_ID)try{document.querySelector("#mpCardSessionId").value=MP_DEVICE_SESSION_ID}catch(e){console.warn(e)}}isCheckoutCustomPaymentMethodSelected(){const e=document.getElementById("payment_method_woo-mercado-pago-custom")||document.querySelector("input[value=woo-mercado-pago-custom]");return e&&e.checked}handlePaymentMethodSelected(){return this.isCheckoutCustomPaymentMethodSelected()?this.isOrderPayPage()?this.onSelectCheckoutCustomInOrderPayPage():void 0:(this.cardForm.formMounted&&this.cardForm.form.unmount(),void(window.mpSuperTokenTriggerHandler?.isSuperTokenPaymentMethodsLoaded()&&window.mpSuperTokenPaymentMethods.getPaymentMethodsListElement()?.style.setProperty("display","none","important")))}handleOrderReviewSubmit(e){if(this.isCheckoutCustomPaymentMethodSelected())return this.mercadoPagoFormHandler(e);this.cardForm.formMounted&&this.cardForm.form.unmount()}handleCheckoutError(){this.hasToken=!1,this.mercado_pago_submit=!1,this.cardForm.removeLoadSpinner(),window.mpSuperTokenTriggerHandler?.resetSuperTokenOnError()}handleUpdatedCheckout(){if(this.isCheckoutCustomPaymentMethodSelected()){this.cardForm.createLoadSpinner();const e=this.cardForm.getAmount(),r=this.cardForm.amount,o=[window.mpSuperTokenTriggerHandler?.loadSuperToken(e)];this.cardForm.formMounted&&["form-checkout__cardNumber-container","form-checkout__expirationDate-container","form-checkout__securityCode-container"].every((e=>{const r=document.getElementById(e);return!!r&&!r.querySelector("iframe")}))?(this.cardForm.form.unmount(),this.cardForm.formMounted=!1):this.cardForm.formMounted&&e!==r&&this.cardForm.form.unmount(),this.cardForm.formMounted||o.push(this.cardForm.initCardForm()),Promise.all(o).finally((()=>{setTimeout((()=>this.cardForm.removeLoadSpinner()),this.REMOVE_LOAD_SPINNER_DELAY)}))}}handle3dsPayOrderFormSubmission(){var e=jQuery("#order_review").seri
1alize();jQuery.post("#",e).done((e=>{if(e.three_ds_flow)this.threeDSHandler.load3DSFlow(e.last_four_digits);else if("success"===e.result&&e.redirect)window.location.href=e.redirect;else{if("fail"===e.result){jQuery("#order_review .woocommerce-error, #order_review .woocommerce-message").remove(),jQuery("#order_review").prepend('<div class="woocommerce-error">'+e.messages+"</div>");const r=document.querySelector("#order_review .woocommerce-error");return r&&r.scrollIntoView({behavior:"smooth"}),this.cardForm.removeBlockOverlay(),this.cardForm.removeLoadSpinner(),this.cardForm.form.unmount(),this.cardForm.initCardForm(),this.hasToken=!1,void(this.mercado_pago_submit=!1)}window.location.reload()}})).error((()=>{window.location.reload()}))}setPayerIdentificationInfo(){[{selector:"#form-checkout__identificationType",hiddenInputId:"#payerDocType"},{selector:"#form-checkout__identificationNumber",hiddenInputId:"#payerDocNumber"}].forEach((({selector:e,hiddenInputId:r})=>{const o=document.querySelector(e),t=document.querySelector(r);o&&t&&o.value&&(t.value=o.value)}))}onSelectCheckoutCustomInOrderPayPage(){let e=0;this.cardForm.createLoadSpinner();const r=setInterval((()=>{if(++e<100&&!window.mpSuperTokenTriggerHandler)return;clearInterval(r);const o=this.cardForm.getAmount(),t=[];return window.mpSuperTokenTriggerHandler&&t.push(window.mpSuperTokenTriggerHandler?.loadSuperToken(o)),this.cardForm.formMounted||t.push(this.cardForm.initCardForm()),Promise.all(t).finally((()=>{setTimeout((()=>this.cardForm.removeLoadSpinner()),this.REMOVE_LOAD_SPINNER_DELAY)}))}),100)}}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.