Skip to content

Commit d831265

Browse files
committed
MAGETWO-36272: Create /mine API for PaymentMethodManagement
- code style fix/ removed exessive whitespaces - renamed api url to more appropriate - refactored code to use foreach
1 parent 7f65d58 commit d831265

File tree

3 files changed

+50
-68
lines changed

3 files changed

+50
-68
lines changed

app/code/Magento/Quote/etc/webapi.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@
257257
</route>
258258

259259
<!-- Managing Cart Payment -->
260-
<route url="/V1/carts/:cartId/selected-payment-methods" method="GET">
260+
<route url="/V1/carts/:cartId/selected-payment-method" method="GET">
261261
<service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="get"/>
262262
<resources>
263263
<resource ref="Magento_Cart::manage" />
264264
</resources>
265265
</route>
266-
<route url="/V1/carts/:cartId/selected-payment-methods" method="PUT">
266+
<route url="/V1/carts/:cartId/selected-payment-method" method="PUT">
267267
<service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="set"/>
268268
<resources>
269269
<resource ref="Magento_Cart::manage" />
@@ -277,13 +277,13 @@
277277
</route>
278278

279279
<!-- Managing Guest Cart Payment -->
280-
<route url="/V1/guest-carts/:cartId/selected-payment-methods" method="GET">
280+
<route url="/V1/guest-carts/:cartId/selected-payment-method" method="GET">
281281
<service class="Magento\Quote\Api\GuestPaymentMethodManagementInterface" method="get"/>
282282
<resources>
283283
<resource ref="anonymous" />
284284
</resources>
285285
</route>
286-
<route url="/V1/guest-carts/:cartId/selected-payment-methods" method="PUT">
286+
<route url="/V1/guest-carts/:cartId/selected-payment-method" method="PUT">
287287
<service class="Magento\Quote\Api\GuestPaymentMethodManagementInterface" method="set"/>
288288
<resources>
289289
<resource ref="anonymous" />
@@ -297,7 +297,7 @@
297297
</route>
298298

299299
<!-- Managing my Cart Payment -->
300-
<route url="/V1/carts/mine/selected-payment-methods" method="GET">
300+
<route url="/V1/carts/mine/selected-payment-method" method="GET">
301301
<service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="get"/>
302302
<resources>
303303
<resource ref="self" />
@@ -306,7 +306,7 @@
306306
<parameter name="cartId" force="true">%cart_id%</parameter>
307307
</data>
308308
</route>
309-
<route url="/V1/carts/mine/selected-payment-methods" method="PUT">
309+
<route url="/V1/carts/mine/selected-payment-method" method="PUT">
310310
<service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="set"/>
311311
<resources>
312312
<resource ref="self" />

dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testReSetPayment()
6666

