Skip to content

Commit 99da6e2

Browse files
committed
Merge remote-tracking branch 'remotes/origin/MAGETWO-69110' into MPI-PR-Bugfixes
2 parents 22ed99f + 5a78f0b commit 99da6e2

File tree

4 files changed

+250
-16
lines changed

4 files changed

+250
-16
lines changed

app/code/Magento/Authorizenet/Model/Directpost.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,11 @@ protected function processPaymentFraudStatus(\Magento\Sales\Model\Order\Payment
744744
return $this;
745745
}
746746

747-
$payment->setIsFraudDetected(true);
747+
$fdsFilterAction = (string)$fraudDetailsResponse->getFdsFilterAction();
748+
if ($this->fdsFilterActionIsReportOnly($fdsFilterAction) === false) {
749+
$payment->setIsFraudDetected(true);
750+
}
751+
748752
$payment->setAdditionalInformation('fraud_details', $fraudData);
749753
} catch (\Exception $e) {
750754
//this request is optional
@@ -989,4 +993,16 @@ private function getPsrLogger()
989993
}
990994
return $this->psrLogger;
991995
}
996+
997+
/**
998+
* Checks if filter action is Report Only. Transactions that trigger this filter are processed as normal,
999+
* but are also reported in the Merchant Interface as triggering this filter.
1000+
*
1001+
* @param string $fdsFilterAction
1002+
* @return bool
1003+
*/
1004+
private function fdsFilterActionIsReportOnly($fdsFilterAction)
1005+
{
1006+
return $fdsFilterAction === (string)$this->dataHelper->getFdsFilterActionLabel('report');
1007+
}
9921008
}

dev/tests/integration/testsuite/Magento/Authorizenet/Model/DirectpostTest.php

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
*/
66
namespace Magento\Authorizenet\Model;
77

8-
use Magento\Framework\Api\FilterBuilder;
98
use Magento\Framework\Api\SearchCriteriaBuilder;
109
use Magento\Framework\App\ObjectManager;
1110
use Magento\Framework\HTTP\ZendClient;
1211
use Magento\Framework\HTTP\ZendClientFactory;
12+
use Magento\Framework\Simplexml\Element;
1313
use Magento\Sales\Api\Data\OrderInterface;
1414
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Sales\Model\Order;
1516
use Magento\Sales\Model\Order\Payment;
1617
use Magento\TestFramework\Helper\Bootstrap;
1718
use PHPUnit_Framework_MockObject_MockObject as MockObject;
18-
use Zend_Http_Response;
1919

2020
/**
2121
* Class contains tests for Direct Post integration
@@ -59,7 +59,7 @@ public function testCapture()
5959
{
6060
$amount = 120.15;
6161
/** @var Payment $payment */
62-
$payment = $this->getPayment();
62+
$payment = $this->getPayment('100000002');
6363
$transactionId = '106235225';
6464

6565
/** @var ZendClient|MockObject $httpClient */
@@ -72,7 +72,7 @@ public function testCapture()
7272
->method('create')
7373
->willReturn($httpClient);
7474

75-
$response = $this->getMockBuilder(Zend_Http_Response::class)
75+
$response = $this->getMockBuilder('Zend_Http_Response')
7676
->disableOriginalConstructor()
7777
->setMethods(['getBody'])
7878
->getMock();
@@ -100,22 +100,118 @@ public function testCapture()
100100
}
101101

