Skip to content

Commit

Permalink
MAG2-301 - Fixed birthday fields for safe invoice, extended validation
Browse files Browse the repository at this point in the history
  • Loading branch information
FatchipRobert committed Mar 1, 2024
1 parent c15511b commit c70d039
Showing 1 changed file with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit c70d039

Please sign in to comment.