6767
$serviceInfo = [
6868
'rest' => [
69-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
69+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
7070
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
7171
],
7272
'soap' => [
@@ -103,7 +103,7 @@ public function testSetPaymentWithVirtualProduct()
103103

104104
$serviceInfo = [
105105
'rest' => [
106-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
106+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
107107
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
108108
],
109109
'soap' => [
@@ -139,7 +139,7 @@ public function testSetPaymentWithSimpleProduct()
139139

140140
$serviceInfo = [
141141
'rest' => [
142-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
142+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
143143
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
144144
],
145145
'soap' => [
@@ -178,7 +178,7 @@ public function testSetPaymentWithVirtualProductWithoutAddress()
178178

179179
$serviceInfo = [
180180
'rest' => [
181-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
181+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
182182
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
183183
],
184184
'soap' => [
@@ -216,7 +216,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress()
216216

217217
$serviceInfo = [
218218
'rest' => [
219-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
219+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
220220
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
221221
],
222222
'soap' => [
@@ -286,7 +286,7 @@ public function testGet()
286286

287287
$serviceInfo = [
288288
'rest' => [
289-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
289+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
290290
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
291291
],
292292
'soap' => [
@@ -299,25 +299,22 @@ public function testGet()
299299
$requestData = ["cartId" => $cartId];
300300
$requestResponse = $this->_webApiCall($serviceInfo, $requestData);
301301

302-
$this->assertArrayHasKey('method', $requestResponse);
303-
$this->assertArrayHasKey('po_number', $requestResponse);
304-
$this->assertArrayHasKey('cc_owner', $requestResponse);
305-
$this->assertArrayHasKey('cc_type', $requestResponse);
306-
$this->assertArrayHasKey('cc_exp_year', $requestResponse);
307-
$this->assertArrayHasKey('cc_exp_month', $requestResponse);
308-
$this->assertArrayHasKey('additional_data', $requestResponse);
309-
310-
$this->assertNotNull($requestResponse['method']);
311-
$this->assertNotNull($requestResponse['po_number']);
312-
$this->assertNotNull($requestResponse['cc_owner']);
313-
$this->assertNotNull($requestResponse['cc_type']);
314-
$this->assertNotNull($requestResponse['cc_exp_year']);
315-
$this->assertNotNull($requestResponse['cc_exp_month']);
316-
$this->assertNotNull($requestResponse['additional_data']);
302+
foreach ($this->getPaymentMethodFieldsForAssert() as $field) {
303+
$this->assertArrayHasKey($field, $requestResponse);
304+
$this->assertNotNull($requestResponse[$field]);
305+
}
317306

318307
$this->assertEquals('checkmo', $requestResponse['method']);
319308
}
320309

310+
/**
311+
* @return array
312+
*/
313+
protected function getPaymentMethodFieldsForAssert()
314+
{
315+
return ['method', 'po_number', 'cc_owner', 'cc_type', 'cc_exp_year', 'cc_exp_month', 'additional_data'];
316+
}
317+
321318
/**
322319
* Retrieve masked cart ID for guest cart.
323320
*

dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testReSetPayment()
3333

3434
$serviceInfo = [
3535
'rest' => [
36-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
36+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
3737
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
3838
],
3939
'soap' => [
@@ -70,7 +70,7 @@ public function testSetPaymentWithVirtualProduct()
7070

7171
$serviceInfo = [
7272
'rest' => [
73-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
73+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
7474
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
7575
],
7676
'soap' => [
@@ -106,7 +106,7 @@ public function testSetPaymentWithSimpleProduct()
106106

107107
$serviceInfo = [
108108
'rest' => [
109-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
109+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
110110
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
111111
],
112112
'soap' => [
@@ -145,7 +145,7 @@ public function testSetPaymentWithVirtualProductWithoutAddress()
145145

146146
$serviceInfo = [
147147
'rest' => [
148-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
148+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
149149
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
150150
],
151151
'soap' => [
@@ -183,7 +183,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress()
183183

184184
$serviceInfo = [
185185
'rest' => [
186-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
186+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
187187
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
188188
],
189189
'soap' => [
@@ -253,7 +253,7 @@ public function testGet()
253253

254254
$serviceInfo = [
255255
'rest' => [
256-
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods',
256+
'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
257257
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
258258
],
259259
'soap' => [
@@ -266,21 +266,10 @@ public function testGet()
266266
$requestData = ["cartId" => $cartId];
267267
$requestResponse = $this->_webApiCall($serviceInfo, $requestData);
268268

269-
$this->assertArrayHasKey('method', $requestResponse);
270-
$this->assertArrayHasKey('po_number', $requestResponse);
271-
$this->assertArrayHasKey('cc_owner', $requestResponse);
272-
$this->assertArrayHasKey('cc_type', $requestResponse);
273-
$this->assertArrayHasKey('cc_exp_year', $requestResponse);
274-
$this->assertArrayHasKey('cc_exp_month', $requestResponse);
275-
$this->assertArrayHasKey('additional_data', $requestResponse);
276-
277-
$this->assertNotNull($requestResponse['method']);
278-
$this->assertNotNull($requestResponse['po_number']);
279-
$this->assertNotNull($requestResponse['cc_owner']);
280-
$this->assertNotNull($requestResponse['cc_type']);
281-
$this->assertNotNull($requestResponse['cc_exp_year']);
282-
$this->assertNotNull($requestResponse['cc_exp_month']);
283-
$this->assertNotNull($requestResponse['additional_data']);
269+
foreach ($this->getPaymentMethodFieldsForAssert() as $field) {
270+
$this->assertArrayHasKey($field, $requestResponse);
271+
$this->assertNotNull($requestResponse[$field]);
272+
}
284273

285274
$this->assertEquals('checkmo', $requestResponse['method']);
286275
}
@@ -292,7 +281,7 @@ public function testGetListMine()
292281
{
293282
$this->_markTestAsRestOnly();
294283

295-
/** @var \Magento\Quote\Model\Quote $quote */
284+
/** @var \Magento\Quote\Model\Quote $quote */
296285
$quote = $this->objectManager->create('Magento\Quote\Model\Quote');
297286
$quote->load('test_order_1', 'reserved_order_id');
298287

@@ -329,30 +318,18 @@ public function testGetMine()
329318

330319
$serviceInfo = [
331320
'rest' => [
332-
'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-methods',
321+
'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-method',
333322
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
334323
'token' => $this->getCustomerToken()
335324
]
336325
];
337326

338327
$requestResponse = $this->_webApiCall($serviceInfo);
339328

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-
329+
foreach ($this->getPaymentMethodFieldsForAssert() as $field) {
330+
$this->assertArrayHasKey($field, $requestResponse);
331+
$this->assertNotNull($requestResponse[$field]);
332+
}
356333
$this->assertEquals('checkmo', $requestResponse['method']);
357334
}
358335

@@ -363,13 +340,13 @@ public function testSetPaymentWithSimpleProductMine()
363340
{
364341
$this->_markTestAsRestOnly();
365342

366-
/** @var \Magento\Quote\Model\Quote $quote */
343+
/** @var \Magento\Quote\Model\Quote $quote */
367344
$quote = $this->objectManager->create('\Magento\Quote\Model\Quote');
368345
$quote->load('test_order_1', 'reserved_order_id');
369346

370347
$serviceInfo = [
371348
'rest' => [
372-
'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-methods',
349+
'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-method',
373350
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
374351
'token' => $this->getCustomerToken()
375352
]
@@ -389,6 +366,14 @@ public function testSetPaymentWithSimpleProductMine()
389366
$this->assertNotNull($this->_webApiCall($serviceInfo, $requestData));
390367
}
391368

369+
/**
370+
* @return array
371+
*/
372+
protected function getPaymentMethodFieldsForAssert()
373+
{
374+
return ['method', 'po_number', 'cc_owner', 'cc_type', 'cc_exp_year', 'cc_exp_month', 'additional_data'];
375+
}
376+
392377
/**
393378
* Get customer ID token
394379
*

0 commit comments

Comments
 (0)