102102
/**
103-
* Get order payment
104-
* @return Payment
103+
* Verifies that order is placed in correct state according the action taken for a transaction that
104+
* triggered one or more of the Advanced Fraud Detection Suite filters.
105+
*
106+
* @param string $filterAction
107+
* @param string $orderId
108+
* @param string $expectedOrderState
109+
*
110+
* @magentoConfigFixture current_store payment/authorizenet_directpost/trans_md5 TestHash
111+
* @magentoConfigFixture current_store payment/authorizenet_directpost/login TestLogin
112+
* @magentoDataFixture Magento/Authorizenet/_files/order.php
113+
* @dataProvider fdsFilterActionDataProvider
105114
*/
106-
private function getPayment()
115+
public function testProcessWithFdsFilterActionReportOnly($filterAction, $orderId, $expectedOrderState)
107116
{
108-
/** @var FilterBuilder $filterBuilder */
109-
$filterBuilder = $this->objectManager->get(FilterBuilder::class);
110-
$filters = [
111-
$filterBuilder->setField(OrderInterface::INCREMENT_ID)
112-
->setValue('100000002')
113-
->create()
117+
$responseBody = $this->getSuccessResponse($orderId);
118+
$transactionService = $this->getTransactionService($filterAction);
119+
$this->objectManager->addSharedInstance($transactionService, TransactionService::class);
120+
121+
$this->directPost->process($responseBody);
122+
123+
/** @var Payment $payment */
124+
$payment = $this->getPayment($orderId);
125+
$this->objectManager->removeSharedInstance(TransactionService::class);
126+
127+
static::assertEquals($expectedOrderState, $payment->getOrder()->getState());
128+
}
129+
130+
/**
131+
* @return array
132+
*/
133+
public function fdsFilterActionDataProvider()
134+
{
135+
return [
136+
[
137+
'filter_action' => 'authAndHold',
138+
'order_id' => '100000003',
139+
'expected_order_state' => Order::STATE_PAYMENT_REVIEW
140+
],
141+
[
142+
'filter_action' => 'report',
143+
'order_id' => '100000004',
144+
'expected_order_state' => Order::STATE_PROCESSING
145+
],
114146
];
147+
}
115148

149+
/**
150+
* @param string $orderId
151+
* @return array
152+
*/
153+
private function getSuccessResponse($orderId)
154+
{
155+
return [
156+
'x_response_code' => '1',
157+
'x_response_reason_code' => '1',
158+
'x_response_reason_text' => 'This transaction has been approved.',
159+
'x_avs_code' => 'Y',
160+
'x_auth_code' => 'YWO2E2',
161+
'x_trans_id' => '40004862720',
162+
'x_method' => 'CC',
163+
'x_card_type' => 'Visa',
164+
'x_account_number' => 'XXXX1111',
165+
'x_first_name' => 'John',
166+
'x_last_name' => 'Smith',
167+
'x_company' => 'CompanyName',
168+
'x_address' => 'Green str, 67',
169+
'x_city' => 'CityM',
170+
'x_state' => 'Alabama',
171+
'x_zip' => '93930',
172+
'x_country' => 'US',
173+
'x_phone' => '3468676',
174+
'x_fax' => '04040404',
175+
'x_email' => 'user_1@example.com',
176+
'x_invoice_num' => $orderId,
177+
'x_description' => '',
178+
'x_type' => 'auth_only',
179+
'x_cust_id' => '',
180+
'x_ship_to_first_name' => 'John',
181+
'x_ship_to_last_name' => 'Smith',
182+
'x_ship_to_company' => 'CompanyName',
183+
'x_ship_to_address' => 'Green str, 67',
184+
'x_ship_to_city' => 'CityM',
185+
'x_ship_to_state' => 'Alabama',
186+
'x_ship_to_zip' => '93930',
187+
'x_ship_to_country' => 'US',
188+
'x_amount' => '120.15',
189+
'x_tax' => '0.00',
190+
'x_duty' => '0.00',
191+
'x_freight' => '5.00',
192+
'x_tax_exempt' => 'FALSE',
193+
'x_po_num' => '',
194+
'x_MD5_Hash' => 'C1CC5AB9D6F0481E240AD74DFF624584',
195+
'x_SHA2_Hash' => '',
196+
'x_cvv2_resp_code' => 'P',
197+
'x_cavv_response' => '2',
198+
'x_test_request' => 'false',
199+
'controller_action_name' => 'directpost_payment',
200+
'is_secure' => '1',
201+
];
202+
}
203+
204+
/**
205+
* Get order payment.
206+
*
207+
* @param string $orderId
208+
* @return Payment
209+
*/
210+
private function getPayment($orderId)
211+
{
116212
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
117213
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
118-
$searchCriteria = $searchCriteriaBuilder->addFilters($filters)
214+
$searchCriteria = $searchCriteriaBuilder->addFilter(OrderInterface::INCREMENT_ID, $orderId)
119215
->create();
120216

121217
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
@@ -126,4 +222,29 @@ private function getPayment()
126222
$order = array_pop($orders);
127223
return $order->getPayment();
128224
}
225+
226+
/**
227+
* Returns TransactionService mocked object with authorize predefined response.
228+
*
229+
* @param string $filterAction
230+
* @return TransactionService|MockObject
231+
*/
232+
private function getTransactionService($filterAction)
233+
{
234+
$response = str_replace(
235+
'{filterAction}',
236+
$filterAction,
237+
file_get_contents(__DIR__ . '/../_files/transaction_details.xml')
238+
);
239+
240+
$transactionService = $this->getMockBuilder(TransactionService::class)
241+
->disableOriginalConstructor()
242+
->getMock();
243+
$transactionService->method('getTransactionDetails')
244+
->willReturn(
245+
new Element($response)
246+
);
247+
248+
return $transactionService;
249+
}
129250
}

