diff --git a/CHANGELOG.md b/CHANGELOG.md index a8816e659..0ec7bab63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [7.3.5] - 2024-04-17 +### Fixed: +- Checked field on checkout now validated. +- Rollback SDK dependency. + ## [7.3.4] - 2024-04-15 ### Fixed: - Thankyou page redirect for PIX and Ticket Payments working again. diff --git a/assets/js/checkouts/custom/mp-custom-checkout.js b/assets/js/checkouts/custom/mp-custom-checkout.js index fea912239..4adf78a8a 100644 --- a/assets/js/checkouts/custom/mp-custom-checkout.js +++ b/assets/js/checkouts/custom/mp-custom-checkout.js @@ -382,7 +382,7 @@ jQuery(document).on('updated_checkout', function () { const checkoutCustomPaymentMethodElement = document.getElementById('payment_method_woo-mercado-pago-custom'); // Checkout Custom is not selected, so we can stop checking - if (checkoutCustomPaymentMethodElement || checkoutCustomPaymentMethodElement.checked) { + if (checkoutCustomPaymentMethodElement && checkoutCustomPaymentMethodElement.checked) { if (cardFormMounted) { cardForm.unmount(); } diff --git a/assets/js/checkouts/custom/mp-custom-checkout.min.js b/assets/js/checkouts/custom/mp-custom-checkout.min.js index 028eb8ffc..fd2971412 100644 --- a/assets/js/checkouts/custom/mp-custom-checkout.min.js +++ b/assets/js/checkouts/custom/mp-custom-checkout.min.js @@ -1 +1 @@ -var cardForm,hasToken=!1,mercado_pago_submit=!1,triggeredPaymentMethodSelectedEvent=!1,cardFormMounted=!1,threedsTarget="mp_custom_checkout_security_fields_client",mpCheckoutForm=document.querySelector("form[name=checkout]"),mpFormId="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()){var 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)=>{e?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");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"),t=document.getElementById("form-checkout__cardNumber-container");o&&o.checked?t&&t.childElementCount>0?clearInterval(e):cardFormMounted&&(cardForm.unmount(),cardFormLoad()):clearInterval(e)}),1e3)}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+"

"}function removeModal3ds(){CheckoutPage.clearInputs(),document.getElementById("mp-3ds-modal-container").remove()}function threeDSHandler(e,o){try{if(null==e||null==o)return removeModal3ds(),sendMetric("MP_THREE_DS_ERROR","3DS URL or CRED not set",threedsTarget),void console.log("Invalid parameters for 3ds");var t=document.createElement("div");t.className="mp-card-info",t.innerHTML='
'+wc_mercadopago_custom_checkout_params.threeDsText.title_frame+"
";var r=document.getElementById("mp-3ds-modal-content"),a=document.createElement("iframe");a.name="mp-3ds-frame",a.id="mp-3ds-frame",a.onload=()=>removeLoadSpinner3ds(),document.getElementById("mp-3ds-title").innerText=wc_mercadopago_custom_checkout_params.threeDsText.tooltip_frame,r.appendChild(t),r.appendChild(a);var n=a.contentWindow.document,c=n.createElement("form");c.name="mp-3ds-frame",c.className="mp-modal",c.setAttribute("target","mp-3ds-frame"),c.setAttribute("method","post"),c.setAttribute("action",e);var d=n.createElement("input");d.setAttribute("type","hidden"),d.setAttribute("name","creq"),d.setAttribute("value",o),c.appendChild(d),a.appendChild(c),c.submit()}catch(e){console.log(e),sendMetric("MP_THREE_DS_ERROR","3DS Loading error: "+e,threedsTarget),alert("Error doing Challenge, try again later.")}}function load3DSFlow(e){var o=document.createElement("div");o.setAttribute("id","mp-3ds-modal-container"),o.className="mp-3ds-modal";var t=document.createElement("div");t.id="mp-3ds-modal-content",t.innerHTML='
×

'+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+"

