Skip to content

Commit 373afd6

Browse files
committed
MAGETWO-61353: Gift Card Accounts are not being generated with Auth&Capture payment action on Authorize.net DP enabled
- introduce service class for parameters settings
1 parent cea48c1 commit 373afd6

File tree

8 files changed

+110
-62
lines changed

8 files changed

+110
-62
lines changed

app/code/Magento/Authorizenet/Controller/Adminhtml/Authorizenet/Directpost/Payment/Redirect.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ public function execute()
129129
$this->_returnQuote($cancelOrder, $redirectParams['error_msg']);
130130
}
131131

132-
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, array_merge($params, $redirectParams));
132+
$this->_objectManager->get(\Magento\Payment\Model\IframeService::class)->setParams(
133+
array_merge($params, $redirectParams)
134+
);
133135
return $this->resultLayoutFactory->create();
134136
}
135137
}

app/code/Magento/Authorizenet/Controller/Directpost/Payment.php

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ abstract class Payment extends \Magento\Framework\App\Action\Action
1717
/**
1818
* Core registry
1919
*
20+
* @deprecated
2021
* @var \Magento\Framework\Registry
2122
*/
2223
protected $_coreRegistry = null;
@@ -26,20 +27,29 @@ abstract class Payment extends \Magento\Framework\App\Action\Action
2627
*/
2728
protected $dataFactory;
2829

30+
/**
31+
* @var \Magento\Payment\Model\IframeService
32+
*/
33+
private $iframeService;
34+
2935
/**
3036
* Constructor
3137
*
3238
* @param \Magento\Framework\App\Action\Context $context
3339
* @param \Magento\Framework\Registry $coreRegistry
3440
* @param \Magento\Authorizenet\Helper\DataFactory $dataFactory
41+
* @param \Magento\Payment\Model\IframeService|null $iframeService
3542
*/
3643
public function __construct(
3744
\Magento\Framework\App\Action\Context $context,
3845
\Magento\Framework\Registry $coreRegistry,
39-
\Magento\Authorizenet\Helper\DataFactory $dataFactory
46+
\Magento\Authorizenet\Helper\DataFactory $dataFactory,
47+
\Magento\Payment\Model\IframeService $iframeService = null
4048
) {
4149
$this->_coreRegistry = $coreRegistry;
4250
$this->dataFactory = $dataFactory;
51+
$this->iframeService = $iframeService ?: \Magento\Framework\App\ObjectManager::getInstance()
52+
->get(\Magento\Payment\Model\IframeService::class);
4353
parent::__construct($context);
4454
}
4555

@@ -66,19 +76,17 @@ protected function _getDirectPostSession()
6676
* Action for Authorize.net SIM Relay Request.
6777
*
6878
* @param string $area
69-
* @param \Magento\Authorizenet\Model\Directpost $paymentMethod
70-
* @return \Magento\Framework\Controller\ResultInterface
79+
* @return void
80+
* @throws \Magento\Framework\Exception\LocalizedException
7181
*/
72-
protected function _responseAction($area = 'frontend', \Magento\Authorizenet\Model\Directpost $paymentMethod = null)
82+
protected function _responseAction($area = 'frontend')
7383
{
7484
$helper = $this->dataFactory->create($area);
75-
/** @var \Magento\Framework\View\Result\Page $resultPage */
76-
$resultPage = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
7785

7886
$params = [];
7987
$data = $this->getRequest()->getParams();
8088

81-
$paymentMethod = $this->getPaymentMethod($paymentMethod);
89+
$paymentMethod = $this->_objectManager->create(\Magento\Authorizenet\Model\Directpost::class);
8290

8391
$result = [];
8492
if (!empty($data['x_invoice_num'])) {
@@ -113,21 +121,8 @@ protected function _responseAction($area = 'frontend', \Magento\Authorizenet\Mod
113121
$params['redirect'] = $helper->getRedirectIframeUrl($result);
114122
}
115123

116-
//registering parameter for iframe content
117-
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, $params);
118-
return $resultPage;
119-
}
120-
121-
/**
122-
* @param \Magento\Authorizenet\Model\Directpost|null $paymentMethod
123-
* @return \Magento\Authorizenet\Model\Directpost
124-
*/
125-
private function getPaymentMethod(\Magento\Authorizenet\Model\Directpost $paymentMethod = null)
126-
{
127-
if (empty($paymentMethod)) {
128-
$paymentMethod = $this->_objectManager->create(\Magento\Authorizenet\Model\Directpost::class);
129-
}
130-
return $paymentMethod;
124+
//registering response parameters for iframe content
125+
$this->iframeService->setParams($params);
131126
}
132127

133128
/**

app/code/Magento/Authorizenet/Controller/Directpost/Payment/BackendResponse.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class BackendResponse extends \Magento\Authorizenet\Controller\Directpost\Paymen
1616
*/
1717
public function execute()
1818
{
19-
return $this->_responseAction('adminhtml');
19+
$this->_responseAction('adminhtml');
20+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
2021
}
2122
}

app/code/Magento/Authorizenet/Controller/Directpost/Payment/Redirect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function execute()
4646
unset($params['redirect_parent']);
4747
}
4848

49-
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, $params);
49+
$this->_objectManager->get(\Magento\Payment\Model\IframeService::class)->setParams($params);
5050
$this->_view->addPageLayoutHandles();
5151
$this->_view->loadLayout(false)->renderLayout();
5252
}

app/code/Magento/Authorizenet/Controller/Directpost/Payment/Response.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,8 @@
66
*/
77
namespace Magento\Authorizenet\Controller\Directpost\Payment;
88

