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-323 - Fixed problems with birthdate validation and usage in safe… #563

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
1 change: 0 additions & 1 deletion Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ protected function getPayoneConfig()
'bankCodeValidatedAndValid' => false,
'blockedMessage' => $this->paymentHelper->getBankaccountCheckBlockedMessage(),
'epsBankGroups' => Eps::getBankGroups(),
'customerBirthday' => $this->customerHelper->getCustomerBirthday(),
'addresscheckEnabled' => (int)$this->requestHelper->getConfigParam('enabled', 'address_check', 'payone_protect'),
'addresscheckBillingEnabled' => $this->requestHelper->getConfigParam('check_billing', 'address_check', 'payone_protect') == 'NO' ? 0 : 1,
'addresscheckShippingEnabled' => $this->requestHelper->getConfigParam('check_shipping', 'address_check', 'payone_protect') == 'NO' ? 0 : 1,
Expand Down
31 changes: 24 additions & 7 deletions Model/Methods/SafeInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ public function __construct(
$this->paymentBan = $paymentBan;
}

/**
* @param Order $oOrder
* @return string|false
*/
protected function getBirthday(Order $oOrder)
{
$sDob = false;
if (!empty($oOrder->getCustomerDob())) {
$sDob = $oOrder->getCustomerDob();
} elseif (!empty($this->getInfoInstance()->getAdditionalInformation('dob'))) {
$sDob = $this->getInfoInstance()->getAdditionalInformation('dob');
}

if (!empty($sDob)) {
$iDobTime = strtotime($sDob);
if ($iDobTime !== false) {
$sDob = date('Ymd', $iDobTime);
}
}
return $sDob;
}

/**
* Return parameters specific to this payment type
*
Expand All @@ -129,7 +151,7 @@ public function getPaymentSpecificParameters(Order $oOrder)
{
$aParams = ['clearingsubtype' => 'POV'];

$sDob = $this->getInfoInstance()->getAdditionalInformation('dob');
$sDob = $this->getBirthday($oOrder);
if ($sDob) {
$aParams['birthday'] = $sDob;
}
Expand Down Expand Up @@ -157,11 +179,7 @@ protected function getFormattedBirthday(DataObject $data)
$sBirthmonth = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthmonth');
$sBirthyear = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthyear');
if ($sBirthday && $sBirthmonth && $sBirthyear) {
$sDob = $sBirthyear.'-'.$sBirthmonth.'-'.$sBirthday;
$iDobTime = strtotime($sDob);
if ($iDobTime !== false) {
$sFormattedDob = date('Ymd', $iDobTime);
}
$sFormattedDob = $sBirthyear.'-'.$sBirthmonth.'-'.$sBirthday;
}
return $sFormattedDob;
}
Expand All @@ -181,7 +199,6 @@ public function assignData(DataObject $data)
$oInfoInstance = $this->getInfoInstance();
$oInfoInstance->setAdditionalInformation('dob', $sFormattedDob);
}

return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ define(
[
'Payone_Core/js/view/payment/method-renderer/base',
'mage/translate',
'Magento_Checkout/js/model/quote'
'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer'
],
function (Component, $t, quote) {
function (Component, $t, quote, customer) {
'use strict';
return Component.extend({
defaults: {
Expand Down Expand Up @@ -56,15 +57,12 @@ define(
return false;
},
requestBirthday: function () {
if (!window.checkoutConfig.payment.payone.customerBirthday && !this.isB2bMode()) {
if ((customer.customerData.dob == undefined || customer.customerData.dob === null) && !this.isB2bMode()) {
return true;
}
return false;
},
getBirthDate: function () {
if (window.checkoutConfig.payment.payone.customerBirthday) {
return window.checkoutConfig.payment.payone.customerBirthday;
}
return this.birthyear() + "-" + this.birthmonth() + "-" + this.birthday();
},
isCustomerTooYoung: function () {
Expand All @@ -91,28 +89,16 @@ 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.isDateInvalid() || this.isDateInFuture())) {
if (this.requestBirthday() === true && (this.isDateValid(this.birthyear(), this.birthmonth(), this.birthday()) === false || this.isDateInFuture())) {
this.messageContainer.addErrorMessage({'message': $t('Please enter a valid birthdate.')});
return false;
}
if (!this.isB2bMode() && this.isCustomerTooYoung()) {
if (this.requestBirthday() === true && 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()) {
if (this.requestBirthday() === true && this.isCustomerTooOld()) {
this.messageContainer.addErrorMessage({'message': $t('An error occured. Please check the supplied data.')});
return false;
}
Expand All @@ -123,9 +109,11 @@ define(
if (parentReturn.additional_data === null) {
parentReturn.additional_data = {};
}
parentReturn.additional_data.birthday = this.birthday();
parentReturn.additional_data.birthmonth = this.birthmonth();
parentReturn.additional_data.birthyear = this.birthyear();
if (this.requestBirthday() === true) {
parentReturn.additional_data.birthday = this.birthday();
parentReturn.additional_data.birthmonth = this.birthmonth();
parentReturn.additional_data.birthyear = this.birthyear();
}
return parentReturn;
},
/** Returns payment method instructions */
Expand Down
Loading