1class MPCardForm{TIMEOUT_TO_WAIT_INIT_CARD_FORM=1e4;constructor(){this.form=null,this.formMounted=!1,this.mpFormId="checkout",this.amount=null,this.onReadyDebounce=null,this.fields=null,this.initCardFormTimeoutReference=null,this.isLoading=!1}async initCardForm(e=this.getAmount()){if(this.amount=e,this.cardNumberFilledValidator=!1,!window.mpSdkInstance){const e=new MercadoPago(wc_mercadopago_custom_checkout_params.public_key,{locale:wc_mercadopago_custom_checkout_params.locale});window.mpSdkInstance=e}return new Promise(((o,t)=>{this.createTimeoutToWaitInitCardForm(t),this.form=window.mpSdkInstance.cardForm({amount:e,iframe:!0,form:this.getCardFormConfig(),callbacks:this.getCardFormCallbacks(o,t)})})).then((()=>{this.clearTimeoutToWaitInitCardForm(),this.sendMetric("MP_CARDFORM_SUCCESS","Security fields loaded","mp_custom_checkout_security_fields_client"),CheckoutPage.verifyCardholderNameOnFocus()})).catch((e=>{this.clearTimeoutToWaitInitCardForm();const o=this.handleCardFormErrors(e);this.sendMetric("MP_CARDFORM_ERROR",o,"mp_custom_checkout_security_fields_client"),console.error("Mercado Pago cardForm error: ",o)}))}createTimeoutToWaitInitCardForm(e=()=>{}){this.initCardFormTimeoutReference=setTimeout((()=>{this.removeLoadSpinner(),e(new Error("INIT_CARD_FORM_TIMEOUT"))}),this.TIMEOUT_TO_WAIT_INIT_CARD_FORM)}clearTimeoutToWaitInitCardForm(){clearTimeout(this.initCardFormTimeoutReference)}getCardFormConfig(){const e={fontSize:"16px",height:"48px",padding:"14px",textAlign:"left",fontFamily:"Inter ",fontWeight:"400",placeholderColor:" #0000008C"},o={src:"https://fonts.googleapis.com/css2?family=Inter"};return{id:this.mpFormId,cardNumber:{id:"form-checkout__cardNumber-container",placeholder:"1234 1234 1234 1234",style:e,customFonts:[o]},cardholderName:{id:"form-checkout__cardholderName",placeholder:wc_mercadopago_custom_checkout_params.placeholders.cardholderName},cardExpirationDate:{id:"form-checkout__expirationDate-container",placeholder:wc_mercadopago_custom_checkout_params.placeholders.cardExpirationDate,mode:"short",style:e,customFonts:[o]},securityCode:{id:"form-checkout__securityCode-container",placeholder:wc_mercadopago_custom_card_form_params.security_code_placeholder_text_3_digits,style:e,customFonts:[o]},identificationType:{id:"form-checkout__identificationType"},identificationNumber:{id:"form-checkout__identificationNumber"},issuer:{id:"form-checkout__issuer",placeholder:wc_mercadopago_custom_checkout_params.placeholders.issuer},installments:{id:"form-checkout__installments",placeholder:wc_mercadopago_custom_checkout_params.placeholders.installments}}}getCardFormCallbacks(e,o){return{onReady:o=>{this.fields=o,this.setupSecureFieldsStylesAndAddListeners(),e()},onFormMounted:o=>{this.formMounted=!0,e(),o&&console.log("Callback to handle the error: creating the CardForm",o)},onFormUnmounted:o=>{this.formMounted=!1,CheckoutPage.clearInputs(),e(),o&&console.log("Callback to handle the error: unmounting the CardForm",o)},onInstallmentsReceived:(e,o)=>{if(e){const o=wc_mercadopago_custom_checkout_params.error_messages;return this.addErrorAlert(o.installments[e.message]??o.default),void console.warn("Installments handling error: ",e)}CheckoutPage.setChangeEventOnInstallments(o)},onCardTokenReceived:e=>{e&&console.error("Token handling error: ",e)},onPaymentMethodsReceived:(e,o)=>{if(e)console.error("Payment methods handling error: ",e);else try{if(o){CheckoutPage.clearInputs();const e=o[0];CheckoutPage.setValueOn("paymentMethodId",e.id),CheckoutPage.setCvvConfig(e.settings[0].security_code),CheckoutPage.setImageCard(e.secure_thumbnail||e.thumbnail);const t=CheckoutPage.loadAdditionalInfo(e.additional_info_needed);CheckoutPage.additionalInfoHandler(t),CheckoutPage.setDisplayOfError("fcCardNumberContainer","remove","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-number","none"),CheckoutPage.setDisplayOfError("mpCardholderNameInputLabel","remove","mp-label-error"),CheckoutPage.setDisplayOfError("mpDocumentInputLabel","remove","mp-label-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-holder-name","none"),CheckoutPage.setDisplayOfInputHelperInfo("mp-card-holder-name","flex"),CheckoutPage.shouldEnableInstallmentsComponent(e.payment_type_id)}else CheckoutPage.setDisplayOfError("fcCardNumberContainer","add","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-number","flex")}catch(e){if(e)return void console.error("Payment methods handling error: ",e);CheckoutPage.setDisplayOfError("fcCardNumberContainer","add","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-number","flex")}},onSubmit:e=>{e.preventDefault()},onValidityChange:(e,o)=>{if("cardNumber"===o&&(this.cardNumberFilledValidator=!0),e){let t=CheckoutPage.getHelperMessage(o),r=wc_mercadopago_custom_checkout_params.input_helper_message[o][e[0].code];t.innerHTML=r||wc_mercadopago_custom_checkout_params.input_helper_message[o].invalid_length,"cardNumber"===o&&("invalid_length"!==e[0].code&&(CheckoutPage.setBackgroun
1d("fcCardNumberContainer","no-repeat #fff"),CheckoutPage.removeAdditionFields(),CheckoutPage.clearInputs()),CheckoutPage.setDisplayOfInputHelperInfo("mp-card-holder-name","flex"));let a=CheckoutPage.findContainerField(o);return CheckoutPage.setDisplayOfError(a,"add","mp-error"),"cardholderName"===o&&CheckoutPage.verifyCardholderName(),CheckoutPage.setDisplayOfInputHelper(CheckoutPage.inputHelperName(o),"flex")}if("cardholderName"===o&&!CheckoutPage.verifyCardholderName())return;let t=CheckoutPage.findContainerField(o);return CheckoutPage.setDisplayOfError(t,"removed","mp-error"),CheckoutPage.setDisplayOfInputHelper(CheckoutPage.inputHelperName(o),"none")},onError:e=>{CheckoutPage.verifyCardholderName(),e.forEach((e=>(this.removeBlockOverlay(),e.message.includes("timed out")?o(e):e.message.includes("cardNumber")?(CheckoutPage.setDisplayOfError("fcCardNumberContainer","add","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-number","flex")):e.message.includes("cardholderName")?(CheckoutPage.setDisplayOfError("fcCardholderName","add","mp-error"),CheckoutPage.setDisplayOfInputHelperInfo("mp-card-holder-name","none"),CheckoutPage.setDisplayOfError("mpCardholderNameInputLabel","add","mp-label-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-holder-name","flex")):e.message.includes("expirationMonth")||e.message.includes("expirationYear")?(CheckoutPage.setDisplayOfError("fcCardExpirationDateContainer","add","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-expiration-date","flex")):e.message.includes("securityCode")?(e.message.includes("should be a number")||e.message.includes("should be of length")?CheckoutPage.setDisplayOfInputHelperMessage("mp-security-code",wc_mercadopago_custom_checkout_params.input_helper_message.securityCode.invalid_length):CheckoutPage.setDisplayOfInputHelperMessage("mp-security-code",wc_mercadopago_custom_checkout_params.input_helper_message.securityCode.invalid_type),CheckoutPage.setDisplayOfError("fcSecurityNumberContainer","add","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-security-code","flex")):e.message.includes("identificationNumber")?(CheckoutPage.setDisplayOfError("fcIdentificationNumberContainer","add","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-doc-number","flex")):o(e))))}}}scrollToCardForm(){const e=document.querySelector("#mp-checkout-custom-container.mp-checkout-container");e&&e.scrollIntoView({behavior:"smooth"})}getAmount(){const e=parseFloat(document.getElementById("mp-amount").value.replace(",","."));return String(e)}handleCardFormErrors(e){if(e.length){const o=[];return e.forEach((e=>{o.push(e.description||e.message)})),o.join(",")}return e.description||e.message}sendMetric(e,o,t){void 0!==window.mPmetrics&&window.mPmetrics.push({action:e,label:o,target:t})}isClassicCheckout(){return!!document.querySelector(".payment_method_woo-mercado-pago-custom")}startLoadingOnClassicCheckout(){jQuery("form.checkout")?.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}stopLoadingOnClassicCheckout(){jQuery("form.checkout")?.unblock()}createLoadSpinner(){if(this.isLoading)return;const e=document.querySelector("#mp-checkout-custom-container.mp-checkout-container"),o=document.querySelector(".mp-checkout-custom-load");this.isLoading=!0,e?.classList.add("mp-hidden"),e?.classList.add("mp-display-none"),o?.classList.remove("mp-hidden"),o?.classList.remove("mp-display-none");const t=Date.now();setTimeout((()=>{document.dispatchEvent(new CustomEvent("mp_super_token_loading_start",{detail:{dateNowInMilliseconds:t}})),window.melidata||sendMetric("MP_MELIDATA_CLIENT_UNDEFINED","Loading started but melidata client is not loaded yet","mp_custom_checkout_melidata_client_undefined")}),3e3)}removeLoadSpinner(){if(!this.isLoading)return;const e=document.querySelector("#mp-checkout-custom-container.mp-checkout-container"),o=document.querySelector(".mp-checkout-custom-load");this.isLoading=!1;window.mpSuperTokenTriggerHandler?.isSuperTokenPaymentMethodsLoaded()&&o?.classList.add("mp-hidden"),setTimeout((()=>{o?.classList.add("mp-hidden"),o?.classList.add("mp-display-none"),e?.classList.remove("mp-hidden"),e?.classList.remove("mp-display-none")}),800);const t=Date.now();setTimeout((()=>{document.dispatchEvent(new CustomEvent("mp_super_token_loading_end",{detail:{dateNowInMilliseconds:t}})),window.melidata||sendMetric("MP_MELIDATA_CLIENT_UNDEFINED","Loading ended but melidata client is not loaded yet","mp_custom_checkout_melidata_client_undefined")}),3e3)}removeBlockOverlay(){jQuery("form#order_review").length>0&&jQuery(".blockOverlay").css("display","none")}addErrorAlert(e){this.removeElementsByClass("woocommerce-NoticeGroup-checkout"),jQuery(window.mpCheckoutForm).prepend(`\n <div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">\n <ul class="woocommerce-error" role="alert">\n <li>${e}<li>\n </ul>\n </div>\n `),window.scrollTo(0,0)}removeElementsByClass(e){const o=document.getElementsByClassName(e);for(;o.length>0;)o[0].parentNode.removeChild(o[0])}setupSecureFieldsStylesAndAddListeners(){if(!this.fields)return;
1const e=[{field:this.fields.cardNumber,fieldName:"cardNumber",containerId:"form-checkout__cardNumber-container",focusEventName:"card_number_focused",blurEventName:"card_number_filled",validator:()=>this.cardNumberFilledValidator},{field:this.fields.expirationDate,containerId:"form-checkout__expirationDate-container"},{field:this.fields.securityCode,containerId:"form-checkout__securityCode-container"}];for(const o of e)o.field&&"function"==typeof o.field.on&&(o.field.on("focus",(()=>{this.addOrRemoveCssClass(o.containerId,"mp-checkout-custom-card-form-focus","add"),o.focusEventName&&MPCheckoutFieldsDispatcher?.addEventListenerDispatcher(null,"focus",o.focusEventName,{onlyDispatch:!0})})),o.field.on("blur",(()=>{let e=!1;this.addOrRemoveCssClass(o.containerId,"mp-checkout-custom-card-form-focus"),o.validator&&(e="function"==typeof o.validator?o.validator():o.validator),o.blurEventName&&e&&(MPCheckoutFieldsDispatcher?.addEventListenerDispatcher(null,"blur",o.blurEventName,{onlyDispatch:!0}),o.fieldName&&this.updateFieldValidator(o.fieldName))})))}addOrRemoveCssClass(e,o,t="remove"){const r=document.getElementById(e);r?.classList["add"===t?"add":"remove"](o)}updateFieldValidator(e){"cardNumber"===e&&(this.cardNumberFilledValidator=!1)}}
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.