dev/tests/integration/testsuite/Magento/Authorizenet/_files/order.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$amount = 120.15;
1515

1616
/** @var Payment $payment */
17-
$payment = $objectManager->get(Payment::class);
17+
$payment = $objectManager->create(Payment::class);
1818
$payment
1919
->setMethod('authorizenet_directpost')
2020
->setAnetTransType('AUTH_ONLY')
@@ -68,3 +68,19 @@
6868
/** @var OrderRepositoryInterface $orderRepository */
6969
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
7070
$orderRepository->save($order);
71+
72+
$clonedOrder = clone $order;
73+
$clonedOrder->setIncrementId('100000003')
74+
->setId(null)
75+
->setBillingAddress($billingAddress->setId(null))
76+
->setShippingAddress($shippingAddress->setId(null))
77+
->setPayment($payment->setId(null));
78+
$orderRepository->save($clonedOrder);
79+
80+
$clonedOrder = clone $order;
81+
$clonedOrder->setIncrementId('100000004')
82+
->setId(null)
83+
->setBillingAddress($billingAddress->setId(null))
84+
->setShippingAddress($shippingAddress->setId(null))
85+
->setPayment($payment->setId(null));
86+
$orderRepository->save($clonedOrder);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<getTransactionDetailsResponse>
9+
<messages>
10+
<resultCode>Ok</resultCode>
11+
<message>
12+
<code>I00001</code>
13+
<text>Successful.</text>
14+
</message>
15+
</messages>
16+
<transaction>
17+
<transId>40004862720</transId>
18+
<submitTimeUTC>2017-06-12T13:33:10.1Z</submitTimeUTC>
19+
<submitTimeLocal>2017-06-12T06:33:10.1</submitTimeLocal>
20+
<transactionType>authOnlyTransaction</transactionType>
21+
<transactionStatus>authorizedPendingCapture</transactionStatus>
22+
<responseCode>1</responseCode>
23+
<responseReasonCode>1</responseReasonCode>
24+
<responseReasonDescription>Approval</responseReasonDescription>
25+
<authCode>YWO2E2</authCode>
26+
<AVSResponse>Y</AVSResponse>
27+
<cardCodeResponse>P</cardCodeResponse>
28+
<FDSFilterAction>{filterAction}</FDSFilterAction>
29+
<FDSFilters>
30+
<FDSFilter>
31+
<name>Amount Filter</name>
32+
<action>{filterAction}</action>
33+
</FDSFilter>
34+
</FDSFilters>
35+
<order>
36+
<invoiceNumber>100000002</invoiceNumber>
37+
</order>
38+
<authAmount>120.15</authAmount>
39+
<settleAmount>120.15</settleAmount>
40+
<shipping>
41+
<amount>5.00</amount>
42+
</shipping>
43+
<taxExempt>false</taxExempt>
44+
<payment>
45+
<creditCard>
46+
<cardNumber>XXXX1111</cardNumber>
47+
<expirationDate>XXXX</expirationDate>
48+
<cardType>Visa</cardType>
49+
</creditCard>
50+
</payment>
51+
<customer>
52+
<email>user_1@example.com</email>
53+
</customer>
54+
<billTo>
55+
<firstName>John</firstName>
56+
<lastName>Smith</lastName>
57+
<company>CompanyName</company>
58+
<address>Green str, 67</address>
59+
<city>CityM</city>
60+
<state>Alabama</state>
61+
<zip>93930</zip>
62+
<country>US</country>
63+
<phoneNumber>3468676</phoneNumber>
64+
<faxNumber>04040404</faxNumber>
65+
</billTo>
66+
<shipTo>
67+
<firstName>John</firstName>
68+
<lastName>Smith</lastName>
69+
<company>CompanyName</company>
70+
<address>Green str, 67</address>
71+
<city>CityM</city>
72+
<state>Alabama</state>
73+
<zip>93930</zip>
74+
<country>US</country>
75+
</shipTo>
76+
<recurringBilling>false</recurringBilling>
77+
<customerIP>195.14.124.5</customerIP>
78+
<product>Card Not Present</product>
79+
<marketType>eCommerce</marketType>
80+
</transaction>
81+
</getTransactionDetailsResponse>

0 commit comments

Comments
 (0)