Skip to content

Commit

Permalink
Merge pull request #409 from FatchipRobert/MAG2-205-Consumerscore-Gen…
Browse files Browse the repository at this point in the history
…der-Birthday

MAG2-205 - Added guest checkout extension for gender and birthday fields
  • Loading branch information
janteuber authored Jan 27, 2022
2 parents da73f35 + e78b607 commit 7447368
Show file tree
Hide file tree
Showing 19 changed files with 902 additions and 48 deletions.
93 changes: 93 additions & 0 deletions Block/Adminhtml/Config/Form/Field/Label.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Payone\Core\Block\Adminhtml\Config\Form\Field;

class Label extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* Payone Base Helper
*
* @var \Payone\Core\Helper\Base
*/
protected $baseHelper;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Payone\Core\Helper\Base $baseHelper
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Payone\Core\Helper\Base $baseHelper,
array $data = []
) {
parent::__construct($context, $data);
$this->baseHelper = $baseHelper;
}

/**
* Check if inheritance checkbox has to be rendered
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return bool
*/
protected function _isInheritCheckboxRequired(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return false;
}

/**
* Render scope label
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
protected function _renderScopeLabel(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return '';
}

/**
* Determine if label has to be shown
*
* @return bool
*/
protected function showElement()
{
if ($this->baseHelper->getConfigParamByPath("customer/address/dob_show") == "req" && $this->baseHelper->getConfigParamByPath("customer/address/gender_show") == "req") {
return false;
}
return true;
}

/**
* Render element value
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
protected function _renderValue(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$html = '<td class="value">';
$html .= $this->_getElementHtml($element);
if ($element->getComment()) {
$html .= '<span style="color: red;"><strong>' . $element->getComment() . '</strong></span>';
}
$html .= '</td>';
return $html;
}

/**
* Retrieve HTML markup for given form element
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
if ($this->showElement() === false) {
return '';
}
return parent::render($element);
}
}
54 changes: 41 additions & 13 deletions Helper/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,59 @@ public function __construct(
}

/**
* Determine if the customer entered his gender
* Get customer gender
*
* @return bool
* @return string|null
*/
public function customerHasGivenGender()
public function getCustomerGender()
{
$oCustomer = $this->checkoutSession->getQuote()->getCustomer();
if ($oCustomer && $oCustomer->getGender()) {
return true;
$sGender = null;
if (!empty($this->checkoutSession->getPayoneGuestGender())) {
$sGender = $this->checkoutSession->getPayoneGuestGender();
} else {
$oCustomer = $this->checkoutSession->getQuote()->getCustomer();
if ($oCustomer && $oCustomer->getGender()) {
$sGender = $oCustomer->getGender();
}
}

if (!empty($sGender)) {
switch ($sGender) {
case 1:
$sGender = "m";
break;
case 2:
$sGender = "f";
break;
case 3:
$sGender = "d";
break;
}
}
return false;
return $sGender;
}

/**
* Determine if the customer entered his birthday
* Get customer birthday
*
* @return string|bool
* @return string|null
*/
public function getCustomerBirthday()
{
$oCustomer = $this->checkoutSession->getQuote()->getCustomer();
if ($oCustomer && $oCustomer->getDob()) {
return $oCustomer->getDob();
$sBirthday = null;
if (!empty($this->checkoutSession->getPayoneGuestDateofbirth())) {
$sBirthday = $this->checkoutSession->getPayoneGuestDateofbirth();
} else {
$oCustomer = $this->checkoutSession->getQuote()->getCustomer();
if ($oCustomer && $oCustomer->getDob()) {
$sBirthday = $oCustomer->getDob();
}
}

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

/**
Expand Down
11 changes: 10 additions & 1 deletion Model/Api/Request/Consumerscore.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ protected function getCombinedAdressCheckType()
* Send request "addresscheck" to PAYONE server API
*
* @param AddressInterface $oAddress
* @param string $sGender
* @param string $sBirthday
* @return array|bool
*/
public function sendRequest(AddressInterface $oAddress)
public function sendRequest(AddressInterface $oAddress, $sGender = null, $sBirthday = null)
{
if (!$this->isCheckEnabled() || $oAddress->getCountryId() != 'DE') {
return true;
Expand All @@ -114,6 +116,13 @@ public function sendRequest(AddressInterface $oAddress)
$this->addParameter('consumerscoretype', $sType);
$this->addParameter('language', $this->shopHelper->getLocale());

if ($sType == CreditratingCheckType::BONIVERSUM_VERITA && $sGender !== null) {
$this->addParameter('gender', $sGender);
}
if ($sType == CreditratingCheckType::BONIVERSUM_VERITA && $sBirthday !== null) {
$this->addParameter('birthday', $sBirthday);
}

$this->addAddress($oAddress);
if ($this->addressesChecked->wasAddressCheckedBefore($oAddress, $sType,true) === false) {
$aResponse = $this->send();
Expand Down
1 change: 0 additions & 1 deletion Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ protected function getPayoneConfig()
'blockedMessage' => $this->paymentHelper->getBankaccountCheckBlockedMessage(),
'epsBankGroups' => Eps::getBankGroups(),
'idealBankGroups' => Ideal::getBankGroups(),
'customerHasGivenGender' => $this->customerHelper->customerHasGivenGender(),
'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,
Expand Down
Loading

0 comments on commit 7447368

Please sign in to comment.