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 377a6c7a..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 @@ -48,36 +48,74 @@ 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() - 125)); // max 125 years + 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; + }, + 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.isDateInvalid() || this.isDateInFuture())) { + this.messageContainer.addErrorMessage({'message': $t('Please enter a valid birthdate.')}); + 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('An error occured. Please check the supplied data.')}); + return false; + } return true; }, getData: function () {