Skip to content

Commit d6cee84

Browse files
committed
MAGETWO-69110: Incorrect status for order placed within Authorize.net with Fraud Filters Triggered (Filter Actions = Process as normal and report filter(s) triggered)
- Added check for FDSFilterAction
1 parent bab4284 commit d6cee84

File tree

4 files changed

+237
-6
lines changed

4 files changed

+237
-6
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: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
*/
66
namespace Magento\Authorizenet\Model;
77

8+
use Magento\Framework\Simplexml\Element;
89
use Magento\Framework\Api\FilterBuilder;
910
use Magento\Framework\Api\SearchCriteriaBuilder;
1011
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\HTTP\ZendClient;
1213
use Magento\Framework\HTTP\ZendClientFactory;
1314
use Magento\Sales\Api\Data\OrderInterface;
1415
use Magento\Sales\Api\OrderRepositoryInterface;
16+
use Magento\Sales\Model\Order;
1517
use Magento\Sales\Model\Order\Payment;
1618
use Magento\TestFramework\Helper\Bootstrap;
1719
use PHPUnit_Framework_MockObject_MockObject as MockObject;
@@ -59,7 +61,7 @@ public function testCapture()
5961
{
6062
$amount = 120.15;
6163
/** @var Payment $payment */
62-
$payment = $this->getPayment();
64+
$payment = $this->getPayment('100000002');
6365
$transactionId = '106235225';
6466

6567
/** @var ZendClient|MockObject $httpClient */
@@ -99,17 +101,114 @@ public function testCapture()
99101
static::assertEquals('UK', $payment->getOrder()->getShippingAddress()->getCountryId());
100102
}
101103

