From db2a61b5c01a0e743ea42af62b77dcb8d060808c Mon Sep 17 00:00:00 2001 From: arti0090 Date: Wed, 16 Oct 2024 19:09:39 +0200 Subject: [PATCH] Fixes after rebase --- assets/shop/js/_visa_mobile.js | 41 ++++++++----------- config/config/sylius_template_events.php | 4 +- config/validation/Pay.xml | 7 ++++ package.json | 3 -- src/Api/Command/PayByVisaMobileHandler.php | 16 +------- .../BankListContextProvider.php | 3 +- src/Form/Type/TpayPaymentDetailsType.php | 4 ++ src/Model/PaymentDetails.php | 1 + .../Api/CreateVisaMobileTransactionAction.php | 5 ++- src/Tpay/PaymentType.php | 2 +- .../shop/cart/complete/_payByLink.html.twig | 2 +- .../shop/cart/complete/_visaMobile.html.twig | 6 +-- .../payment_method.yml | 2 +- .../payment_method.yml | 2 +- .../fixtures/common/payment_method.yaml | 2 +- .../Unit/Api/Command/PayByLinkHandlerTest.php | 6 ++- .../Command/PayByVisaMobileHandlerTest.php | 2 + .../TpayChannelIdEligibilityValidatorTest.php | 8 ++-- translations/messages.en.yaml | 2 + translations/messages.pl.yaml | 2 + translations/validators.en.yaml | 1 - translations/validators.pl.yaml | 1 - 22 files changed, 58 insertions(+), 64 deletions(-) diff --git a/assets/shop/js/_visa_mobile.js b/assets/shop/js/_visa_mobile.js index e4b30db9..ad6d88e9 100644 --- a/assets/shop/js/_visa_mobile.js +++ b/assets/shop/js/_visa_mobile.js @@ -1,26 +1,11 @@ -import 'intl-tel-input/build/css/intlTelInput.css'; - -import intlTelInput from 'intl-tel-input'; - -const inputElement = '#sylius_checkout_complete_tpay_visa_mobile_phone_number'; - -const input = document.querySelector(inputElement); -const locale = input.dataset.locale; - -const iti = intlTelInput(input, { - initialCountry: locale, - strictMode: true, - nationalMode: true, - utilsScript: "/intl-tel-input/js/utils.js?1727952657388", - loadUtilsOnInit: () => import("intl-tel-input/utils"), -}); - document.addEventListener('DOMContentLoaded', () => { + const COUNTRY_CODED_MOBILE_PHONE_LENGTH = 11; + let form = document.querySelector('[name="sylius_checkout_complete"]'); let phoneNumber = form.querySelector('[data-visa-mobile-phone-number]'); form.addEventListener('submit', (event) => { - validateVisaMobilePhoneNumber(); + validateVisaMobilePhoneNumber(phoneNumber); const isValid = form.querySelectorAll('.sylius-validation-error').length === 0; @@ -33,17 +18,23 @@ document.addEventListener('DOMContentLoaded', () => { return; } - phoneNumber.value = iti.getNumber().replace(/\D/g, ''); form.submit(); }); - function validateVisaMobilePhoneNumber() { - if (iti.isValidNumber()) { + function validateVisaMobilePhoneNumber(field) { + let fieldLength = field.value.length; + + if (fieldLength === COUNTRY_CODED_MOBILE_PHONE_LENGTH) { clearErrors(phoneNumber); return; } + if (fieldLength === 0) { + addError(phoneNumber, 'validationErrorRequired'); + return; + } + addError(phoneNumber); } @@ -54,15 +45,15 @@ document.addEventListener('DOMContentLoaded', () => { errorContainer.innerHTML = ''; } - function addError(field) { + function addError(field, validationErrorName = 'validationErrorLength') { const tpayField = field.closest('[data-tpay-field]'); const errorContainer = tpayField.querySelector('[data-tpay-error-container]'); - errorContainer.innerHTML = createErrorElement(field); + errorContainer.innerHTML = createErrorElement(field, validationErrorName); } - function createErrorElement(field) { - const errorMessage = field.dataset.validationError; + function createErrorElement(field, validationErrorName = 'validationErrorLength') { + const errorMessage = field.dataset[validationErrorName]; return `
diff --git a/config/config/sylius_template_events.php b/config/config/sylius_template_events.php index 03a9f736..92b78810 100644 --- a/config/config/sylius_template_events.php +++ b/config/config/sylius_template_events.php @@ -29,11 +29,11 @@ 'template' => '@CommerceWeaversSyliusTpayPlugin/shop/cart/complete/_card.html.twig', 'priority' => 5, ], - 'pay-by-link' => [ + 'pay_by_link' => [ 'template' => '@CommerceWeaversSyliusTpayPlugin/shop/cart/complete/_payByLink.html.twig', 'priority' => 5, ], - 'visa-mobile' => [ + 'visa_mobile' => [ 'template' => '@CommerceWeaversSyliusTpayPlugin/shop/cart/complete/_visaMobile.html.twig', 'priority' => 5, ] diff --git a/config/validation/Pay.xml b/config/validation/Pay.xml index 9f50274b..c867af23 100644 --- a/config/validation/Pay.xml +++ b/config/validation/Pay.xml @@ -41,6 +41,13 @@ + + + + +