Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Cc.php
Go to the documentation of this file.
1 <?php
7 
13 {
17  protected $_template = 'Magento_Payment::form/cc.phtml';
18 
24  protected $_paymentConfig;
25 
31  public function __construct(
32  \Magento\Framework\View\Element\Template\Context $context,
33  \Magento\Payment\Model\Config $paymentConfig,
34  array $data = []
35  ) {
36  parent::__construct($context, $data);
37  $this->_paymentConfig = $paymentConfig;
38  }
39 
46  public function getCcAvailableTypes()
47  {
48  $types = $this->_paymentConfig->getCcTypes();
49  if ($method = $this->getMethod()) {
50  $availableTypes = $method->getConfigData('cctypes');
51  if ($availableTypes) {
52  $availableTypes = explode(',', $availableTypes);
53  foreach ($types as $code => $name) {
54  if (!in_array($code, $availableTypes)) {
55  unset($types[$code]);
56  }
57  }
58  }
59  }
60  return $types;
61  }
62 
68  public function getCcMonths()
69  {
70  $months = $this->getData('cc_months');
71  if ($months === null) {
72  $months[0] = __('Month');
73  $months = array_merge($months, $this->_paymentConfig->getMonths());
74  $this->setData('cc_months', $months);
75  }
76  return $months;
77  }
78 
84  public function getCcYears()
85  {
86  $years = $this->getData('cc_years');
87  if ($years === null) {
88  $years = $this->_paymentConfig->getYears();
89  $years = [0 => __('Year')] + $years;
90  $this->setData('cc_years', $years);
91  }
92  return $years;
93  }
94 
100  public function hasVerification()
101  {
102  if ($this->getMethod()) {
103  $configData = $this->getMethod()->getConfigData('useccv');
104  if ($configData === null) {
105  return true;
106  }
107  return (bool)$configData;
108  }
109  return true;
110  }
111 
118  public function hasSsCardType()
119  {
120  $availableTypes = explode(',', $this->getMethod()->getConfigData('cctypes'));
121  $ssPresenations = array_intersect(['SS', 'SM', 'SO'], $availableTypes);
122  if ($availableTypes && count($ssPresenations) > 0) {
123  return true;
124  }
125  return false;
126  }
127 
134  public function getSsStartYears()
135  {
136  $years = [];
137  $first = date("Y");
138 
139  for ($index = 5; $index >= 0; $index--) {
140  $year = $first - $index;
141  $years[$year] = $year;
142  }
143  $years = [0 => __('Year')] + $years;
144  return $years;
145  }
146 
152  protected function _toHtml()
153  {
154  $this->_eventManager->dispatch('payment_form_block_to_html_before', ['block' => $this]);
155  return parent::_toHtml();
156  }
157 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Payment\Model\Config $paymentConfig, array $data=[])
Definition: Cc.php:31
getData($key='', $index=null)
Definition: DataObject.php:119
__()
Definition: __.php:13
$method
Definition: info.phtml:13
setData($key, $value=null)
Definition: DataObject.php:72
$index
Definition: list.phtml:44
$code
Definition: info.phtml:12
if(!isset($_GET['name'])) $name
Definition: log.php:14