We will be off on April 7th (Monday) for public holiday in our country

Commit 2eacd3e0 authored by attilak's avatar attilak

Remove trait and move to abstract class

Remove code duplications
parent e2c2c46a
......@@ -20,11 +20,56 @@
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Observer;
trait AdyenObserverTrait
use Magento\Framework\DataObject;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
abstract class AdyenAbstractDataAssignObserver extends AbstractDataAssignObserver
{
const BRAND_CODE = 'brand_code';
const STATE_DATA = 'state_data';
const BROWSER_INFO = 'browserInfo';
const PAYMENT_METHOD = 'paymentMethod';
const RISK_DATA = 'riskData';
const STORE_PAYMENT_METHOD = 'storePaymentMethod';
const CC_TYPE = 'cc_type';
const NUMBER_OF_INSTALLMENTS = 'number_of_installments';
const COMBO_CARD_TYPE = 'combo_card_type';
/**
* @param DataObject $data
* @return array|void
*/
protected function getValidatedAdditionalData(DataObject $data)
{
// Get additional data array
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}
// Get a validated additional data array
$additionalData = $this->getArrayOnlyWithApprovedKeys($additionalData, $this->approvedAdditionalDataKeys);
// json decode state data
$stateData = [];
if (!empty($additionalData[self::STATE_DATA])) {
$stateData = json_decode($additionalData[self::STATE_DATA], true);
}
// Get validated state data array
if (!empty($stateData)) {
$stateData = $this->getArrayOnlyWithApprovedKeys($stateData, $this->approvedStateDataKeys);
}
// Replace state data with the decoded and validated state data
$additionalData[self::STATE_DATA] = $stateData;
return $additionalData;
}
/**
* Returns an array with only the approved keys
*
......
......@@ -24,35 +24,19 @@
namespace Adyen\Payment\Observer;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
use Adyen\Payment\Observer\AdyenObserverTrait;
/**
* Class DataAssignObserver
*/
class AdyenCcDataAssignObserver extends AbstractDataAssignObserver
class AdyenCcDataAssignObserver extends AdyenAbstractDataAssignObserver
{
use AdyenObserverTrait;
//TODO do we need these?
const VARIANT = 'variant';
const STATE_DATA = 'state_data';
const STORE_PAYMENT_METHOD = 'storePaymentMethod';
const CC_TYPE = 'cc_type';
const NUMBER_OF_INSTALLMENTS = 'number_of_installments';
const COMBO_CARD_TYPE = 'combo_card_type';
const BROWSER_INFO = 'browserInfo';
const PAYMENT_METHOD = 'paymentMethod';
const RISK_DATA = 'riskData';
/**
* Approved root level keys from additional data array
*
* @var array
*/
private static $approvedAdditionalDataKeys = [
protected $approvedAdditionalDataKeys = [
self::STATE_DATA,
self::COMBO_CARD_TYPE,
self::NUMBER_OF_INSTALLMENTS
......@@ -63,7 +47,7 @@ class AdyenCcDataAssignObserver extends AbstractDataAssignObserver
*
* @var array
*/
private static $approvedStateDataKeys = [
protected $approvedStateDataKeys = [
self::BROWSER_INFO,
self::PAYMENT_METHOD,
self::RISK_DATA,
......@@ -79,28 +63,7 @@ class AdyenCcDataAssignObserver extends AbstractDataAssignObserver
// Get request fields
$data = $this->readDataArgument($observer);
// Get additional data array
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}
// Get a validated additional data array
$additionalData = $this->getArrayOnlyWithApprovedKeys($additionalData, self::$approvedAdditionalDataKeys);
// json decode state data
$stateData = [];
if (!empty($additionalData[self::STATE_DATA])) {
$stateData = json_decode($additionalData[self::STATE_DATA], true);
}
// Get validated state data array
if (!empty($stateData)) {
$stateData = $this->getArrayOnlyWithApprovedKeys($stateData, self::$approvedStateDataKeys);
}
// Replace state data with the decoded and validated state data
$additionalData[self::STATE_DATA] = $stateData;
$additionalData = $this->getValidatedAdditionalData($data);
// Set additional data in the payment
$paymentInfo = $this->readPaymentModelArgument($observer);
......
......@@ -23,31 +23,19 @@
namespace Adyen\Payment\Observer;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
/**
* Class DataAssignObserver
*/
class AdyenHppDataAssignObserver extends AbstractDataAssignObserver
class AdyenHppDataAssignObserver extends AdyenAbstractDataAssignObserver
{
use AdyenObserverTrait;
// TODO do we need these?
const DF_VALUE = 'df_value';
const BRAND_CODE = 'brand_code';
const STATE_DATA = 'state_data';
const BROWSER_INFO = 'browserInfo';
const PAYMENT_METHOD = 'paymentMethod';
const RISK_DATA = 'riskData';
/**
* Approved root level keys from additional data array
*
* @var array
*/
private static $approvedAdditionalDataKeys = [
protected $approvedAdditionalDataKeys = [
self::STATE_DATA,
self::BRAND_CODE
];
......@@ -57,7 +45,7 @@ class AdyenHppDataAssignObserver extends AbstractDataAssignObserver
*
* @var array
*/
private static $approvedStateDataKeys = [
protected $approvedStateDataKeys = [
self::BROWSER_INFO,
self::PAYMENT_METHOD,
self::RISK_DATA
......@@ -72,28 +60,7 @@ class AdyenHppDataAssignObserver extends AbstractDataAssignObserver
// Get request fields
$data = $this->readDataArgument($observer);
// Get additional data array
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}
// Get a validated additional data array
$additionalData = $this->getArrayOnlyWithApprovedKeys($additionalData, self::$approvedAdditionalDataKeys);
// json decode state data
$stateData = [];
if (!empty($additionalData[self::STATE_DATA])) {
$stateData = json_decode($additionalData[self::STATE_DATA], true);
}
// Get validated state data array
if (!empty($stateData)) {
$stateData = $this->getArrayOnlyWithApprovedKeys($stateData, self::$approvedStateDataKeys);
}
// Replace state data with the decoded and validated state data
$additionalData[self::STATE_DATA] = $stateData;
$additionalData = $this->getValidatedAdditionalData($data);
// Set additional data in the payment
$paymentInfo = $this->readPaymentModelArgument($observer);
......@@ -101,7 +68,6 @@ class AdyenHppDataAssignObserver extends AbstractDataAssignObserver
$paymentInfo->setAdditionalInformation($key, $data);
}
// Is this the correct way of setting it???
// Set BrandCode into CCType
if (isset($additionalData[self::BRAND_CODE])) {
$paymentInfo->setCcType($additionalData[self::BRAND_CODE]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment