Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CardDetailsHandler.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
19  const CARD_TYPE = 'cardType';
20 
21  const CARD_EXP_MONTH = 'expirationMonth';
22 
23  const CARD_EXP_YEAR = 'expirationYear';
24 
25  const CARD_LAST4 = 'last4';
26 
27  const CARD_NUMBER = 'cc_number';
28 
32  private $config;
33 
37  private $subjectReader;
38 
45  public function __construct(
46  Config $config,
47  SubjectReader $subjectReader
48  ) {
49  $this->config = $config;
50  $this->subjectReader = $subjectReader;
51  }
52 
56  public function handle(array $handlingSubject, array $response)
57  {
58  $paymentDO = $this->subjectReader->readPayment($handlingSubject);
59  $transaction = $this->subjectReader->readTransaction($response);
60 
64  $payment = $paymentDO->getPayment();
66 
67  $creditCard = $transaction->creditCard;
68  $payment->setCcLast4($creditCard[self::CARD_LAST4]);
69  $payment->setCcExpMonth($creditCard[self::CARD_EXP_MONTH]);
70  $payment->setCcExpYear($creditCard[self::CARD_EXP_YEAR]);
71 
72  $payment->setCcType($this->getCreditCardType($creditCard[self::CARD_TYPE]));
73 
74  // set card details to additional info
75  $payment->setAdditionalInformation(self::CARD_NUMBER, 'xxxx-' . $creditCard[self::CARD_LAST4]);
76  $payment->setAdditionalInformation(OrderPaymentInterface::CC_TYPE, $creditCard[self::CARD_TYPE]);
77  }
78 
85  private function getCreditCardType($type)
86  {
87  $replaced = str_replace(' ', '-', strtolower($type));
88  $mapper = $this->config->getCcTypesMapper();
89 
90  return $mapper[$replaced];
91  }
92 }
$transaction
$response
Definition: 404.php:11
$config
Definition: fraud_order.php:17
__construct(Config $config, SubjectReader $subjectReader)
$payment
Definition: order.php:17
$type
Definition: item.phtml:13
handle(array $handlingSubject, array $response)
static assertOrderPayment(InfoInterface $paymentInfo)