1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Observer;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Paypal\Model\Payflow\Transparent;
use Magento\Quote\Api\Data\PaymentInterface;
class PayflowProAddCcData extends AbstractDataAssignObserver
{
/**
* @var array
*/
private $ccKeys = [
'cc_type',
'cc_exp_year',
'cc_exp_month',
'cc_last_4'
];
/**
* @param Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$dataObject = $this->readDataArgument($observer);
$additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}
$ccData = array_intersect_key($additionalData, array_flip($this->ccKeys));
if (count($ccData) !== count($this->ccKeys)) {
return;
}
$paymentModel = $this->readPaymentModelArgument($observer);
$paymentModel->setAdditionalInformation(
Transparent::CC_DETAILS,
$this->sortCcData($ccData)
);
// CC data should be stored explicitly
foreach ($ccData as $ccKey => $ccValue) {
$paymentModel->setData($ccKey, $ccValue);
}
}
/**
* @param array $ccData
* @return array
*/
private function sortCcData(array $ccData)
{
$r = [];
foreach ($this->ccKeys as $key) {
$r[$key] = isset($ccData[$key]) ? $ccData[$key] : null;
}
return $r;
}
}