Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAG2-301 - Fixed birthday fields for safe invoice, extended validation #531

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading