CcConfig.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Model;
  7. use Magento\Framework\App\RequestInterface;
  8. use Magento\Framework\Exception\LocalizedException;
  9. use Magento\Framework\UrlInterface;
  10. use Magento\Framework\View\Asset\Repository;
  11. use Psr\Log\LoggerInterface;
  12. use Magento\Payment\Model\Config as PaymentConfig;
  13. /**
  14. * Credit card configuration model
  15. *
  16. * @api
  17. * @since 100.0.2
  18. */
  19. class CcConfig
  20. {
  21. /**
  22. * @var \Magento\Payment\Model\Config
  23. */
  24. protected $config;
  25. /**
  26. * @var Repository
  27. */
  28. protected $assetRepo;
  29. /**
  30. * @var RequestInterface
  31. */
  32. protected $request;
  33. /**
  34. * @var UrlInterface
  35. */
  36. protected $urlBuilder;
  37. /**
  38. * @var LoggerInterface
  39. */
  40. protected $logger;
  41. /**
  42. * @param PaymentConfig $paymentConfig
  43. * @param Repository $assetRepo
  44. * @param RequestInterface $request
  45. * @param UrlInterface $urlBuilder
  46. * @param LoggerInterface $logger
  47. */
  48. public function __construct(
  49. PaymentConfig $paymentConfig,
  50. Repository $assetRepo,
  51. RequestInterface $request,
  52. UrlInterface $urlBuilder,
  53. LoggerInterface $logger
  54. ) {
  55. $this->config = $paymentConfig;
  56. $this->assetRepo = $assetRepo;
  57. $this->request = $request;
  58. $this->urlBuilder = $urlBuilder;
  59. $this->logger = $logger;
  60. }
  61. /**
  62. * Solo/switch card start years
  63. *
  64. * @return array
  65. * @deprecated 100.1.0 unused
  66. */
  67. public function getSsStartYears()
  68. {
  69. $years = [];
  70. $first = date("Y");
  71. for ($index = 5; $index >= 0; $index--) {
  72. $year = $first - $index;
  73. $years[$year] = $year;
  74. }
  75. return $years;
  76. }
  77. /**
  78. * Retrieve available credit card types
  79. *
  80. * @return array
  81. */
  82. public function getCcAvailableTypes()
  83. {
  84. return $this->config->getCcTypes();
  85. }
  86. /**
  87. * Retrieve credit card expire months
  88. *
  89. * @return array
  90. */
  91. public function getCcMonths()
  92. {
  93. return $this->config->getMonths();
  94. }
  95. /**
  96. * Retrieve credit card expire years
  97. *
  98. * @return array
  99. */
  100. public function getCcYears()
  101. {
  102. return $this->config->getYears();
  103. }
  104. /**
  105. * Retrieve has verification configuration
  106. *
  107. * @return bool
  108. */
  109. public function hasVerification()
  110. {
  111. return true;
  112. }
  113. /**
  114. * Whether switch/solo card type available
  115. *
  116. * @return bool
  117. * @deprecated 100.1.0 unused
  118. */
  119. public function hasSsCardType()
  120. {
  121. return false;
  122. }
  123. /**
  124. * Retrieve CVV tooltip image url
  125. *
  126. * @return string
  127. */
  128. public function getCvvImageUrl()
  129. {
  130. return $this->getViewFileUrl('Magento_Checkout::cvv.png');
  131. }
  132. /**
  133. * Retrieve url of a view file
  134. *
  135. * @param string $fileId
  136. * @param array $params
  137. * @return string
  138. */
  139. public function getViewFileUrl($fileId, array $params = [])
  140. {
  141. try {
  142. $params = array_merge(['_secure' => $this->request->isSecure()], $params);
  143. return $this->assetRepo->getUrlWithParams($fileId, $params);
  144. } catch (LocalizedException $e) {
  145. $this->logger->critical($e);
  146. return $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']);
  147. }
  148. }
  149. /**
  150. * Create a file asset that's subject of fallback system
  151. *
  152. * @param string $fileId
  153. * @param array $params
  154. * @return \Magento\Framework\View\Asset\File
  155. */
  156. public function createAsset($fileId, array $params = [])
  157. {
  158. $params = array_merge(['_secure' => $this->request->isSecure()], $params);
  159. return $this->assetRepo->createAsset($fileId, $params);
  160. }
  161. }