Skip to content

Commit 71f37b0

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'mainline/develop' into develop-prs
2 parents e67a97d + 119b950 commit 71f37b0

File tree

6 files changed

+316
-5
lines changed

6 files changed

+316
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ protected function _responseAction($area = 'frontend')
7373
$helper = $this->dataFactory->create($area);
7474

7575
$params = [];
76-
$data = $this->getRequest()->getPostValue();
76+
$data = $this->getRequest()->getParams();
77+
7778
/* @var $paymentMethod \Magento\Authorizenet\Model\DirectPost */
7879
$paymentMethod = $this->_objectManager->create(\Magento\Authorizenet\Model\Directpost::class);
7980

@@ -110,9 +111,8 @@ protected function _responseAction($area = 'frontend')
110111
$params['redirect'] = $helper->getRedirectIframeUrl($result);
111112
}
112113

114+
//registering parameter for iframe content
113115
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, $params);
114-
$this->_view->addPageLayoutHandles();
115-
$this->_view->loadLayout(false)->renderLayout();
116116
}
117117

118118
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ class BackendResponse extends \Magento\Authorizenet\Controller\Directpost\Paymen
1212
* Response action.
1313
* Action for Authorize.net SIM Relay Request.
1414
*
15-
* @return void
15+
* @return \Magento\Framework\Controller\ResultInterface
1616
*/
1717
public function execute()
1818
{
1919
$this->_responseAction('adminhtml');
20+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
2021
}
2122
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ class Response extends \Magento\Authorizenet\Controller\Directpost\Payment
1212
* Response action.
1313
* Action for Authorize.net SIM Relay Request.
1414
*
15-
* @return void
15+
* @return \Magento\Framework\Controller\ResultInterface
1616
*/
1717
public function execute()
1818
{
1919
$this->_responseAction('frontend');
20+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
2021
}
2122
}

dev/tests/functional/tests/app/Magento/Authorizenet/Test/Repository/ConfigData.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,37 @@
7171
<item name="value" xsi:type="number">0</item>
7272
</field>
7373
</dataset>
74+
<dataset name="authorizenet_authorize">
75+
<field name="payment/authorizenet_directpost/payment_action" xsi:type="array">
76+
<item name="scope" xsi:type="string">payment</item>
77+
<item name="scope_id" xsi:type="number">1</item>
78+
<item name="label" xsi:type="string"/>
79+
<item name="value" xsi:type="string">authorize_capture</item>
80+
</field>
81+
</dataset>
82+
<dataset name="authorizenet_authorize_rollback">
83+
<field name="payment/authorizenet_directpost/payment_action" xsi:type="array">
84+
<item name="scope" xsi:type="string">payment</item>
85+
<item name="scope_id" xsi:type="number">1</item>
86+
<item name="label" xsi:type="string"/>
87+
<item name="value" xsi:type="string">authorize</item>
88+
</field>
89+
</dataset>
90+
<dataset name="authorizenet_authorize_capture">
91+
<field name="payment/authorizenet_directpost/payment_action" xsi:type="array">
92+
<item name="scope" xsi:type="string">payment</item>
93+
<item name="scope_id" xsi:type="number">1</item>
94+
<item name="label" xsi:type="string"/>
95+
<item name="value" xsi:type="string">authorize_capture</item>
96+
</field>
97+
</dataset>
98+
<dataset name="authorizenet_authorize_capture_rollback">
99+
<field name="payment/authorizenet_directpost/payment_action" xsi:type="array">
100+
<item name="scope" xsi:type="string">payment</item>
101+
<item name="scope_id" xsi:type="number">1</item>
102+
<item name="label" xsi:type="string"/>
103+
<item name="value" xsi:type="string">authorize</item>
104+
</field>
105+
</dataset>
74106
</repository>
75107
</config>

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Info.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ class Info extends Block
2929
*/
3030
protected $group = '//th[text()="Customer Group"]/following-sibling::*';
3131

