Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PayflowProAddCcData.php
Go to the documentation of this file.
1 <?php
7 
12 
14 {
18  private $ccKeys = [
19  'cc_type',
20  'cc_exp_year',
21  'cc_exp_month',
22  'cc_last_4'
23  ];
24 
29  public function execute(\Magento\Framework\Event\Observer $observer)
30  {
31  $dataObject = $this->readDataArgument($observer);
32 
33  $additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
34 
35  if (!is_array($additionalData)) {
36  return;
37  }
38 
39  $ccData = array_intersect_key($additionalData, array_flip($this->ccKeys));
40  if (count($ccData) !== count($this->ccKeys)) {
41  return;
42  }
43  $paymentModel = $this->readPaymentModelArgument($observer);
44 
45  $paymentModel->setAdditionalInformation(
47  $this->sortCcData($ccData)
48  );
49 
50  // CC data should be stored explicitly
51  foreach ($ccData as $ccKey => $ccValue) {
52  $paymentModel->setData($ccKey, $ccValue);
53  }
54  }
55 
60  private function sortCcData(array $ccData)
61  {
62  $r = [];
63  foreach ($this->ccKeys as $key) {
64  $r[$key] = isset($ccData[$key]) ? $ccData[$key] : null;
65  }
66 
67  return $r;
68  }
69 }
execute(\Magento\Framework\Event\Observer $observer)