",o.appendChild(t),document.body.appendChild(o),document.querySelector("#mp-3ds-modal-close").addEventListener("click",(function(){setDisplayOfErrorCheckout(wc_mercadopago_custom_checkout_params.threeDsText.message_close),removeModal3ds()})),jQuery.post(woocommerce_params.wc_ajax_url.replace("%%endpoint%%","mp_get_3ds_from_session")).done((function(e){e.success?threeDSHandler(e.data.data["3ds_url"],e.data.data["3ds_creq"]):(console.error("Error POST:",e),window.dispatchEvent(new CustomEvent("completed_3ds",{detail:{error:!0}})),removeModal3ds())})).fail((function(e,o,t){console.error("Failed to make POST:",o,t),window.dispatchEvent(new CustomEvent("completed_3ds",{detail:{error:!0}})),removeModal3ds()}))}function redirectAfter3dsChallenge(){jQuery.post(woocommerce_params.wc_ajax_url.replace("%%endpoint%%","mp_redirect_after_3ds_challenge")).done((function(e){e.data.redirect?(window.dispatchEvent(new CustomEvent("completed_3ds",{detail:{error:!1}})),sendMetric("MP_THREE_DS_SUCCESS","3DS challenge complete",threedsTarget),removeModal3ds(),window.location.href=e.data.redirect):(window.dispatchEvent(new CustomEvent("completed_3ds",{detail:{error:e.data.data.error}})),setDisplayOfErrorCheckout(e.data.data.error),removeModal3ds())}))}function handle3dsPayOrderFormSubmission(){var e=jQuery("#order_review").serialize();jQuery.post("#",e).done((function(e){e.three_ds_flow?load3DSFlow(e.last_four_digits):(e.redirect&&(window.location.href=e.redirect),window.location.reload())})).error((function(){window.location.reload()}))}function setDisplayOfErrorCheckout(e){if(sendMetric("MP_THREE_DS_ERROR",e,threedsTarget),"blocks_checkout_form"!==window.mpFormId){removeElementsByClass("woocommerce-NoticeGroup-checkout");var o=document.createElement("div");o.className="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout",o.innerHTML='",mpCheckoutForm.prepend(o),window.scrollTo(0,0)}}function removeElementsByClass(e){const o=document.getElementsByClassName(e);for(;o.length>0;)o[0].parentNode.removeChild(o[0])}function sendMetric(e,o,t){const r={name:e,message:o,target:t,plugin:{version:wc_mercadopago_custom_checkout_params.plugin_version},platform:{name:"woocommerce",uri:window.location.href,version:wc_mercadopago_custom_checkout_params.platform_version,location:`${wc_mercadopago_custom_checkout_params.location}_${wc_mercadopago_custom_checkout_params.theme}`}};navigator.sendBeacon("https://api.mercadopago.com/v1/plugins/melidata/errors",JSON.stringify(r))}mpCheckoutForm?mpCheckoutForm.id=mpFormId:mpFormId="order_review",jQuery("form.checkout").on("checkout_place_order_woo-mercado-pago-custom",mercadoPagoFormHandler),jQuery("body").on("payment_method_selected",(function(){triggeredPaymentMethodSelectedEvent||cardFormLoad()})),jQuery("form#order_review").submit((function(e){const o=document.getElementById("payment_method_woo-mercado-pago-custom");if(o&&o.checked)return e.preventDefault(),mercadoPagoFormHandler();cardFormLoad()})),jQuery(document.body).on("checkout_error",(()=>{hasToken=!1,mercado_pago_submit=!1})),jQuery(document).on("updated_checkout",(function(){const e=document.getElementById("payment_method_woo-mercado-pago-custom");if(e||e.checked)return cardFormMounted&&cardForm.unmount(),void handleCardFormLoad()})),jQuery(document).ready((()=>{setCardFormLoadInterval()})),triggeredPaymentMethodSelectedEvent||jQuery("body").trigger("payment_method_selected"),window.addEventListener("message",(e=>{"COMPLETE"===e.data.status&&(sendMetric("MP_THREE_DS_SUCCESS","3DS iframe Closed",threedsTarget),document.getElementById("mp-3ds-modal-content").innerHTML="",addLoadSpinner3dsSubmit(),redirectAfter3dsChallenge())})); \ No newline at end of file +var cardForm,hasToken=!1,mercado_pago_submit=!1,triggeredPaymentMethodSelectedEvent=!1,cardFormMounted=!1,threedsTarget="mp_custom_checkout_security_fields_client",mpCheckoutForm=document.querySelector("form[name=checkout]"),mpFormId="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()){var 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)=>{e?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");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"),t=document.getElementById("form-checkout__cardNumber-container");o&&o.checked?t&&t.childElementCount>0?clearInterval(e):cardFormMounted&&(cardForm.unmount(),cardFormLoad()):clearInterval(e)}),1e3)}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+"

