5
5
*/
6
6
namespace Magento \Authorizenet \Model ;
7
7
8
+ use Magento \Framework \Simplexml \Element ;
8
9
use Magento \Framework \Api \FilterBuilder ;
9
10
use Magento \Framework \Api \SearchCriteriaBuilder ;
10
11
use Magento \Framework \App \ObjectManager ;
11
12
use Magento \Framework \HTTP \ZendClient ;
12
13
use Magento \Framework \HTTP \ZendClientFactory ;
13
14
use Magento \Sales \Api \Data \OrderInterface ;
14
15
use Magento \Sales \Api \OrderRepositoryInterface ;
16
+ use Magento \Sales \Model \Order ;
15
17
use Magento \Sales \Model \Order \Payment ;
16
18
use Magento \TestFramework \Helper \Bootstrap ;
17
19
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
@@ -59,7 +61,7 @@ public function testCapture()
59
61
{
60
62
$ amount = 120.15 ;
61
63
/** @var Payment $payment */
62
- $ payment = $ this ->getPayment ();
64
+ $ payment = $ this ->getPayment (' 100000002 ' );
63
65
$ transactionId = '106235225 ' ;
64
66
65
67
/** @var ZendClient|MockObject $httpClient */
@@ -99,17 +101,114 @@ public function testCapture()
99
101
static ::assertEquals ('UK ' , $ payment ->getOrder ()->getShippingAddress ()->getCountryId ());
100
102
}
101
103
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
+
102
144
/**
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
104
203
* @return Payment
105
204
*/
106
- private function getPayment ()
205
+ private function getPayment ($ orderId )
107
206
{
108
207
/** @var FilterBuilder $filterBuilder */
109
208
$ filterBuilder = $ this ->objectManager ->get (FilterBuilder::class);
110
209
$ filters = [
111
210
$ filterBuilder ->setField (OrderInterface::INCREMENT_ID )
112
- ->setValue (' 100000002 ' )
211
+ ->setValue ($ orderId )
113
212
->create ()
114
213
];
115
214
@@ -126,4 +225,29 @@ private function getPayment()
126
225
$ order = array_pop ($ orders );
127
226
return $ order ->getPayment ();
128
227
}
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
+ }
129
253
}
0 commit comments