Cc.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Block\Form;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class Cc extends \Magento\Payment\Block\Form
  12. {
  13. /**
  14. * @var string
  15. */
  16. protected $_template = 'Magento_Payment::form/cc.phtml';
  17. /**
  18. * Payment config model
  19. *
  20. * @var \Magento\Payment\Model\Config
  21. */
  22. protected $_paymentConfig;
  23. /**
  24. * @param \Magento\Framework\View\Element\Template\Context $context
  25. * @param \Magento\Payment\Model\Config $paymentConfig
  26. * @param array $data
  27. */
  28. public function __construct(
  29. \Magento\Framework\View\Element\Template\Context $context,
  30. \Magento\Payment\Model\Config $paymentConfig,
  31. array $data = []
  32. ) {
  33. parent::__construct($context, $data);
  34. $this->_paymentConfig = $paymentConfig;
  35. }
  36. /**
  37. * Retrieve availables credit card types
  38. *
  39. * @return array
  40. * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  41. */
  42. public function getCcAvailableTypes()
  43. {
  44. $types = $this->_paymentConfig->getCcTypes();
  45. if ($method = $this->getMethod()) {
  46. $availableTypes = $method->getConfigData('cctypes');
  47. if ($availableTypes) {
  48. $availableTypes = explode(',', $availableTypes);
  49. foreach ($types as $code => $name) {
  50. if (!in_array($code, $availableTypes)) {
  51. unset($types[$code]);
  52. }
  53. }
  54. }
  55. }
  56. return $types;
  57. }
  58. /**
  59. * Retrieve credit card expire months
  60. *
  61. * @return array
  62. */
  63. public function getCcMonths()
  64. {
  65. $months = $this->getData('cc_months');
  66. if ($months === null) {
  67. $months[0] = __('Month');
  68. $months = array_merge($months, $this->_paymentConfig->getMonths());
  69. $this->setData('cc_months', $months);
  70. }
  71. return $months;
  72. }
  73. /**
  74. * Retrieve credit card expire years
  75. *
  76. * @return array
  77. */
  78. public function getCcYears()
  79. {
  80. $years = $this->getData('cc_years');
  81. if ($years === null) {
  82. $years = $this->_paymentConfig->getYears();
  83. $years = [0 => __('Year')] + $years;
  84. $this->setData('cc_years', $years);
  85. }
  86. return $years;
  87. }
  88. /**
  89. * Retrieve has verification configuration
  90. *
  91. * @return bool
  92. */
  93. public function hasVerification()
  94. {
  95. if ($this->getMethod()) {
  96. $configData = $this->getMethod()->getConfigData('useccv');
  97. if ($configData === null) {
  98. return true;
  99. }
  100. return (bool)$configData;
  101. }
  102. return true;
  103. }
  104. /**
  105. * Whether switch/solo card type available
  106. *
  107. * @deprecated 100.1.0 unused
  108. * @return bool
  109. */
  110. public function hasSsCardType()
  111. {
  112. $availableTypes = explode(',', $this->getMethod()->getConfigData('cctypes'));
  113. $ssPresenations = array_intersect(['SS', 'SM', 'SO'], $availableTypes);
  114. if ($availableTypes && count($ssPresenations) > 0) {
  115. return true;
  116. }
  117. return false;
  118. }
  119. /**
  120. * Solo/switch card start year
  121. *
  122. * @deprecated 100.1.0 unused
  123. * @return array
  124. */
  125. public function getSsStartYears()
  126. {
  127. $years = [];
  128. $first = date("Y");
  129. for ($index = 5; $index >= 0; $index--) {
  130. $year = $first - $index;
  131. $years[$year] = $year;
  132. }
  133. $years = [0 => __('Year')] + $years;
  134. return $years;
  135. }
  136. /**
  137. * Render block HTML
  138. *
  139. * @return string
  140. */
  141. protected function _toHtml()
  142. {
  143. $this->_eventManager->dispatch('payment_form_block_to_html_before', ['block' => $this]);
  144. return parent::_toHtml();
  145. }
  146. }