5
5
*/
6
6
namespace Magento \Authorizenet \Model ;
7
7
8
- use Magento \Framework \Api \FilterBuilder ;
9
8
use Magento \Framework \Api \SearchCriteriaBuilder ;
10
9
use Magento \Framework \App \ObjectManager ;
11
10
use Magento \Framework \HTTP \ZendClient ;
12
11
use Magento \Framework \HTTP \ZendClientFactory ;
12
+ use Magento \Framework \Simplexml \Element ;
13
13
use Magento \Sales \Api \Data \OrderInterface ;
14
14
use Magento \Sales \Api \OrderRepositoryInterface ;
15
+ use Magento \Sales \Model \Order ;
15
16
use Magento \Sales \Model \Order \Payment ;
16
17
use Magento \TestFramework \Helper \Bootstrap ;
17
18
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
18
- use Zend_Http_Response ;
19
19
20
20
/**
21
21
* Class contains tests for Direct Post integration
@@ -59,7 +59,7 @@ public function testCapture()
59
59
{
60
60
$ amount = 120.15 ;
61
61
/** @var Payment $payment */
62
- $ payment = $ this ->getPayment ();
62
+ $ payment = $ this ->getPayment (' 100000002 ' );
63
63
$ transactionId = '106235225 ' ;
64
64
65
65
/** @var ZendClient|MockObject $httpClient */
@@ -72,7 +72,7 @@ public function testCapture()
72
72
->method ('create ' )
73
73
->willReturn ($ httpClient );
74
74
75
- $ response = $ this ->getMockBuilder (Zend_Http_Response::class )
75
+ $ response = $ this ->getMockBuilder (' Zend_Http_Response ' )
76
76
->disableOriginalConstructor ()
77
77
->setMethods (['getBody ' ])
78
78
->getMock ();
@@ -100,22 +100,118 @@ public function testCapture()
100
100
}
101
101
102
102
/**
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
105
114
*/
106
- private function getPayment ( )
115
+ public function testProcessWithFdsFilterActionReportOnly ( $ filterAction , $ orderId , $ expectedOrderState )
107
116
{
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
+ ],
114
146
];
147
+ }
115
148
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
+ {
116
212
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
117
213
$ searchCriteriaBuilder = $ this ->objectManager ->get (SearchCriteriaBuilder::class);
118
- $ searchCriteria = $ searchCriteriaBuilder ->addFilters ( $ filters )
214
+ $ searchCriteria = $ searchCriteriaBuilder ->addFilter (OrderInterface:: INCREMENT_ID , $ orderId )
119
215
->create ();
120
216
121
217
$ orderRepository = $ this ->objectManager ->get (OrderRepositoryInterface::class);
@@ -126,4 +222,29 @@ private function getPayment()
126
222
$ order = array_pop ($ orders );
127
223
return $ order ->getPayment ();
128
224
}
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
+ }
129
250
}
0 commit comments