32+
/**
33+
* Item Options
34+
*
35+
* @var string
36+
*/
37+
protected $itemOptions = '//div[@class=\'product-sku-block\' and contains(normalize-space(.), \'{SKU}\')]'
38+
. '/following-sibling::*[@class="item-options"]';
39+
3240
/**
3341
* Get email from the data inside block
3442
*
@@ -48,4 +56,28 @@ public function getCustomerGroup()
4856
{
4957
return $this->_rootElement->find($this->group, Locator::SELECTOR_XPATH)->getText();
5058
}
59+
60+
/**
61+
* Get Product options
62+
*
63+
* @param int $sku
64+
* @return array
65+
*/
66+
public function getProductOptions($sku)
67+
{
68+
$selector = str_replace('{SKU}', $sku, $this->itemOptions);
69+
$productOption = $this->_rootElement->find($selector, Locator::SELECTOR_XPATH);
70+
$result = [];
71+
if ($productOption->isPresent()) {
72+
$keyItem = $productOption->getElements('dt');
73+
$valueItem = $productOption->getElements('dd');
74+
foreach ($keyItem as $key => $item) {
75+
$result[$item->getText()] = null;
76+
if (isset($valueItem[$key])) {
77+
$result[$item->getText()] = $valueItem[$key]->getText();
78+
}
79+
}
80+
}
81+
return $result;
82+
}
5183
}
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Authorizenet\Controller\Directpost\Payment;
7+
8+
/**
9+
* Class ResponseTest
10+
*
11+
* @magentoAppArea frontend
12+
*/
13+
class ResponseTest extends \Magento\TestFramework\TestCase\AbstractController
14+
{
15+
/**
16+
* Tests the controller for declines
17+
*
18+
* @param int $invoiceNum
19+
* @param string $hash
20+
* @param string $errorMsg
21+
* @param string[] $params
22+
*
23+
* @dataProvider responseActionAuthorizeCaptureDeclineDataProvider
24+
*/
25+
public function testResponseActionAuthorizeCaptureDecline($invoiceNum, $hash, $errorMsg, $params)
26+
{
27+
$controllerName = 'directpost_payment';
28+
$controllerModule = 'authorizenet';
29+
$controllerAction = 'response';
30+
$params['x_invoice_num'] = $invoiceNum;
31+
$params['x_MD5_Hash'] = $hash;
32+
$this->getRequest()->setControllerName(
33+
$controllerName
34+
)->setControllerModule(
35+
$controllerModule
36+
)->setActionName(
37+
$controllerAction
38+
)->setRouteName(
39+
$controllerModule
40+
)->setRequestUri("/{$controllerModule}/{$controllerName}/{$controllerAction}")
41+
->setParams($params);
42+
43+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
44+
45+
/** @var \Magento\Authorizenet\Controller\Directpost\Payment\Response */
46+
$controller = $objectManager->create(\Magento\Authorizenet\Controller\Directpost\Payment\Response::class);
47+
48+
$response = $controller->execute();
49+
$output = $response->getLayout()->getOutput();
50+
51+
$expectedString = "{$controllerModule}/{$controllerName}/redirect/x_invoice_num/{$params['x_invoice_num']}/"
52+
. "success/0/error_msg/{$errorMsg}/controller_action_name/{$controllerName}/";
53+
54+
$this->assertContains('window.location', $output);
55+
$this->assertContains($expectedString, $output);
56+
}
57+
58+
/**
59+
* Tests the controller for created blocks used for sending emails that should not affect layout response
60+
*
61+
* @param string $hash
62+
* @param string[] $params
63+
*
64+
* @dataProvider responseActionAuthorizeCaptureSuccessDataProvider
65+
*/
66+
public function testBlockCreationAffectingResult($hash, $params)
67+
{
68+
$controllerName = 'directpost_payment';
69+
$controllerModule = 'authorizenet';
70+
$controllerAction = 'response';
71+
$params['x_invoice_num'] = 100000002;
72+
$params['x_MD5_Hash'] = $hash;
73+
$this->getRequest()->setControllerName(
74+
$controllerName
75+
)->setControllerModule(
76+
$controllerModule
77+
)->setActionName(
78+
$controllerAction
79+
)->setRouteName(
80+
$controllerModule
81+
)->setRequestUri("/{$controllerModule}/{$controllerName}/{$controllerAction}")
82+
->setParams($params);
83+
84+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
85+
86+
$directpostMock = $this->getMockBuilder(\Magento\Authorizenet\Model\Directpost::class)
87+
->disableOriginalConstructor()
88+
->getMock();
89+
$objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
90+
->setMethods(['create'])
91+
->getMockForAbstractClass();
92+
$objectManagerMock->expects($this->atLeastOnce())
93+
->method('create')
94+
->with(\Magento\Authorizenet\Model\Directpost::class)
95+
->willReturn($directpostMock);
96+
$context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
97+
\Magento\Backend\App\Action\Context::class,
98+
[
99+
'objectManager' => $objectManagerMock
100+
]
101+
);
102+
103+
/** @var \Magento\Authorizenet\Controller\Directpost\Payment\Response $controller */
104+
$controller = $objectManager->create(
105+
\Magento\Authorizenet\Controller\Directpost\Payment\Response::class,
106+
[
107+
'context' => $context
108+
]
109+
);
110+
111+
// create one block for potential layout stack modification that should not affect response
112+
/** @var \Magento\Authorizenet\Block\Adminhtml\Order\View\Info\FraudDetails $block */
113+
$block = $objectManager->get(\Magento\Framework\View\LayoutInterface::class)
114+
->createBlock(\Magento\Authorizenet\Block\Adminhtml\Order\View\Info\FraudDetails::class);
115+
$block->setTemplate('Magento_Payment::order/view/info/fraud_details.phtml');
116+
117+
$response = $controller->execute();
118+
$output = $response->getLayout()->getOutput();
119+
120+
$expectedString = "{$controllerModule}/{$controllerName}/redirect/x_invoice_num/{$params['x_invoice_num']}/"
121+
. "success/1/controller_action_name/{$controllerName}/";
122+
123+
$this->assertContains('window.location', $output);
124+
$this->assertContains($expectedString, $output);
125+
}
126+
127+
/**
128+
* @return array
129+
*/
130+
public function responseActionAuthorizeCaptureDeclineDataProvider()
131+
{
132+
$postArray = [
133+
'x_response_code' => 1,
134+
'x_response_reason_code' => 1,
135+
'x_response_reason_text' => 'This transaction has been approved.',
136+
'x_avs_code' => 'Y',
137+
'x_auth_code' => 'G0L0XR',
138+
'x_trans_id' => '60016479791',
139+
'x_method' => 'CC',
140+
'x_card_type' => 'American Express',
141+
'x_account_number' => 'XXXX0002',
142+
'x_first_name' => 'Name',
143+
'x_last_name' => 'Surname',
144+
'x_company' => null,
145+
'x_address' => 'Address',
146+
'x_city' => 'Austin',
147+
'x_state' => 'Texas',
148+
'x_zip' => '78753',
149+
'x_country' => 'US',
150+
'x_phone' => '5127242323',
151+
'x_fax' => null,
152+
'x_email' => 'customer@example.com',
153+
'x_description' => null,
154+
'x_type' => 'auth_capture',
155+
'x_cust_id' => null,
156+
'x_ship_to_first_name' => null,
157+
'x_ship_to_last_name' => null,
158+
'x_ship_to_company' => null,
159+
'x_ship_to_address' => null,
160+
'x_ship_to_city' => null,
161+
'x_ship_to_state' => null,
162+
'x_ship_to_zip' => null,
163+
'x_ship_to_country' => null,
164+
'x_amount' => 100.00,
165+
'x_tax' => 0.00,
166+
'x_duty' => 0.00,
167+
'x_freight' => 0.00,
168+
'x_tax_exempt' => false,
169+
'x_po_num' => null,
170+
'x_SHA2_Hash' => null,
171+
'x_cvv2_resp_code' => 'P',
172+
'x_cavv_response' => 2,
173+
'x_test_request' => false,
174+
'controller_action_name' => 'directpost_payment',
175+
'is_secure' => null
176+
];
177+
return [
178+
'error_hash' => [
179+
'invoice_num' => '1231231',
180+
'x_MD5_Hash' => 'F9AE81A5DA36057D1312D71C904FCCF2',
181+
'error_msg' => 'The%20transaction%20was%20declined%20because%20the%20'
182+
. 'response%20hash%20validation%20failed.',
183+
'post' => $postArray
184+
]
185+
];
186+
}
187+
188+
/**
189+
* @return array
190+
*/
191+
public function responseActionAuthorizeCaptureSuccessDataProvider()
192+
{
193+
$postArray = [
194+
'x_response_code' => 1,
195+
'x_response_reason_code' => 1,
196+
'x_response_reason_text' => 'This transaction has been approved.',
197+
'x_avs_code' => 'Y',
198+
'x_auth_code' => 'G0L0XR',
199+
'x_trans_id' => '60016479791',
200+
'x_method' => 'CC',
201+
'x_card_type' => 'American Express',
202+
'x_account_number' => 'XXXX0002',
203+
'x_first_name' => 'Name',
204+
'x_last_name' => 'Surname',
205+
'x_company' => null,
206+
'x_address' => 'Address',
207+
'x_city' => 'Austin',
208+
'x_state' => 'Texas',
209+
'x_zip' => '78753',
210+
'x_country' => 'US',
211+
'x_phone' => '5127242323',
212+
'x_fax' => null,
213+
'x_email' => 'integrationtest@magento.com',
214+
'x_description' => null,
215+
'x_type' => 'auth_capture',
216+
'x_cust_id' => null,
217+
'x_ship_to_first_name' => null,
218+
'x_ship_to_last_name' => null,
219+
'x_ship_to_company' => null,
220+
'x_ship_to_address' => null,
221+
'x_ship_to_city' => null,
222+
'x_ship_to_state' => null,
223+
'x_ship_to_zip' => null,
224+
'x_ship_to_country' => null,
225+
'x_amount' => 120.15,
226+
'x_tax' => 0.00,
227+
'x_duty' => 0.00,
228+
'x_freight' => 0.00,
229+
'x_tax_exempt' => false,
230+
'x_po_num' => null,
231+
'x_SHA2_Hash' => null,
232+
'x_cvv2_resp_code' => 'P',
233+
'x_cavv_response' => 2,
234+
'x_test_request' => false,
235+
'controller_action_name' => 'directpost_payment',
236+
'is_secure' => null
237+
];
238+
return [
239+
'success' => [
240+
'x_MD5_Hash' => '35DCF749F7760193FB8254886E1D1522',
241+
'post' => $postArray
242+
],
243+
];
244+
}
245+
}

0 commit comments

Comments
 (0)