Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IframeConfigProvider.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Payment\Model;
7 
13 use Magento\Payment\Helper\Data as PaymentHelper;
15 use Psr\Log\LoggerInterface;
16 
30 {
34  const TIMEOUT_TIME = 30000;
35 
40 
44  const CHECKOUT_IDENTIFIER = 'checkout_flow';
45 
49  protected $assetRepo;
50 
54  protected $request;
55 
59  protected $urlBuilder;
60 
64  protected $logger;
65 
71  protected $methodCode;
72 
76  protected $method;
77 
86  public function __construct(
90  LoggerInterface $logger,
91  PaymentHelper $paymentHelper,
93  ) {
94  $this->assetRepo = $assetRepo;
95  $this->request = $request;
96  $this->urlBuilder = $urlBuilder;
97  $this->logger = $logger;
98  $this->methodCode = $methodCode;
99  $this->method = $paymentHelper->getMethodInstance($methodCode);
100  }
101 
105  public function getConfig()
106  {
107  return [
108  'payment' => [
109  'iframe' => [
110  'timeoutTime' => [$this->methodCode => self::TIMEOUT_TIME],
111  'dateDelim' => [$this->methodCode => $this->getDateDelim()],
112  'cardFieldsMap' => [$this->methodCode => $this->getCardFieldsMap()],
113  'source' => [$this->methodCode => $this->getViewFileUrl('blank.html')],
114  'controllerName' => [$this->methodCode => self::CHECKOUT_IDENTIFIER],
115  'cgiUrl' => [$this->methodCode => $this->getCgiUrl()],
116  'placeOrderUrl' => [$this->methodCode => $this->getPlaceOrderUrl()],
117  'saveOrderUrl' => [$this->methodCode => $this->getSaveOrderUrl()],
118  'expireYearLength' => [$this->methodCode => $this->getExpireDateYearLength()]
119  ]
120  ]
121  ];
122  }
123 
129  protected function getDateDelim()
130  {
131  $result = '';
132  if ($this->method->isAvailable()) {
133  $configData = $this->getMethodConfigData('date_delim');
134  if ($configData !== null) {
136  }
137  }
138 
139  return $result;
140  }
141 
147  protected function getExpireDateYearLength()
148  {
149  return (int)$this->getMethodConfigData('cc_year_length') ?: self::DEFAULT_YEAR_LENGTH;
150  }
151 
158  protected function getCardFieldsMap()
159  {
160  $result = [];
161  if ($this->method->isAvailable()) {
162  $configData = $this->getMethodConfigData('ccfields');
163  $keys = ['cccvv', 'ccexpdate', 'ccnum'];
164  $result = array_combine($keys, explode(',', $configData));
165  }
166 
167  return $result;
168  }
169 
177  protected function getViewFileUrl($fileId, array $params = [])
178  {
179  try {
180  $params = array_merge(['_secure' => $this->request->isSecure()], $params);
181  return $this->assetRepo->getUrlWithParams($fileId, $params);
182  } catch (LocalizedException $e) {
183  $this->logger->critical($e);
184  return $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']);
185  }
186  }
187 
193  protected function getPlaceOrderUrl()
194  {
195  return $this->urlBuilder->getUrl(
196  $this->getMethodConfigData('place_order_url'),
197  [
198  '_secure' => $this->request->isSecure()
199  ]
200  );
201  }
202 
208  protected function getSaveOrderUrl()
209  {
210  return $this->urlBuilder->getUrl('checkout/onepage/saveOrder', ['_secure' => $this->request->isSecure()]);
211  }
212 
218  protected function getCgiUrl()
219  {
220  return (bool)$this->getMethodConfigData('sandbox_flag')
221  ? $this->getMethodConfigData('cgi_url_test_mode')
222  : $this->getMethodConfigData('cgi_url');
223  }
224 
231  protected function getMethodConfigData($fieldName)
232  {
233  if ($this->method instanceof TransparentInterface) {
234  return $this->method->getConfigInterface()->getValue($fieldName);
235  }
236  return $this->method->getConfigData($fieldName);
237  }
238 }
__construct(Repository $assetRepo, RequestInterface $request, UrlInterface $urlBuilder, LoggerInterface $logger, PaymentHelper $paymentHelper, $methodCode)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18