This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataAssignObserver.php
77 lines (68 loc) · 2.08 KB
/
DataAssignObserver.php
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
70
71
72
73
74
75
76
77
<?php
namespace Femsa\Payments\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Checkout\Model\Session;
class DataAssignObserver extends AbstractDataAssignObserver
{
public const PAYMENT_METHOD = 'payment_method';
public const IFRAME_PAYMENT = 'iframe_payment';
public const ORDER_ID = 'order_id';
public const TXN_ID = 'txn_id';
public const REFERENCE = 'reference';
/**
* @var string[]
*/
protected array $additionalInformationList = [
self::PAYMENT_METHOD,
self::IFRAME_PAYMENT,
self::ORDER_ID,
self::TXN_ID,
self::REFERENCE,
];
/**
* @var Session
*/
protected Session $_checkoutSession;
/**
* @param Session $checkoutSession
*/
public function __construct(
Session $checkoutSession
) {
$this->_checkoutSession = $checkoutSession;
}
/**
* Execute
*
* @param Observer $observer
* @return void
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function execute(Observer $observer)
{
$data = $this->readDataArgument($observer);
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}
$paymentInfo = $this->readPaymentModelArgument($observer);
$quote = $this->_checkoutSession->getQuote();
$paymentInfo->setAdditionalInformation(
'quote_id',
$quote->getId()
);
foreach ($this->additionalInformationList as $additionalInformationKey) {
if (isset($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$additionalData[$additionalInformationKey]
);
}
}
}
}