Skip to content

Commit

Permalink
Merge pull request #531 from FatchipRobert/MAG2-301-Safe-Invoice-Birt…
Browse files Browse the repository at this point in the history
…hday

MAG2-301 - Fixed birthday fields for safe invoice, extended validation
  • Loading branch information
janteuber authored Mar 14, 2024
2 parents f4d50ff + 8d00d0a commit 83a9254
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
2 changes: 2 additions & 0 deletions i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 83a9254

Please sign in to comment.