@@ -284,4 +284,123 @@ public function testGet()
284
284
285
285
$ this ->assertEquals ('checkmo ' , $ requestResponse ['method ' ]);
286
286
}
287
+
288
+ /**
289
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
290
+ */
291
+ public function testGetListMine ()
292
+ {
293
+ $ this ->_markTestAsRestOnly ();
294
+
295
+ /** @var \Magento\Quote\Model\Quote $quote */
296
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
297
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
298
+
299
+ $ serviceInfo = [
300
+ 'rest ' => [
301
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/payment-methods ' ,
302
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_GET ,
303
+ 'token ' => $ this ->getCustomerToken ()
304
+ ]
305
+ ];
306
+
307
+ $ requestResponse = $ this ->_webApiCall ($ serviceInfo );
308
+
309
+ $ expectedResponse = [
310
+ 'code ' => 'checkmo ' ,
311
+ 'title ' => 'Check / Money order ' ,
312
+ ];
313
+
314
+ $ this ->assertGreaterThan (0 , count ($ requestResponse ));
315
+ $ this ->assertContains ($ expectedResponse , $ requestResponse );
316
+ }
317
+
318
+
319
+ /**
320
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php
321
+ */
322
+ public function testGetMine ()
323
+ {
324
+ $ this ->_markTestAsRestOnly ();
325
+
326
+ /** @var \Magento\Quote\Model\Quote $quote */
327
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
328
+ $ quote ->load ('test_order_1_with_payment ' , 'reserved_order_id ' );
329
+
330
+ $ serviceInfo = [
331
+ 'rest ' => [
332
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/selected-payment-methods ' ,
333
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_GET ,
334
+ 'token ' => $ this ->getCustomerToken ()
335
+ ]
336
+ ];
337
+
338
+ $ requestResponse = $ this ->_webApiCall ($ serviceInfo );
339
+
340
+ $ this ->assertArrayHasKey ('method ' , $ requestResponse );
341
+ $ this ->assertArrayHasKey ('po_number ' , $ requestResponse );
342
+ $ this ->assertArrayHasKey ('cc_owner ' , $ requestResponse );
343
+ $ this ->assertArrayHasKey ('cc_type ' , $ requestResponse );
344
+ $ this ->assertArrayHasKey ('cc_exp_year ' , $ requestResponse );
345
+ $ this ->assertArrayHasKey ('cc_exp_month ' , $ requestResponse );
346
+ $ this ->assertArrayHasKey ('additional_data ' , $ requestResponse );
347
+
348
+ $ this ->assertNotNull ($ requestResponse ['method ' ]);
349
+ $ this ->assertNotNull ($ requestResponse ['po_number ' ]);
350
+ $ this ->assertNotNull ($ requestResponse ['cc_owner ' ]);
351
+ $ this ->assertNotNull ($ requestResponse ['cc_type ' ]);
352
+ $ this ->assertNotNull ($ requestResponse ['cc_exp_year ' ]);
353
+ $ this ->assertNotNull ($ requestResponse ['cc_exp_month ' ]);
354
+ $ this ->assertNotNull ($ requestResponse ['additional_data ' ]);
355
+
356
+ $ this ->assertEquals ('checkmo ' , $ requestResponse ['method ' ]);
357
+ }
358
+
359
+ /**
360
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
361
+ */
362
+ public function testSetPaymentWithSimpleProductMine ()
363
+ {
364
+ $ this ->_markTestAsRestOnly ();
365
+
366
+ /** @var \Magento\Quote\Model\Quote $quote */
367
+ $ quote = $ this ->objectManager ->create ('\Magento\Quote\Model\Quote ' );
368
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
369
+
370
+ $ serviceInfo = [
371
+ 'rest ' => [
372
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/selected-payment-methods ' ,
373
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_PUT ,
374
+ 'token ' => $ this ->getCustomerToken ()
375
+ ]
376
+ ];
377
+
378
+ $ requestData = [
379
+ "method " => [
380
+ 'method ' => 'checkmo ' ,
381
+ 'po_number ' => '200 ' ,
382
+ 'cc_owner ' => 'tester ' ,
383
+ 'cc_type ' => 'test ' ,
384
+ 'cc_exp_year ' => '2014 ' ,
385
+ 'cc_exp_month ' => '1 ' ,
386
+ ],
387
+ ];
388
+
389
+ $ this ->assertNotNull ($ this ->_webApiCall ($ serviceInfo , $ requestData ));
390
+ }
391
+
392
+ /**
393
+ * Get customer ID token
394
+ *
395
+ * @return string
396
+ */
397
+ protected function getCustomerToken ()
398
+ {
399
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
400
+ $ customerTokenService = $ this ->objectManager ->create (
401
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
402
+ );
403
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
404
+ return $ token ;
405
+ }
287
406
}
0 commit comments