Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThreeDSecureDataBuilder.php
Go to the documentation of this file.
1 <?php
7 
12 use Magento\Payment\Helper\Formatter;
13 
18 {
19  use Formatter;
20 
24  private $config;
25 
29  private $subjectReader;
30 
37  public function __construct(Config $config, SubjectReader $subjectReader)
38  {
39  $this->config = $config;
40  $this->subjectReader = $subjectReader;
41  }
42 
46  public function build(array $buildSubject)
47  {
48  $result = [];
49 
50  $paymentDO = $this->subjectReader->readPayment($buildSubject);
51  $amount = $this->formatPrice($this->subjectReader->readAmount($buildSubject));
52 
53  if ($this->is3DSecureEnabled($paymentDO->getOrder(), $amount)) {
54  $result['options'][Config::CODE_3DSECURE] = ['required' => true];
55  }
56  return $result;
57  }
58 
65  private function is3DSecureEnabled(OrderAdapterInterface $order, $amount)
66  {
67  $storeId = $order->getStoreId();
68  if (!$this->config->isVerify3DSecure($storeId)
69  || $amount < $this->config->getThresholdAmount($storeId)
70  ) {
71  return false;
72  }
73 
74  $billingAddress = $order->getBillingAddress();
75  $specificCounties = $this->config->get3DSecureSpecificCountries($storeId);
76  if (!empty($specificCounties) && !in_array($billingAddress->getCountryId(), $specificCounties)) {
77  return false;
78  }
79 
80  return true;
81  }
82 }
$billingAddress
Definition: order.php:25
$config
Definition: fraud_order.php:17
$order
Definition: order.php:55
$amount
Definition: order.php:14
__construct(Config $config, SubjectReader $subjectReader)