"}function removeModal3ds(){CheckoutPage.clearInputs(),document.getElementById("mp-3ds-modal-container").remove()}function threeDSHandler(e,o){try{if(null==e||null==o)return removeModal3ds(),sendMetric("MP_THREE_DS_ERROR","3DS URL or CRED not set",threedsTarget),void console.log("Invalid parameters for 3ds");var t=document.createElement("div");t.className="mp-card-info",t.innerHTML='
'+wc_mercadopago_custom_checkout_params.threeDsText.title_frame+"
";var r=document.getElementById("mp-3ds-modal-content"),a=document.createElement("iframe");a.name="mp-3ds-frame",a.id="mp-3ds-frame",a.onload=()=>removeLoadSpinner3ds(),document.getElementById("mp-3ds-title").innerText=wc_mercadopago_custom_checkout_params.threeDsText.tooltip_frame,r.appendChild(t),r.appendChild(a);var n=a.contentWindow.document,c=n.createElement("form");c.name="mp-3ds-frame",c.className="mp-modal",c.setAttribute("target","mp-3ds-frame"),c.setAttribute("method","post"),c.setAttribute("action",e);var d=n.createElement("input");d.setAttribute("type","hidden"),d.setAttribute("name","creq"),d.setAttribute("value",o),c.appendChild(d),a.appendChild(c),c.submit()}catch(e){console.log(e),sendMetric("MP_THREE_DS_ERROR","3DS Loading error: "+e,threedsTarget),alert("Error doing Challenge, try again later.")}}function load3DSFlow(e){var o=document.createElement("div");o.setAttribute("id","mp-3ds-modal-container"),o.className="mp-3ds-modal";var t=document.createElement("div");t.id="mp-3ds-modal-content",t.innerHTML='
×

'+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+"