104+
105+
/**
106+
* Verifies that order is placed in correct state according the action taken for a transaction that
107+
* triggered one or more of the Advanced Fraud Detection Suite filters.
108+
*
109+
* @param string $filterAction
110+
* @param string $orderId
111+
* @param string $expectedOrderState
112+
*
113+
* @magentoConfigFixture current_store payment/authorizenet_directpost/trans_md5 TestHash
114+
* @magentoConfigFixture current_store payment/authorizenet_directpost/login TestLogin
115+
* @magentoDataFixture Magento/Authorizenet/_files/order.php
116+
* @dataProvider fdsFilterActionDataProvider
117+
*/
118+
public function testProcessWithFdsFilterActionReportOnly($filterAction, $orderId, $expectedOrderState)
119+
{
120+
$responseBody = $this->getSuccessResponse($orderId);
121+
$transactionService = $this->getTransactionService($filterAction);
122+
$this->objectManager->addSharedInstance($transactionService, TransactionService::class);
123+
124+
$this->directPost->process($responseBody);
125+
126+
/** @var Payment $payment */
127+
$payment = $this->getPayment($orderId);
128+
$this->objectManager->removeSharedInstance(TransactionService::class);
129+
130+
static::assertEquals($expectedOrderState, $payment->getOrder()->getState());
131+
}
132+
133+
/**
134+
* @return array
135+
*/
136+
public function fdsFilterActionDataProvider()
137+
{
138+
return [
139+
['filter_action' => 'authAndHold', 'order_id' => '100000003', 'expected_order_state' => Order::STATE_PAYMENT_REVIEW],
140+
['filter_action' => 'report', 'order_id' => '100000004', 'expected_order_state' => Order::STATE_PROCESSING],
141+
];
142+
}
143+
102144
/**
103-
* Get order payment
145+
* @param string $orderId
146+
* @return array
147+
*/
148+
private function getSuccessResponse($orderId)
149+
{
150+
return [
151+
'x_response_code' => '1',
152+
'x_response_reason_code' => '1',
153+
'x_response_reason_text' => 'This transaction has been approved.',
154+
'x_avs_code' => 'Y',
155+
'x_auth_code' => 'YWO2E2',
156+
'x_trans_id' => '40004862720',
157+
'x_method' => 'CC',
158+
'x_card_type' => 'Visa',
159+
'x_account_number' => 'XXXX1111',
160+
'x_first_name' => 'John',
161+
'x_last_name' => 'Smith',
162+
'x_company' => 'CompanyName',
163+
'x_address' => 'Green str, 67',
164+
'x_city' => 'CityM',
165+
'x_state' => 'Alabama',
166+
'x_zip' => '93930',
167+
'x_country' => 'US',
168+
'x_phone' => '3468676',
169+
'x_fax' => '04040404',
170+
'x_email' => 'user_1@example.com',
171+
'x_invoice_num' => $orderId,
172+
'x_description' => '',
173+
'x_type' => 'auth_only',
174+
'x_cust_id' => '',
175+
'x_ship_to_first_name' => 'John',
176+
'x_ship_to_last_name' => 'Smith',
177+
'x_ship_to_company' => 'CompanyName',
178+
'x_ship_to_address' => 'Green str, 67',
179+
'x_ship_to_city' => 'CityM',
180+
'x_ship_to_state' => 'Alabama',
181+
'x_ship_to_zip' => '93930',
182+
'x_ship_to_country' => 'US',
183+
'x_amount' => '120.15',
184+
'x_tax' => '0.00',
185+
'x_duty' => '0.00',
186+
'x_freight' => '5.00',
187+
'x_tax_exempt' => 'FALSE',
188+
'x_po_num' => '',
189+
'x_MD5_Hash' => 'C1CC5AB9D6F0481E240AD74DFF624584',
190+
'x_SHA2_Hash' => '',
191+
'x_cvv2_resp_code' => 'P',
192+
'x_cavv_response' => '2',
193+
'x_test_request' => 'false',
194+
'controller_action_name' => 'directpost_payment',
195+
'is_secure' => '1',
196+
];
197+
}
198+
199+
/**
200+
* Get order payment.
201+
*
202+
* @param string $orderId
104203
* @return Payment
105204
*/
106-
private function getPayment()
205+
private function getPayment($orderId)
107206
{
108207
/** @var FilterBuilder $filterBuilder */
109208
$filterBuilder = $this->objectManager->get(FilterBuilder::class);
110209
$filters = [
111210
$filterBuilder->setField(OrderInterface::INCREMENT_ID)
112-
->setValue('100000002')
211+
->setValue($orderId)
113212
->create()
114213
];
115214

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

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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<getTransactionDetailsResponse>
3+
<messages>
4+
<resultCode>Ok</resultCode>
5+
<message>
6+
<code>I00001</code>
7+
<text>Successful.</text>
8+
</message>
9+
</messages>
10+
<transaction>
11+
<transId>40004862720</transId>
12+
<submitTimeUTC>2017-06-12T13:33:10.1Z</submitTimeUTC>
13+
<submitTimeLocal>2017-06-12T06:33:10.1</submitTimeLocal>
14+
<transactionType>authOnlyTransaction</transactionType>
15+
<transactionStatus>authorizedPendingCapture</transactionStatus>
16+
<responseCode>1</responseCode>
17+
<responseReasonCode>1</responseReasonCode>
18+
<responseReasonDescription>Approval</responseReasonDescription>
19+
<authCode>YWO2E2</authCode>
20+
<AVSResponse>Y</AVSResponse>
21+
<cardCodeResponse>P</cardCodeResponse>
22+
<FDSFilterAction>{filterAction}</FDSFilterAction>
23+
<FDSFilters>
24+
<FDSFilter>
25+
<name>Amount Filter</name>
26+
<action>{filterAction}</action>
27+
</FDSFilter>
28+
</FDSFilters>
29+
<order>
30+
<invoiceNumber>100000002</invoiceNumber>
31+
</order>
32+
<authAmount>120.15</authAmount>
33+
<settleAmount>120.15</settleAmount>
34+
<shipping>
35+
<amount>5.00</amount>
36+
</shipping>
37+
<taxExempt>false</taxExempt>
38+
<payment>
39+
<creditCard>
40+
<cardNumber>XXXX1111</cardNumber>
41+
<expirationDate>XXXX</expirationDate>
42+
<cardType>Visa</cardType>
43+
</creditCard>
44+
</payment>
45+
<customer>
46+
<email>user_1@example.com</email>
47+
</customer>
48+
<billTo>
49+
<firstName>John</firstName>
50+
<lastName>Smith</lastName>
51+
<company>CompanyName</company>
52+
<address>Green str, 67</address>
53+
<city>CityM</city>
54+
<state>Alabama</state>
55+
<zip>93930</zip>
56+
<country>US</country>
57+
<phoneNumber>3468676</phoneNumber>
58+
<faxNumber>04040404</faxNumber>
59+
</billTo>
60+
<shipTo>
61+
<firstName>John</firstName>
62+
<lastName>Smith</lastName>
63+
<company>CompanyName</company>
64+
<address>Green str, 67</address>
65+
<city>CityM</city>
66+
<state>Alabama</state>
67+
<zip>93930</zip>
68+
<country>US</country>
69+
</shipTo>
70+
<recurringBilling>false</recurringBilling>
71+
<customerIP>195.14.124.5</customerIP>
72+
<product>Card Not Present</product>
73+
<marketType>eCommerce</marketType>
74+
</transaction>
75+
</getTransactionDetailsResponse>

0 commit comments

Comments
 (0)