Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Form.php
Go to the documentation of this file.
1 <?php
7 
14 
21 class Form extends \Magento\Payment\Block\Form\Cc
22 {
26  private $checkoutSession;
27 
31  protected $_template = 'Magento_Payment::transparent/form.phtml';
32 
39  public function __construct(
40  Context $context,
41  Config $paymentConfig,
42  Session $checkoutSession,
43  array $data = []
44  ) {
45  parent::__construct($context, $paymentConfig, $data);
46  $this->checkoutSession = $checkoutSession;
47  }
48 
52  protected function _toHtml()
53  {
54  if ($this->shouldRender()) {
55  return $this->processHtml();
56  }
57 
58  return '';
59  }
60 
67  protected function shouldRender()
68  {
69  $quote = $this->checkoutSession->getQuote();
70  if ($quote) {
71  $payment = $quote->getPayment();
72  return $payment && $payment->getMethodInstance() instanceof TransparentInterface;
73  }
74 
75  return false;
76  }
77 
83  protected function initializeMethod()
84  {
85  $this->setData(
86  'method',
87  $this->checkoutSession
88  ->getQuote()
89  ->getPayment()
90  ->getMethodInstance()
91  );
92  }
93 
99  protected function processHtml()
100  {
101  $this->initializeMethod();
102  return parent::_toHtml();
103  }
104 
110  public function isAjaxRequest()
111  {
112  return $this->getRequest()->getParam('isAjax');
113  }
114 
120  public function getDateDelim()
121  {
122  return $this->getMethodConfigData('date_delim');
123  }
124 
131  public function getCardFieldsMap()
132  {
133  $keys = ['cccvv', 'ccexpdate', 'ccnum'];
134  $ccfields = array_combine($keys, explode(',', $this->getMethodConfigData('ccfields')));
135  return json_encode($ccfields);
136  }
137 
143  public function getOrderUrl()
144  {
145  return $this->_urlBuilder->getUrl(
146  $this->getMethodConfigData('place_order_url'),
147  [
148  '_secure' => $this->getRequest()->isSecure()
149  ]
150  );
151  }
152 
158  public function getCgiUrl()
159  {
160  return (bool)$this->getMethodConfigData('sandbox_flag')
161  ? $this->getMethodConfigData('cgi_url_test_mode')
162  : $this->getMethodConfigData('cgi_url');
163  }
164 
171  public function getMethodConfigData($fieldName)
172  {
173  $method = $this->getMethod();
174  if ($method instanceof TransparentInterface) {
175  return $method->getConfigInterface()->getValue($fieldName);
176  }
177  return $method->getConfigData($fieldName);
178  }
179 
186  public function getMethod()
187  {
188  $method = parent::getMethod();
189 
190  if (!$method instanceof TransparentInterface && !$method instanceof Adapter) {
191  throw new LocalizedException(
192  __('We cannot retrieve the transparent payment method model object.')
193  );
194  }
195  return $method;
196  }
197 }
__construct(Context $context, Config $paymentConfig, Session $checkoutSession, array $data=[])
Definition: Form.php:39
$quote
__()
Definition: __.php:13
$payment
Definition: order.php:17
$method
Definition: info.phtml:13
setData($key, $value=null)
Definition: DataObject.php:72