From e37af15804e58feea97f4a70278cc6086077ae5a Mon Sep 17 00:00:00 2001 From: Adam Wysocki Date: Thu, 28 Nov 2024 12:34:54 +0100 Subject: [PATCH] Fix channel choice error button behaviour --- _dev/js/_partials/gateways.ts | 23 ++++++++++++++--------- views/js/main.min.js | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/_dev/js/_partials/gateways.ts b/_dev/js/_partials/gateways.ts index 23fb0b3..5b8fb42 100755 --- a/_dev/js/_partials/gateways.ts +++ b/_dev/js/_partials/gateways.ts @@ -51,15 +51,20 @@ export function validateSelectedTransfer(gateways_wrapper: HTMLDivElement) { } function switchButton(checked: boolean, btn: HTMLButtonElement, req: HTMLInputElement, errorMsg) { - if (!checked || !req.checked) { - errorMsg.style.display = 'block' - btn.disabled = true - btn.classList.add('disabled') - } else { - errorMsg.style.display = 'none' - btn.disabled = false - btn.classList.remove('disabled') - } + if (!checked || !req.checked) { + if (!checked) { + errorMsg.style.display = 'block' + } else { + errorMsg.style.display = 'none' + } + + btn.disabled = true + btn.classList.add('disabled') + } else { + errorMsg.style.display = 'none' + btn.disabled = false + btn.classList.remove('disabled') + } } export function addTpaySupercheckoutValidator() { diff --git a/views/js/main.min.js b/views/js/main.min.js index 839aaf3..c38d10f 100755 --- a/views/js/main.min.js +++ b/views/js/main.min.js @@ -1,2 +1,2 @@ /*! For license information please see main.min.js.LICENSE.txt */ -!function(){"use strict";!function(){const e=document.querySelector('input[name="conditions_to_approve[terms-and-conditions]"]');e&&e.addEventListener("click",(()=>{t(e)}));const t=e=>e.checked;function n(){window.localStorage.removeItem("tpay_blik_addepts")}const o=(e,t)=>{const n=r(e);n.style.display=t&&n?"block":"none"},r=e=>{const t=i(e);return document.querySelector(t+" .tpay-preload")},a=e=>{const t=i(e);return document.querySelector(t+" .tpay-blik-response")},i=e=>"use"===e?".tpay-blik--use":".tpay-blik--new";function c(e){return e.ok||alert(e.statusText),e}const l={"Content-Type":"application/x-www-form-urlencoded"};function s(e,t,n,o){let r,i=o;const c=null!=blik_limit_attempt_msg?blik_limit_attempt_msg:"",l=null!=blik_accept_msg?blik_accept_msg:"",y=null!=blik_msg?blik_msg:"",m={action:"assignTransactionId",ajax:!0,cartId:n.cartId,transactionId:t};p(e,m).then((e=>{try{let t,{status:o,payments:s,cartId:p}=e,m=a(n.blikOption);if(t=!0,"pending"===o||"error"===o){if(s.attempts&&(m.innerHTML=l,m.classList.add("tpay-blik-response--open")),s.attempts&&0!==s.attempts.length){let o=s.attempts.length-1,a=s.attempts[o].paymentErrorCode;a&&y&&"63"!==a?(m.innerHTML=y[a],m.classList.add("tpay-blik-response--open"),t=d(r,n),u(e,a)):(m.innerHTML=l,m.classList.add("tpay-blik-response--open"))}i>40&&(m.innerHTML=c,m.classList.add("tpay-blik-response--open"),t=d(r,n),u(e,-1))}return"success"===o&&(t=d(r,n),u(e)),t}catch(e){console.log(e)}})).then((o=>{o&&(r=setTimeout((()=>{s(e,t,n,i+1)}),3e3))}))}function d(e,t){return clearInterval(e),o(t.blikOption,!1),!1}function u(e,t=0){0===t?window.location.href=e.backUrl:n()}function p(e,t){const n={method:"POST",headers:l,body:new URLSearchParams(t)};return fetch(e,n).then(c).then((e=>e.json()))}function y(){const e=document.querySelector("#tpay-blik-form"),t=document.querySelector("input[name=cart_id]"),r=document.querySelector("#payment-confirmation button");if(e){const a=e.action,i={blikOption:"new",ajax:!0,cartId:parseInt(t.value)};e.addEventListener("keydown",(e=>{"Enter"===e.key&&e.preventDefault()})),r.addEventListener("click",(t=>{var r=e.parentElement.parentElement;if("none"===window.getComputedStyle(r).display)return;t.preventDefault(),t.stopPropagation();const s=document.querySelector("#blik_code"),d=document.querySelector(".tpay-radio-payments__radio--active input[name=blikOption]");let u=JSON.parse(window.localStorage.getItem("tpay_blik_addepts"));u&&4===u.attempt&&n();let p="createTransaction";if(u&&4!==u.attempt&&i.cartId==u.cart_id&&(p="createTransactionById"),i.action=p,i.blikOption=d.value,null!=u&&null!=u.transaction_id&&(i.transactionId=u.transaction_id),"use"===d.value){if(!k(s,s.value))return!1;i.blikCode=""}else if("new"===d.value){if(!k(s,s.value))return!1;i.blikCode=s.value}if(i)if(o(i.blikOption,!0),"createTransaction"===p)(function(e,t){const n={method:"POST",headers:l,body:new URLSearchParams(t)};return fetch(e,n).then(c).then((e=>e.json())).then((e=>e))})(a,i).then((e=>{if("success"===e.transaction.result){let t=e.transaction.transactionId;m(a,t,i)}}));else{let e=u.transaction_id;m(a,e,i)}}),!1),function(){const e=document.querySelector('#conditions-to-approve input[type="checkbox"]'),t=document.querySelector(".tpay-blik-input");null==e||e.addEventListener("click",(()=>{f()})),null==t||t.addEventListener("change",(()=>{f()}))}()}}function m(e,t,n){return r=this,i=null,c=function*(){var r,i,c,l;let d;const u={action:"createTransactionById",ajax:!0,transactionId:t,blikCode:n.blikCode},y=yield p(e,u),m=y.transaction.status,f=null==(r=y.response)?void 0:r.payments,k=(null==(l=null==(c=null==(i=y.response)?void 0:i.payments)?void 0:c.errors)?void 0:l.length)||0;let b,v=a(n.blikOption);if(b=!0,"failed"===m&&(console.log(k),v.innerHTML="failed",v.classList.add("tpay-blik-response--open"),clearInterval(d),o(n.blikOption,!1),b=!1),"pending"===m&&k>0){let e;!function(e){window.localStorage.setItem("tpay_blik_addepts",JSON.stringify(e))}({transaction_id:t,cart_id:n.cartId,attempt:y.transaction.payments.attempts.length});const r=null!=messages?messages:null;for(const t in f.errors)e="payment_failed"===f.errors[t].errorCode?null==r?void 0:r.blik_error:null==r?void 0:r.payment_error,v.innerHTML=e,v.classList.add("tpay-blik-response--open");clearInterval(d),o(n.blikOption,!1),b=!1}"correct"===m&&(clearInterval(d),o(n.blikOption,!1),window.location.href=y.backUrl,b=!1),b&&s(e,t,n,1)},new Promise(((e,t)=>{var n=e=>{try{a(c.next(e))}catch(e){t(e)}},o=e=>{try{a(c.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(n,o);a((c=c.apply(r,i)).next())}));var r,i,c}function f(){const e=document.querySelector(".tpay-blik-input"),t=document.querySelectorAll(".tpay-blik-response");document.querySelector("input[name=savedId]");if(!k(e,e.value))return!1;t.forEach((e=>{e.classList.remove("tpay-blik-response--open")})),e.classList.remove("wrong")}function k(e,n){let o;const r=document.querySelector(".tpay-blik--new .tpay-blik-response"),a=document.querySelector('input[name="conditions_to_approve[terms-and-conditions]"]'),i=(document.querySelector("#conditions-to-approve .custom-checkbox > span"),document.querySelector("#blik-rr"));i.style.display="none";const c=document.querySelector(".blikId"),l=document.querySelector("#blikUse");return!1===t(a)?(i.style.display="block",e.classList.remove("wrong"),r.classList.remove("tpay-blik-response--open"),o=!1):/^[0-9]{3}[0-9]{3}$/.test(n)||null!==c&&l&&!0===l.checked?(e.classList.remove("wrong"),r.classList.remove("tpay-blik-response--open"),o=!0):(e.classList.add("wrong"),r.classList.add("tpay-blik-response--open"),o=!1),o}function b(e){let t=!1;const n=document.querySelector('input[name="conditions_to_approve[terms-and-conditions]"]'),o=document.querySelector("#payment-confirmation button"),r=Array.from(document.querySelectorAll("[id^=payment-option]")).find((e=>e.checked)).id,a=document.querySelector("#pay-with-"+r+"-form"),i=null==a?void 0:a.querySelectorAll(".tpay-payment-gateways__item input").length;if(i){const e=a.querySelectorAll("input[name=tpay_transfer_id]"),n=a.querySelectorAll("input[name=tpay_channel_id]");t=void 0!==Array.from(e).find((e=>e.checked)),t||(t=void 0!==Array.from(n).find((e=>e.checked)))}i>0&&setTimeout((()=>{!function(e,t,n,o){e&&n.checked?(o.style.display="none",t.disabled=!1,t.classList.remove("disabled")):(o.style.display="block",t.disabled=!0,t.classList.add("disabled"))}(t,o,n,a.querySelector(".transfer-error"))}),50)}function v(e){return new Promise(((t,n)=>{let o=document.querySelector(e);o?t(o):new MutationObserver(((n,o)=>{Array.from(document.querySelectorAll(e)).forEach((e=>{t(e),o.disconnect()}))})).observe(document.documentElement,{childList:!0,subtree:!0})}))}function h(){return null!==document.getElementById("supercheckout_confirm_order")}!function(){const e=document.querySelector("#blik_code"),t=document.querySelector(".tpay-blik--new .tpay-blik-response");e&&e.addEventListener("click",(function(n){e.classList.remove("wrong"),t.classList.remove("tpay-blik-response--open")}))}(),v("#tpay-blik-form").then((()=>{y()})),v(".tpay-payment-gateways").then((()=>{!function(){const e=document.querySelectorAll(".tpay-payment-gateways");e.length>0&&e.forEach((function(e){e.parentNode.parentNode.nextElementSibling;const t=Array.from(e.querySelectorAll(".tpay-payment-gateways__item"));if(t)for(const e of t)e.addEventListener("click",(()=>{b(),t.forEach((e=>{e.classList.remove("tpay-payment-gateways__item--active")})),e.classList.add("tpay-payment-gateways__item--active")}),!1)}))}(),h&&"function"==typeof window.addSupercheckoutOrderValidator&&window.addSupercheckoutOrderValidator((function(){if(!document.querySelector(".tpay-payment-gateways").closest("li").querySelector("input[type=radio]").checked)return!0;const e=document.querySelectorAll(".tpay-payment-gateways input[type=radio]");if(Array.from(e).some((e=>e.checked)))return!0;throw window.scrollTo({top:0,behavior:"smooth"}),new Error("Wybierz metodę płatności")}))})),function(){const e=Array.from(document.querySelectorAll("input[id^=payment-option]"));Array.from(e).forEach((function(e){e.addEventListener("click",(()=>{}))}))}();!function(){const e=document.querySelectorAll(".tpay-radio-payments__radio");Array.from(e).forEach((t=>{t.addEventListener("click",(n=>{e.forEach((e=>{e.classList.remove("tpay-radio-payments__radio--active")})),t.classList.add("tpay-radio-payments__radio--active"),t.querySelector("input[type=radio]").checked=!0}))}))}(),function(){const e=document.querySelector('#conditions-to-approve input[type="checkbox"]');e&&e.addEventListener("change",(()=>{var e;b(null==(e=document.querySelector(".tpay-payment-gateways__item--active"))||e.closest(".tpay-payment-gateways"))}));document.querySelectorAll('[name="payment-option"]').forEach((function(e){e.addEventListener("change",(()=>{var e;b(null==(e=document.querySelector(".tpay-payment-gateways__item--active"))||e.closest(".tpay-payment-gateways"))}))}))}()}()}(); \ No newline at end of file +!function(){"use strict";!function(){const e=document.querySelector('input[name="conditions_to_approve[terms-and-conditions]"]');e&&e.addEventListener("click",(()=>{t(e)}));const t=e=>e.checked;function n(){window.localStorage.removeItem("tpay_blik_addepts")}const o=(e,t)=>{const n=r(e);n.style.display=t&&n?"block":"none"},r=e=>{const t=i(e);return document.querySelector(t+" .tpay-preload")},a=e=>{const t=i(e);return document.querySelector(t+" .tpay-blik-response")},i=e=>"use"===e?".tpay-blik--use":".tpay-blik--new";function c(e){return e.ok||alert(e.statusText),e}const l={"Content-Type":"application/x-www-form-urlencoded"};function s(e,t,n,o){let r,i=o;const c=null!=blik_limit_attempt_msg?blik_limit_attempt_msg:"",l=null!=blik_accept_msg?blik_accept_msg:"",y=null!=blik_msg?blik_msg:"",m={action:"assignTransactionId",ajax:!0,cartId:n.cartId,transactionId:t};p(e,m).then((e=>{try{let t,{status:o,payments:s,cartId:p}=e,m=a(n.blikOption);if(t=!0,"pending"===o||"error"===o){if(s.attempts&&(m.innerHTML=l,m.classList.add("tpay-blik-response--open")),s.attempts&&0!==s.attempts.length){let o=s.attempts.length-1,a=s.attempts[o].paymentErrorCode;a&&y&&"63"!==a?(m.innerHTML=y[a],m.classList.add("tpay-blik-response--open"),t=d(r,n),u(e,a)):(m.innerHTML=l,m.classList.add("tpay-blik-response--open"))}i>40&&(m.innerHTML=c,m.classList.add("tpay-blik-response--open"),t=d(r,n),u(e,-1))}return"success"===o&&(t=d(r,n),u(e)),t}catch(e){console.log(e)}})).then((o=>{o&&(r=setTimeout((()=>{s(e,t,n,i+1)}),3e3))}))}function d(e,t){return clearInterval(e),o(t.blikOption,!1),!1}function u(e,t=0){0===t?window.location.href=e.backUrl:n()}function p(e,t){const n={method:"POST",headers:l,body:new URLSearchParams(t)};return fetch(e,n).then(c).then((e=>e.json()))}function y(){const e=document.querySelector("#tpay-blik-form"),t=document.querySelector("input[name=cart_id]"),r=document.querySelector("#payment-confirmation button");if(e){const a=e.action,i={blikOption:"new",ajax:!0,cartId:parseInt(t.value)};e.addEventListener("keydown",(e=>{"Enter"===e.key&&e.preventDefault()})),r.addEventListener("click",(t=>{var r=e.parentElement.parentElement;if("none"===window.getComputedStyle(r).display)return;t.preventDefault(),t.stopPropagation();const s=document.querySelector("#blik_code"),d=document.querySelector(".tpay-radio-payments__radio--active input[name=blikOption]");let u=JSON.parse(window.localStorage.getItem("tpay_blik_addepts"));u&&4===u.attempt&&n();let p="createTransaction";if(u&&4!==u.attempt&&i.cartId==u.cart_id&&(p="createTransactionById"),i.action=p,i.blikOption=d.value,null!=u&&null!=u.transaction_id&&(i.transactionId=u.transaction_id),"use"===d.value){if(!k(s,s.value))return!1;i.blikCode=""}else if("new"===d.value){if(!k(s,s.value))return!1;i.blikCode=s.value}if(i)if(o(i.blikOption,!0),"createTransaction"===p)(function(e,t){const n={method:"POST",headers:l,body:new URLSearchParams(t)};return fetch(e,n).then(c).then((e=>e.json())).then((e=>e))})(a,i).then((e=>{if("success"===e.transaction.result){let t=e.transaction.transactionId;m(a,t,i)}}));else{let e=u.transaction_id;m(a,e,i)}}),!1),function(){const e=document.querySelector('#conditions-to-approve input[type="checkbox"]'),t=document.querySelector(".tpay-blik-input");null==e||e.addEventListener("click",(()=>{f()})),null==t||t.addEventListener("change",(()=>{f()}))}()}}function m(e,t,n){return r=this,i=null,c=function*(){var r,i,c,l;let d;const u={action:"createTransactionById",ajax:!0,transactionId:t,blikCode:n.blikCode},y=yield p(e,u),m=y.transaction.status,f=null==(r=y.response)?void 0:r.payments,k=(null==(l=null==(c=null==(i=y.response)?void 0:i.payments)?void 0:c.errors)?void 0:l.length)||0;let b,v=a(n.blikOption);if(b=!0,"failed"===m&&(console.log(k),v.innerHTML="failed",v.classList.add("tpay-blik-response--open"),clearInterval(d),o(n.blikOption,!1),b=!1),"pending"===m&&k>0){let e;!function(e){window.localStorage.setItem("tpay_blik_addepts",JSON.stringify(e))}({transaction_id:t,cart_id:n.cartId,attempt:y.transaction.payments.attempts.length});const r=null!=messages?messages:null;for(const t in f.errors)e="payment_failed"===f.errors[t].errorCode?null==r?void 0:r.blik_error:null==r?void 0:r.payment_error,v.innerHTML=e,v.classList.add("tpay-blik-response--open");clearInterval(d),o(n.blikOption,!1),b=!1}"correct"===m&&(clearInterval(d),o(n.blikOption,!1),window.location.href=y.backUrl,b=!1),b&&s(e,t,n,1)},new Promise(((e,t)=>{var n=e=>{try{a(c.next(e))}catch(e){t(e)}},o=e=>{try{a(c.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(n,o);a((c=c.apply(r,i)).next())}));var r,i,c}function f(){const e=document.querySelector(".tpay-blik-input"),t=document.querySelectorAll(".tpay-blik-response");document.querySelector("input[name=savedId]");if(!k(e,e.value))return!1;t.forEach((e=>{e.classList.remove("tpay-blik-response--open")})),e.classList.remove("wrong")}function k(e,n){let o;const r=document.querySelector(".tpay-blik--new .tpay-blik-response"),a=document.querySelector('input[name="conditions_to_approve[terms-and-conditions]"]'),i=(document.querySelector("#conditions-to-approve .custom-checkbox > span"),document.querySelector("#blik-rr"));i.style.display="none";const c=document.querySelector(".blikId"),l=document.querySelector("#blikUse");return!1===t(a)?(i.style.display="block",e.classList.remove("wrong"),r.classList.remove("tpay-blik-response--open"),o=!1):/^[0-9]{3}[0-9]{3}$/.test(n)||null!==c&&l&&!0===l.checked?(e.classList.remove("wrong"),r.classList.remove("tpay-blik-response--open"),o=!0):(e.classList.add("wrong"),r.classList.add("tpay-blik-response--open"),o=!1),o}function b(e){let t=!1;const n=document.querySelector('input[name="conditions_to_approve[terms-and-conditions]"]'),o=document.querySelector("#payment-confirmation button"),r=Array.from(document.querySelectorAll("[id^=payment-option]")).find((e=>e.checked)).id,a=document.querySelector("#pay-with-"+r+"-form"),i=null==a?void 0:a.querySelectorAll(".tpay-payment-gateways__item input").length;if(i){const e=a.querySelectorAll("input[name=tpay_transfer_id]"),n=a.querySelectorAll("input[name=tpay_channel_id]");t=void 0!==Array.from(e).find((e=>e.checked)),t||(t=void 0!==Array.from(n).find((e=>e.checked)))}i>0&&setTimeout((()=>{!function(e,t,n,o){e&&n.checked?(o.style.display="none",t.disabled=!1,t.classList.remove("disabled")):(o.style.display=e?"none":"block",t.disabled=!0,t.classList.add("disabled"))}(t,o,n,a.querySelector(".transfer-error"))}),50)}function v(e){return new Promise(((t,n)=>{let o=document.querySelector(e);o?t(o):new MutationObserver(((n,o)=>{Array.from(document.querySelectorAll(e)).forEach((e=>{t(e),o.disconnect()}))})).observe(document.documentElement,{childList:!0,subtree:!0})}))}function h(){return null!==document.getElementById("supercheckout_confirm_order")}!function(){const e=document.querySelector("#blik_code"),t=document.querySelector(".tpay-blik--new .tpay-blik-response");e&&e.addEventListener("click",(function(n){e.classList.remove("wrong"),t.classList.remove("tpay-blik-response--open")}))}(),v("#tpay-blik-form").then((()=>{y()})),v(".tpay-payment-gateways").then((()=>{!function(){const e=document.querySelectorAll(".tpay-payment-gateways");e.length>0&&e.forEach((function(e){e.parentNode.parentNode.nextElementSibling;const t=Array.from(e.querySelectorAll(".tpay-payment-gateways__item"));if(t)for(const e of t)e.addEventListener("click",(()=>{b(),t.forEach((e=>{e.classList.remove("tpay-payment-gateways__item--active")})),e.classList.add("tpay-payment-gateways__item--active")}),!1)}))}(),h&&"function"==typeof window.addSupercheckoutOrderValidator&&window.addSupercheckoutOrderValidator((function(){if(!document.querySelector(".tpay-payment-gateways").closest("li").querySelector("input[type=radio]").checked)return!0;const e=document.querySelectorAll(".tpay-payment-gateways input[type=radio]");if(Array.from(e).some((e=>e.checked)))return!0;throw window.scrollTo({top:0,behavior:"smooth"}),new Error("Wybierz metodę płatności")}))})),function(){const e=Array.from(document.querySelectorAll("input[id^=payment-option]"));Array.from(e).forEach((function(e){e.addEventListener("click",(()=>{}))}))}();!function(){const e=document.querySelectorAll(".tpay-radio-payments__radio");Array.from(e).forEach((t=>{t.addEventListener("click",(n=>{e.forEach((e=>{e.classList.remove("tpay-radio-payments__radio--active")})),t.classList.add("tpay-radio-payments__radio--active"),t.querySelector("input[type=radio]").checked=!0}))}))}(),function(){const e=document.querySelector('#conditions-to-approve input[type="checkbox"]');e&&e.addEventListener("change",(()=>{var e;b(null==(e=document.querySelector(".tpay-payment-gateways__item--active"))||e.closest(".tpay-payment-gateways"))}));document.querySelectorAll('[name="payment-option"]').forEach((function(e){e.addEventListener("change",(()=>{var e;b(null==(e=document.querySelector(".tpay-payment-gateways__item--active"))||e.closest(".tpay-payment-gateways"))}))}))}()}()}(); \ No newline at end of file