var cardForm,triggeredPaymentMethodSelectedEvent,cardFormMounted,mercado_pago_submit,hasToken=!1,mpFormId="checkout",threedsTarget="mp_custom_checkout_security_fields_client",mpCheckoutForm=document.querySelector("form[name=checkout]");function mercadoPagoFormHandler(){if(document.querySelector("form[id=order_review]")){document.querySelector(".mp-checkout-custom-container").querySelectorAll("input-helper").forEach((e=>{"none"!==e.querySelector("div").style.display&&removeBlockOverlay()}))}return setMercadoPagoSessionId(),!!mercado_pago_submit||("wallet_button"===jQuery("#mp_checkout_type").val()||(jQuery("#mp_checkout_type").val("custom"),!(!CheckoutPage.validateInputsCreateToken()||hasToken)&&createToken()))}function createToken(){return cardForm.createCardToken().then((e=>{if(!e.token)throw new Error("cardToken is empty");if(!hasToken)return document.querySelector("#cardTokenId").value=e.token,mercado_pago_submit=!0,hasToken=!0,"order_review"===mpFormId?(handle3dsPayOrderFormSubmission(),!1):void jQuery("form.checkout").submit()})).catch((e=>{console.warn("Token creation error: ",e)})),!1}function initCardForm(e=getAmount()){const o=new MercadoPago(wc_mercadopago_custom_checkout_params.public_key);return new Promise(((t,r)=>{cardForm=o.cardForm({amount:e,iframe:!0,form:{id:mpFormId,cardNumber:{id:"form-checkout__cardNumber-container",placeholder:"0000 0000 0000 0000",style:{"font-size":"16px",height:"40px",padding:"14px"}},cardholderName:{id:"form-checkout__cardholderName",placeholder:"Ex.: María López"},cardExpirationDate:{id:"form-checkout__expirationDate-container",placeholder:wc_mercadopago_custom_checkout_params.placeholders.cardExpirationDate,mode:"short",style:{"font-size":"16px",height:"40px",padding:"14px"}},securityCode:{id:"form-checkout__securityCode-container",placeholder:"123",style:{"font-size":"16px",height:"40px",padding:"14px"}},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}},callbacks:{onReady:()=>{removeLoadSpinner(),t()},onFormMounted:function(e){cardFormMounted=!0,e&&console.log("Callback to handle the error: creating the CardForm",e)},onFormUnmounted:function(e){cardFormMounted=!1,CheckoutPage.clearInputs(),e&&console.log("Callback to handle the error: unmounting the CardForm",e)},onInstallmentsReceived:(e,o)=>{if(e){const o=wc_mercadopago_custom_checkout_params.error_messages;return addErrorAlert(o.installments[e.message]??o.default),void console.warn("Installments handling error: ",e)}CheckoutPage.setChangeEventOnInstallments(CheckoutPage.getCountry(),o)},onCardTokenReceived:e=>{e&&console.warn("Token handling error: ",e)},onPaymentMethodsReceived:(e,o)=>{try{if(o){CheckoutPage.setValue("paymentMethodId",o[0].id),CheckoutPage.setCvvHint(o[0].settings[0].security_code),CheckoutPage.changeCvvPlaceHolder(o[0].settings[0].security_code.length),CheckoutPage.clearInputs(),CheckoutPage.setDisplayOfError("fcCardNumberContainer","remove","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-number","none"),CheckoutPage.setImageCard(o[0].secure_thumbnail||o[0].thumbnail),CheckoutPage.installment_amount(o[0].payment_type_id);const e=CheckoutPage.loadAdditionalInfo(o[0].additional_info_needed);CheckoutPage.additionalInfoHandler(e)}else CheckoutPage.setDisplayOfError("fcCardNumberContainer","add","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-number","flex")}catch(e){CheckoutPage.setDisplayOfError("fcCardNumberContainer","add","mp-error"),CheckoutPage.setDisplayOfInputHelper("mp-card-number","flex")}},onSubmit:function(e){e.preventDefault()},onValidityChange:function(e,o){if(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.setBackground("fcCardNumberContainer","no-repeat #fff"),CheckoutPage.removeAdditionFields(),CheckoutPage.clearInputs());let a=CheckoutPage.findContainerField(o);return CheckoutPage.setDisplayOfError(a,"add","mp-error"),CheckoutPage.setDisplayOfInputHelper(CheckoutPage.inputHelperName(o),"flex")}let t=CheckoutPage.findContainerField(o);return CheckoutPage.setDisplayOfError(t,"removed","mp-error"),CheckoutPage.setDisplayOfInputHelper(CheckoutPage.inputHelperName(o),"none")},onError:function(e){e.forEach((e=>(removeBlockOverlay(),e.message.includes("timed out")?r(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.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")?(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")):r(e))))}}})}))}function getAmount(){const e=parseFloat(document.getElementById("mp-amount").value.replace(",","."));return String(e)}function setMercadoPagoSessionId(){try{document.querySelector("#mpCardSessionId").value=MP_DEVICE_SESSION_ID}catch(e){console.warn(e)}}function removeBlockOverlay(){jQuery("form#order_review").length>0&&jQuery(".blockOverlay").css("display","none")}function cardFormLoad(){const e=document.getElementById("payment_method_woo-mercado-pago-custom")||document.querySelector("input[value=woo-mercado-pago-custom]");e&&e.checked?setTimeout((()=>{cardFormMounted||(createLoadSpinner(),handleCardFormLoad())}),2500):cardFormMounted&&cardForm.unmount()}function setCardFormLoadInterval(){var e=setInterval((()=>{const o=document.getElementById("payment_method_woo-mercado-pago-custom")||document.querySelector("input[value=woo-mercado-pago-custom]"),t=document.getElementById("form-checkout__cardNumber-container");o&&o.checked?t&&t.childElementCount>0?clearInterval(e):cardFormMounted&&(cardForm.unmount(),cardFormLoad()):clearInterval(e)}),1500)}function handleCardFormLoad(){initCardForm().then((()=>{sendMetric("MP_CARDFORM_SUCCESS","Security fields loaded",threedsTarget)})).catch((e=>{const o=handleCardFormErrors(e);sendMetric("MP_CARDFORM_ERROR",o,threedsTarget),console.error("Mercado Pago cardForm error: ",o)}))}function handleCardFormErrors(e){if(e.length){const o=[];return e.forEach((e=>{o.push(e.description||e.message)})),o.join(",")}return e.description||e.message}function createLoadSpinner(){document.querySelector(".mp-checkout-custom-container").style.display="none",document.querySelector(".mp-checkout-custom-load").style.display="flex"}function removeLoadSpinner(){document.querySelector(".mp-checkout-custom-container").style.display="block",document.querySelector(".mp-checkout-custom-load").style.display="none"}function removeLoadSpinner3ds(){var e=document.getElementById("mp-loading-container-3ds");e&&e.remove()}function addLoadSpinner3dsSubmit(){document.getElementById("mp-3ds-modal-content").innerHTML='
'+wc_mercadopago_custom_checkout_params.threeDsText.title_loading_response+"
'+wc_mercadopago_custom_checkout_params.threeDsText.title_loading+"
("+document.getElementById("paymentMethodId").value+"****"+e+") "+wc_mercadopago_custom_checkout_params.threeDsText.title_loading2+'
'+wc_mercadopago_custom_checkout_params.threeDsText.text_loading+"