From c70d039ec7b51733325418a1229783725a68e29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 1 Mar 2024 12:30:12 +0100 Subject: [PATCH 1/2] MAG2-301 - Fixed birthday fields for safe invoice, extended validation --- .../method-renderer/safe_invoice-method.js | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/safe_invoice-method.js b/view/frontend/web/js/view/payment/method-renderer/safe_invoice-method.js index 377a6c7a..83235bc1 100644 --- a/view/frontend/web/js/view/payment/method-renderer/safe_invoice-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/safe_invoice-method.js @@ -48,36 +48,62 @@ define( isB2bMode: function () { if (quote.billingAddress() !== null && typeof quote.billingAddress().company !== 'undefined' && - quote.billingAddress().company !== '' + quote.billingAddress().company !== '' && + quote.billingAddress().company !== null ) { return true; } return false; }, requestBirthday: function () { - if (window.checkoutConfig.payment.payone.customerBirthday === false && !this.isB2bMode()) { + if (!window.checkoutConfig.payment.payone.customerBirthday && !this.isB2bMode()) { return true; } return false; }, - isCustomerTooYoung: function () { - if (window.checkoutConfig.payment.payone.customerBirthday !== false) { - var sBirthDate = window.checkoutConfig.payment.payone.customerBirthday; - } else { - var sBirthDate = this.birthyear() + "-" + this.birthmonth() + "-" + this.birthday(); + getBirthDate: function () { + if (window.checkoutConfig.payment.payone.customerBirthday) { + return window.checkoutConfig.payment.payone.customerBirthday; } - var oBirthDate = new Date(sBirthDate); + return this.birthyear() + "-" + this.birthmonth() + "-" + this.birthday(); + }, + isCustomerTooYoung: function () { + var oBirthDate = new Date(this.getBirthDate()); var oMinDate = new Date(new Date().setYear(new Date().getFullYear() - 18)); if(oBirthDate < oMinDate) { return false; } return true; }, + isCustomerTooOld: function () { + var oBirthDate = new Date(this.getBirthDate()); + var oMinDate = new Date(new Date().setYear(new Date().getFullYear() - 126)); // max 125 years old + if(oBirthDate > oMinDate) { + return false; + } + return true; + }, + isDateInFuture: function () { + var oBirthDate = new Date(this.getBirthDate()); + var oDateNow = new Date(); + if (oBirthDate > oDateNow) { + return true; + } + return false; + }, validate: function () { + if (!this.isB2bMode() && this.isDateInFuture()) { + this.messageContainer.addErrorMessage({'message': $t('Please enter a valid birthday.')}); + return false; + } if (!this.isB2bMode() && this.isCustomerTooYoung()) { this.messageContainer.addErrorMessage({'message': $t('You have to be at least 18 years old to use this payment type!')}); return false; } + if (!this.isB2bMode() && this.isCustomerTooOld()) { + this.messageContainer.addErrorMessage({'message': $t('You can not be older than 125 years to use this payment type!')}); + return false; + } return true; }, getData: function () { From 8d00d0a0b5c075246bf2fa7f26d14ff0de8ccbc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 13 Mar 2024 13:23:19 +0100 Subject: [PATCH 2/2] MAG2-301 - Changed validation, added missing translations --- i18n/de_DE.csv | 2 ++ .../method-renderer/safe_invoice-method.js | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index b09145d6..3c6b4489 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -1068,6 +1068,8 @@ "Show IBAN/BIC fields","IBAN/BIC Felder anzeigen" "You have to be at least 18 years old to use this payment type!","Sie müssen mindestens 18 Jahre alt sein um diese Zahlart nutzen zu können!" +"An error occured. Please check the supplied data.","Ein Fehler ist aufgetreten. Bitte überprüfen Sie Ihre Angaben." +"Please enter a valid birthdate.","Bitte geben Sie ein gültiges Geburtsdatum ein." "I agree with the transmission of the necessary data to Unzer which is needed for processing the purchase, the identity-check and the credit rating.","Mit der Übermittlung der für die Abwicklung des Rechnungskaufes und einer Identitätsprüfung und Bonitätsprüfung erforderlicher Daten an Unzer bin ich einverstanden." "I agree with the transmission of the necessary data to Klarna which is needed for processing the purchase, the identity-check and the credit rating.","Mit der Übermittlung der für die Abwicklung des Rechnungskaufes und einer Identitätsprüfung und Bonitätsprüfung erforderlicher Daten an Klarna bin ich einverstanden." diff --git a/view/frontend/web/js/view/payment/method-renderer/safe_invoice-method.js b/view/frontend/web/js/view/payment/method-renderer/safe_invoice-method.js index 83235bc1..f45b2f21 100644 --- a/view/frontend/web/js/view/payment/method-renderer/safe_invoice-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/safe_invoice-method.js @@ -77,7 +77,7 @@ define( }, isCustomerTooOld: function () { var oBirthDate = new Date(this.getBirthDate()); - var oMinDate = new Date(new Date().setYear(new Date().getFullYear() - 126)); // max 125 years old + var oMinDate = new Date(new Date().setYear(new Date().getFullYear() - 125)); // max 125 years if(oBirthDate > oMinDate) { return false; } @@ -91,9 +91,21 @@ define( } return false; }, + isDateInvalid: function () { + if (!this.birthyear() || isNaN(this.birthyear()) || this.birthyear().length != 4) { + return true; + } + if (!this.birthmonth() || isNaN(this.birthmonth()) || parseInt(this.birthmonth()) < 1 || parseInt(this.birthmonth()) > 12) { + return true; + } + if (!this.birthday() || isNaN(this.birthday()) || parseInt(this.birthday()) < 1 || parseInt(this.birthday()) > 31) { + return true; + } + return false; + }, validate: function () { - if (!this.isB2bMode() && this.isDateInFuture()) { - this.messageContainer.addErrorMessage({'message': $t('Please enter a valid birthday.')}); + if (!this.isB2bMode() && (this.isDateInvalid() || this.isDateInFuture())) { + this.messageContainer.addErrorMessage({'message': $t('Please enter a valid birthdate.')}); return false; } if (!this.isB2bMode() && this.isCustomerTooYoung()) { @@ -101,7 +113,7 @@ define( return false; } if (!this.isB2bMode() && this.isCustomerTooOld()) { - this.messageContainer.addErrorMessage({'message': $t('You can not be older than 125 years to use this payment type!')}); + this.messageContainer.addErrorMessage({'message': $t('An error occured. Please check the supplied data.')}); return false; } return true;