Skip to content

Commit a60d492

Browse files
committed
Merge pull request #274 from magento-mpi/MAGETWO-34552-main
[MPI] Implement transparent redirect API
2 parents 4f25bdd + 354b130 commit a60d492

File tree

34 files changed

+1719
-70
lines changed

34 files changed

+1719
-70
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Block\Adminhtml\Transparent;
7+
8+
class Form extends \Magento\Payment\Block\Transparent\Form
9+
{
10+
/**
11+
* On backend this block does not have any conditional checks
12+
*
13+
* @return bool
14+
*/
15+
protected function shouldRender()
16+
{
17+
return true;
18+
}
19+
20+
/**
21+
* {inheritdoc}
22+
*/
23+
protected function initializeMethod()
24+
{
25+
return;
26+
}
27+
}

app/code/Magento/Payment/Block/Form.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Payment\Block;
77

8+
use Magento\Payment\Model\MethodInterface;
9+
810
/**
911
* Payment method form base block
1012
*/
@@ -13,21 +15,33 @@ class Form extends \Magento\Framework\View\Element\Template
1315
/**
1416
* Retrieve payment method model
1517
*
16-
* @return \Magento\Payment\Model\MethodInterface
18+
* @return MethodInterface
1719
* @throws \Magento\Framework\Exception\LocalizedException
1820
*/
1921
public function getMethod()
2022
{
2123
$method = $this->getData('method');
2224

23-
if (!$method instanceof \Magento\Payment\Model\MethodInterface) {
25+
if (!$method instanceof MethodInterface) {
2426
throw new \Magento\Framework\Exception\LocalizedException(
2527
__('We cannot retrieve the payment method model object.')
2628
);
2729
}
2830
return $method;
2931
}
3032

33+
/**
34+
* Sets payment method instance to form
35+
*
36+
* @param MethodInterface $method
37+
* @return $this
38+
*/
39+
public function setMethod(MethodInterface $method)
40+
{
41+
$this->setData('method', $method);
42+
return $this;
43+
}
44+
3145
/**
3246
* Retrieve payment method code
3347
*
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Block\Transparent;
7+
8+
use Magento\Framework\Exception\LocalizedException;
9+
use Magento\Payment\Model\Method\TransparentInterface;
10+
use Magento\Checkout\Model\Session;
11+
use Magento\Payment\Model\Config;
12+
use Magento\Framework\View\Element\Template\Context;
13+
14+
/**
15+
* Transparent form block
16+
*
17+
* @author Magento Core Team <core@magentocommerce.com>
18+
*/
19+
class Form extends \Magento\Payment\Block\Form\Cc
20+
{
21+
/**
22+
* @var Session
23+
*/
24+
private $checkoutSession;
25+
26+
/**
27+
* @var string
28+
*/
29+
protected $_template = 'Magento_Payment::transparent/form.phtml';
30+
31+
/**
32+
* @param Context $context
33+
* @param Config $paymentConfig
34+
* @param Session $checkoutSession
35+
* @param array $data
36+
*/
37+
public function __construct(
38+
Context $context,
39+
Config $paymentConfig,
40+
Session $checkoutSession,
41+
array $data = []
42+
) {
43+
parent::__construct($context, $paymentConfig, $data);
44+
$this->checkoutSession = $checkoutSession;
45+
}
46+
47+
/**
48+
* {inheritdoc}
49+
*/
50+
protected function _toHtml()
51+
{
52+
if ($this->shouldRender()) {
53+
return $this->processHtml();
54+
}
55+
56+
return '';
57+
}
58+
59+
/**
60+
* Checks whether block should be rendered
61+
* basing on TransparentInterface presence in checkout session
62+
*
63+
* @return bool
64+
*/
65+
protected function shouldRender()
66+
{
67+
$quote = $this->checkoutSession->getQuote();
68+
if ($quote) {
69+
$payment = $quote->getPayment();
70+
return $payment && $payment->getMethodInstance() instanceof TransparentInterface;
71+
}
72+
73+
return false;
74+
}
75+
76+
/**
77+
* Initializes method
78+
*
79+
* @return void
80+
*/
81+
protected function initializeMethod()
82+
{
83+
$this->setData(
84+
'method',
85+
$this->checkoutSession
86+
->getQuote()
87+
->getPayment()
88+
->getMethodInstance()
89+
);
90+
}
91+
92+
/**
93+
* Parent rendering wrapper
94+
*
95+
* @return string
96+
*/
97+
protected function processHtml()
98+
{
99+
$this->initializeMethod();
100+
return parent::_toHtml();
101+
}
102+
103+
/**
104+
* Get type of request
105+
*
106+
* @return bool
107+
*/
108+
public function isAjaxRequest()
109+
{
110+
return $this->getRequest()->getParam('isAjax');
111+
}
112+
113+
/**
114+
* Get delimiter for date
115+
*
116+
* @return string
117+
*/
118+
public function getDateDelim()
119+
{
120+
return $this->getMethodConfigData('date_delim');
121+
}
122+
123+
/**
124+
* Get map of cc_code, cc_num, cc_expdate for gateway
125+
* Returns json formatted string
126+
*
127+
* @return string
128+
*/
129+
public function getCardFieldsMap()
130+
{
131+
$keys = ['cccvv', 'ccexpdate', 'ccnum'];
132+
$ccfields = array_combine($keys, explode(',', $this->getMethodConfigData('ccfields')));
133+
return json_encode($ccfields);
134+
}
135+
136+
/**
137+
* Retrieve place order url on front
138+
*
139+
* @return string
140+
*/
141+
public function getOrderUrl()
142+
{
143+
return $this->_urlBuilder->getUrl(
144+
$this->getMethodConfigData('place_order_url'),
145+
[
146+
'_secure' => $this->getRequest()->isSecure()
147+
]
148+
);
149+
}
150+
151+
/**
152+
* Retrieve gateway url
153+
*
154+
* @return string
155+
*/
156+
public function getCgiUrl()
157+
{
158+
return (bool)$this->getMethodConfigData('sandbox_flag')
159+
? $this->getMethodConfigData('cgi_url_test_mode')
160+
: $this->getMethodConfigData('cgi_url');
161+
}
162+
163+
/**
164+
* Retrieve config data value by field name
165+
*
166+
* @param string $fieldName
167+
* @return mixed
168+
*/
169+
public function getMethodConfigData($fieldName)
170+
{
171+
return $this->getMethod()->getConfigInterface()->getConfigValue($fieldName);
172+
}
173+
174+
/**
175+
* Returns transparent method service
176+
*
177+
* @return TransparentInterface
178+
* @throws LocalizedException
179+
*/
180+
public function getMethod()
181+
{
182+
$method = parent::getMethod();
183+
184+
if (!$method instanceof TransparentInterface) {
185+
throw new LocalizedException(
186+
__('We cannot retrieve the transparent payment method model object.')
187+
);
188+
}
189+
return $method;
190+
}
191+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Block\Transparent;
7+
8+
/**
9+
* Iframe block for register specific params in layout
10+
*
11+
* @author Magento Core Team <core@magentocommerce.com>
12+
*/
13+
class Iframe extends \Magento\Framework\View\Element\Template
14+
{
15+
/**
16+
* Core registry
17+
*
18+
* @var \Magento\Framework\Registry
19+
*/
20+
protected $coreRegistry;
21+
22+
/**
23+
* Constructor
24+
*
25+
* @param \Magento\Framework\View\Element\Template\Context $context
26+
* @param \Magento\Framework\Registry $registry
27+
* @param array $data
28+
*/
29+
public function __construct(
30+
\Magento\Framework\View\Element\Template\Context $context,
31+
\Magento\Framework\Registry $registry,
32+
array $data = []
33+
) {
34+
$this->coreRegistry = $registry;
35+
parent::__construct($context, $data);
36+
}
37+
38+
/**
39+
* Preparing layout
40+
*
41+
* @return $this
42+
*/
43+
protected function _prepareLayout()
44+
{
45+
if ($this->hasRegistryKey()) {
46+
$params = $this->coreRegistry->registry($this->getRegistryKey());
47+
$this->setParams($params);
48+
}
49+
return parent::_prepareLayout();
50+
}
51+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Block\Transparent;
7+
8+
/**
9+
* Class Info. Payment Information block used for transparent redirect feature
10+
* @package Magento\Payment\Block\Transparent
11+
*/
12+
class Info extends \Magento\Framework\View\Element\Template
13+
{
14+
/**
15+
* @var string
16+
*/
17+
protected $_template = 'Magento_Payment::transparent/info.phtml';
18+
}

app/code/Magento/Payment/Model/Method/AbstractMethod.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ public function __construct(
254254
$this->_scopeConfig = $scopeConfig;
255255
$this->_eventManager = $context->getEventDispatcher();
256256
$this->logger = $context->getLogger();
257+
$this->initializeData($data);
258+
}
259+
260+
/**
261+
* Initializes injected data
262+
*
263+
* @param array $data
264+
* @return void
265+
*/
266+
protected function initializeData($data = [])
267+
{
268+
if (!empty($data['formBlockType'])) {
269+
$this->_formBlockType = $data['formBlockType'];
270+
}
257271
}
258272

259273
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Model\Method;
7+
8+
/**
9+
* Interface for payment methods config
10+
*
11+
* @author Magento Core Team <core@magentocommerce.com>
12+
*/
13+
interface ConfigInterface
14+
{
15+
/**
16+
* Config field getter
17+
* The specified key can be either in camelCase or under_score format
18+
*
19+
* @param string $key
20+
* @return mixed
21+
*/
22+
public function getConfigValue($key);
23+
}

0 commit comments

Comments
 (0)