",o.appendChild(t),document.body.appendChild(o),document.querySelector("#mp-3ds-modal-close").addEventListener("click",(function(){setDisplayOfErrorCheckout(wc_mercadopago_custom_checkout_params.threeDsText.message_close),removeModal3ds()})),jQuery.post(woocommerce_params.wc_ajax_url.replace("%%endpoint%%","mp_get_3ds_from_session")).done((function(e){e.success?threeDSHandler(e.data.data["3ds_url"],e.data.data["3ds_creq"]):(console.error("Error POST:",e),window.dispatchEvent(new CustomEvent("completed_3ds",{detail:{error:!0}})),removeModal3ds())})).fail((function(e,o,t){console.error("Failed to make POST:",o,t),window.dispatchEvent(new CustomEvent("completed_3ds",{detail:{error:!0}})),removeModal3ds()}))}function redirectAfter3dsChallenge(){jQuery.post(woocommerce_params.wc_ajax_url.replace("%%endpoint%%","mp_redirect_after_3ds_challenge")).done((function(e){e.data.redirect?(window.dispatchEvent(new CustomEvent("completed_3ds",{detail:{error:!1}})),sendMetric("MP_THREE_DS_SUCCESS","3DS challenge complete",threedsTarget),removeModal3ds(),window.location.href=e.data.redirect):(window.dispatchEvent(new CustomEvent("completed_3ds",{detail:{error:e.data.data.error}})),setDisplayOfErrorCheckout(e.data.data.error),removeModal3ds())}))}function handle3dsPayOrderFormSubmission(){var e=jQuery("#order_review").serialize();jQuery.post("#",e).done((function(e){e.three_ds_flow?load3DSFlow(e.last_four_digits):(e.redirect&&(window.location.href=e.redirect),window.location.reload())})).error((function(){window.location.reload()}))}function setDisplayOfErrorCheckout(e){if(sendMetric("MP_THREE_DS_ERROR",e,threedsTarget),"blocks_checkout_form"!==window.mpFormId){removeElementsByClass("woocommerce-NoticeGroup-checkout");var o=document.createElement("div");o.className="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout",o.innerHTML='",mpCheckoutForm.prepend(o),window.scrollTo(0,0)}}function removeElementsByClass(e){const o=document.getElementsByClassName(e);for(;o.length>0;)o[0].parentNode.removeChild(o[0])}function sendMetric(e,o,t){const r={name:e,message:o,target:t,plugin:{version:wc_mercadopago_custom_checkout_params.plugin_version},platform:{name:"woocommerce",uri:window.location.href,version:wc_mercadopago_custom_checkout_params.platform_version,location:`${wc_mercadopago_custom_checkout_params.location}_${wc_mercadopago_custom_checkout_params.theme}`}};navigator.sendBeacon("https://api.mercadopago.com/v1/plugins/melidata/errors",JSON.stringify(r))}mpCheckoutForm?mpCheckoutForm.id=mpFormId:mpFormId="order_review",jQuery("form.checkout").on("checkout_place_order_woo-mercado-pago-custom",mercadoPagoFormHandler),jQuery("body").on("payment_method_selected",(function(){triggeredPaymentMethodSelectedEvent||cardFormLoad()})),jQuery("form#order_review").submit((function(e){const o=document.getElementById("payment_method_woo-mercado-pago-custom");if(o&&o.checked)return e.preventDefault(),mercadoPagoFormHandler();cardFormLoad()})),jQuery(document.body).on("checkout_error",(()=>{hasToken=!1,mercado_pago_submit=!1})),jQuery(document).on("updated_checkout",(function(){const e=document.getElementById("payment_method_woo-mercado-pago-custom");if(e&&e.checked)return cardFormMounted&&cardForm.unmount(),void handleCardFormLoad()})),jQuery(document).ready((()=>{setCardFormLoadInterval()})),triggeredPaymentMethodSelectedEvent||jQuery("body").trigger("payment_method_selected"),window.addEventListener("message",(e=>{"COMPLETE"===e.data.status&&(sendMetric("MP_THREE_DS_SUCCESS","3DS iframe Closed",threedsTarget),document.getElementById("mp-3ds-modal-content").innerHTML="",addLoadSpinner3dsSubmit(),redirectAfter3dsChallenge())})); \ No newline at end of file diff --git a/changelog.log b/changelog.log index 5aa3d32d7..c91b855cf 100644 --- a/changelog.log +++ b/changelog.log @@ -1,6 +1,11 @@ CHANGELOG: == Changelog == += v7.3.5 (17/04/2024) = +* Fixed: +- Checked field on checkout now validated. +- Rollback SDK dependency. + = v7.3.4 (15/04/2024) = * Changed: - Thankyou page redirect for PIX and Ticket Payments working again. diff --git a/package.json b/package.json index 1103486a9..3007b0fe0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "woocommerce-mercadopago", "description": "Woocommerce MercadoPago Payment Gateway", - "version": "7.3.4", + "version": "7.3.5", "main": "main.js", "repository": { "type": "git", diff --git a/readme.txt b/readme.txt index 11cbbcff4..44ee76be6 100644 --- a/readme.txt +++ b/readme.txt @@ -2,9 +2,9 @@ Contributors: Tags: ecommerce, mercadopago, woocommerce Requires at least: 6.3 -Tested up to: 6.4 +Tested up to: 6.5 Requires PHP: 7.4 -Stable tag: 7.3.4 +Stable tag: 7.3.5 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -137,8 +137,7 @@ Check out our $this->mercadopago->storeTranslations->commonMessages['invalid_users'], "Invalid users involved" => $this->mercadopago->storeTranslations->commonMessages['invalid_users'], "Invalid operators users involved" => $this->mercadopago->storeTranslations->commonMessages['invalid_operators'], "exception" => $this->mercadopago->storeTranslations->buyerRefusedMessages['buyer_default'], - "400" => $this->mercadopago->storeTranslations->commonMessages['buyer_default'], + "400" => $this->mercadopago->storeTranslations->buyerRefusedMessages['buyer_default'], ]; foreach ($errorMessages as $keyword => $replacement) { diff --git a/src/Gateways/CreditsGateway.php b/src/Gateways/CreditsGateway.php index db88512d5..b1b9280c8 100644 --- a/src/Gateways/CreditsGateway.php +++ b/src/Gateways/CreditsGateway.php @@ -455,7 +455,6 @@ public function renderCreditsBanner(): void 'banner_link' => $this->storeTranslations['banner_link'], 'modal_title' => $this->storeTranslations['modal_title'], 'modal_subtitle' => $this->storeTranslations['modal_subtitle'], - 'modal_how_to' => $this->storeTranslations['modal_how_to'], 'modal_step_1' => $this->storeTranslations['modal_step_1'], 'modal_step_2' => $this->storeTranslations['modal_step_2'], 'modal_step_3' => $this->storeTranslations['modal_step_3'], diff --git a/src/Notification/CoreNotification.php b/src/Notification/CoreNotification.php index 56441f1a1..7fae948c3 100644 --- a/src/Notification/CoreNotification.php +++ b/src/Notification/CoreNotification.php @@ -60,7 +60,7 @@ public function getSdkInstance(): Sdk $integratorId = $this->store->getIntegratorId(); $accessToken = $this->seller->getCredentialsAccessToken(); - return new Sdk($accessToken, $platformId, $productId, $integratorId, $this->seller->getCredentialsPublicKey()); + return new Sdk($accessToken, $platformId, $productId, $integratorId); } /** diff --git a/src/Transactions/AbstractTransaction.php b/src/Transactions/AbstractTransaction.php index 8584c2b65..91d41bb4c 100644 --- a/src/Transactions/AbstractTransaction.php +++ b/src/Transactions/AbstractTransaction.php @@ -111,7 +111,7 @@ public function getSdkInstance(): Sdk $productId = Device::getDeviceProductId(); $integratorId = $this->mercadopago->storeConfig->getIntegratorId(); - return new Sdk($accessToken, $platformId, $productId, $integratorId, $this->mercadopago->sellerConfig->getCredentialsPublicKey()); + return new Sdk($accessToken, $platformId, $productId, $integratorId); } /** diff --git a/src/WoocommerceMercadoPago.php b/src/WoocommerceMercadoPago.php index bf783bb8a..f2bd92128 100644 --- a/src/WoocommerceMercadoPago.php +++ b/src/WoocommerceMercadoPago.php @@ -31,7 +31,7 @@ class WoocommerceMercadoPago /** * @const */ - private const PLUGIN_VERSION = '7.3.4'; + private const PLUGIN_VERSION = '7.3.5'; /** * @const diff --git a/woocommerce-mercadopago.php b/woocommerce-mercadopago.php index bfd4fd0b7..fea9e0485 100644 --- a/woocommerce-mercadopago.php +++ b/woocommerce-mercadopago.php @@ -4,7 +4,7 @@ * Plugin Name: Mercado Pago * Plugin URI: https://github.com/mercadopago/cart-woocommerce * Description: Configure the payment options and accept payments with cards, ticket and money of Mercado Pago account. - * Version: 7.3.4 + * Version: 7.3.5 * Author: Mercado Pago * Author URI: https://developers.mercadopago.com/ * Text Domain: woocommerce-mercadopago