Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CcGenericConfigProvider.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Payment\Model;
7 
9 use Magento\Payment\Helper\Data as PaymentHelper;
10 
20 {
24  protected $ccConfig;
25 
29  protected $methods = [];
30 
36  public function __construct(
38  PaymentHelper $paymentHelper,
39  array $methodCodes = []
40  ) {
41  $this->ccConfig = $ccConfig;
42  foreach ($methodCodes as $code) {
43  $this->methods[$code] = $paymentHelper->getMethodInstance($code);
44  }
45  }
46 
50  public function getConfig()
51  {
52  $config = [];
53  foreach ($this->methods as $methodCode => $method) {
54  if ($method->isAvailable()) {
55  $config = array_merge_recursive($config, [
56  'payment' => [
57  'ccform' => [
58  'availableTypes' => [$methodCode => $this->getCcAvailableTypes($methodCode)],
59  'months' => [$methodCode => $this->getCcMonths()],
60  'years' => [$methodCode => $this->getCcYears()],
61  'hasVerification' => [$methodCode => $this->hasVerification($methodCode)],
62  'cvvImageUrl' => [$methodCode => $this->getCvvImageUrl()]
63  ]
64  ]
65  ]);
66  }
67  }
68  return $config;
69  }
70 
77  protected function getSsStartYears()
78  {
79  return $this->ccConfig->getSsStartYears();
80  }
81 
87  protected function getCcMonths()
88  {
89  return $this->ccConfig->getCcMonths();
90  }
91 
97  protected function getCcYears()
98  {
99  return $this->ccConfig->getCcYears();
100  }
101 
107  protected function getCvvImageUrl()
108  {
109  return $this->ccConfig->getCvvImageUrl();
110  }
111 
118  protected function getCcAvailableTypes($methodCode)
119  {
120  $types = $this->ccConfig->getCcAvailableTypes();
121  $availableTypes = $this->methods[$methodCode]->getConfigData('cctypes');
122  if ($availableTypes) {
123  $availableTypes = explode(',', $availableTypes);
124  foreach (array_keys($types) as $code) {
125  if (!in_array($code, $availableTypes)) {
126  unset($types[$code]);
127  }
128  }
129  }
130  return $types;
131  }
132 
139  protected function hasVerification($methodCode)
140  {
141  $result = $this->ccConfig->hasVerification();
142  $configData = $this->methods[$methodCode]->getConfigData('useccv');
143  if ($configData !== null) {
144  $result = (bool)$configData;
145  }
146  return $result;
147  }
148 
156  protected function hasSsCardType($methodCode)
157  {
158  $result = false;
159  $availableTypes = explode(',', $this->methods[$methodCode]->getConfigData('cctypes'));
160  $ssPresentations = array_intersect(['SS', 'SM', 'SO'], $availableTypes);
161  if ($availableTypes && count($ssPresentations) > 0) {
162  $result = true;
163  }
164  return $result;
165  }
166 }
$config
Definition: fraud_order.php:17
__construct(CcConfig $ccConfig, PaymentHelper $paymentHelper, array $methodCodes=[])
$method
Definition: info.phtml:13
$code
Definition: info.phtml:12