9-
use Magento\Authorizenet\Model\DirectpostFactory;
10-
119
class Response extends \Magento\Authorizenet\Controller\Directpost\Payment
1210
{
13-
/** @var \Magento\Authorizenet\Model\DirectpostFactory */
14-
private $directpostFactory;
15-
16-
/**
17-
* Constructor
18-
*
19-
* @param \Magento\Framework\App\Action\Context $context
20-
* @param \Magento\Framework\Registry $coreRegistry
21-
* @param \Magento\Authorizenet\Helper\DataFactory $dataFactory
22-
* @param \Magento\Authorizenet\Model\DirectpostFactory|null $directpostFactory
23-
*/
24-
public function __construct(
25-
\Magento\Framework\App\Action\Context $context,
26-
\Magento\Framework\Registry $coreRegistry,
27-
\Magento\Authorizenet\Helper\DataFactory $dataFactory,
28-
\Magento\Authorizenet\Model\DirectpostFactory $directpostFactory = null
29-
) {
30-
parent::__construct($context, $coreRegistry, $dataFactory);
31-
$this->directpostFactory = $directpostFactory ? : $this->_objectManager->create(DirectpostFactory::class);
32-
}
33-
3411
/**
3512
* Response action.
3613
* Action for Authorize.net SIM Relay Request.
@@ -39,6 +16,7 @@ public function __construct(
3916
*/
4017
public function execute()
4118
{
42-
return $this->_responseAction('frontend', $this->directpostFactory->create());
19+
$this->_responseAction('frontend');
20+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
4321
}
4422
}

app/code/Magento/Payment/Block/Transparent/Iframe.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,51 @@ class Iframe extends \Magento\Framework\View\Element\Template
1717
/**
1818
* Core registry
1919
*
20+
* @deprecated
2021
* @var \Magento\Framework\Registry
2122
*/
2223
protected $coreRegistry;
2324

2425
/**
25-
* Constructor
26-
*
26+
* @var \Magento\Payment\Model\IframeService
27+
*/
28+
private $iframeService;
29+
30+
/**
2731
* @param \Magento\Framework\View\Element\Template\Context $context
2832
* @param \Magento\Framework\Registry $registry
2933
* @param array $data
34+
* @param \Magento\Payment\Model\IframeService|null $iframeService
3035
*/
3136
public function __construct(
3237
\Magento\Framework\View\Element\Template\Context $context,
3338
\Magento\Framework\Registry $registry,
34-
array $data = []
39+
array $data = [],
40+
\Magento\Payment\Model\IframeService $iframeService = null
3541
) {
3642
$this->coreRegistry = $registry;
43+
$this->iframeService = $iframeService ?: \Magento\Framework\App\ObjectManager::getInstance()
44+
->get(\Magento\Payment\Model\IframeService::class);
3745
parent::__construct($context, $data);
3846
}
3947

4048
/**
41-
* Override this method in descendants to produce html
49+
* Set params once per request
50+
*
51+
* @return $this
52+
*/
53+
public function setParams(array $params)
54+
{
55+
return $this->iframeService->setParams($params);
56+
}
57+
58+
/**
59+
* Return params
4260
*
43-
* @return string
61+
* @return $this
4462
*/
45-
protected function _toHtml()
63+
public function getParams()
4664
{
47-
$params = $this->getParams();
48-
if (empty($params)) {
49-
$params = $this->coreRegistry->registry(self::REGISTRY_KEY);
50-
}
51-
$this->setParams($params);
52-
return parent::_toHtml();
65+
return $this->iframeService->getParams();
5366
}
5467
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Model;
7+
8+
/**
9+
* Class IframeService
10+
* Inject this into the response control decision class for payment a method on a single request
11+
*/
12+
class IframeService
13+
{
14+
/**
15+
* @var array
16+
*/
17+
private $params = [];
18+
19+
/**
20+
* @var bool
21+
*/
22+
private $isParamsSet = false;
23+
24+
/**
25+
* This method can set only once the parameters to prevent other classes from modifying response
26+
*
27+
* @param array $params
28+
* @return $this
29+
* @throws \Magento\Framework\Exception\LocalizedException
30+
*/
31+
public function setParams(array $params)
32+
{
33+
if (!$this->isParamsSet) {
34+
$this->params = $params;
35+
$this->isParamsSet = true;
36+
} else {
37+
throw new \Magento\Framework\Exception\LocalizedException(
38+
__('Parameters can not be set in the service class more than once per request.')
39+
);
40+
}
41+
return $this;
42+
}
43+
44+
/**
45+
* This method can set only once the parameters to prevent other classes from modifying response
46+
*
47+
* @return array
48+
* @throws \Magento\Framework\Exception\LocalizedException
49+
*/
50+
public function getParams()
51+
{
52+
if (!$this->isParamsSet) {
53+
throw new \Magento\Framework\Exception\LocalizedException(
54+
__('Parameters are not set on this request.')
55+
);
56+
}
57+
return $this->params;
58+
}
59+
}

app/code/Magento/Paypal/Controller/Transparent/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function execute()
8888
$parameters['error_msg'] = $exception->getMessage();
8989
}
9090

91-
$this->coreRegistry->register(Iframe::REGISTRY_KEY, $parameters);
91+
$this->_objectManager->get(\Magento\Payment\Model\IframeService::class)->setParams($parameters);
9292

9393
$resultLayout = $this->resultLayoutFactory->create();
9494
$resultLayout->addDefaultHandle();

0 commit comments

Comments
 (0)