123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Quote\Api;
- class PaymentMethodManagementTest extends \Magento\TestFramework\TestCase\WebapiAbstract
- {
- const SERVICE_VERSION = 'V1';
- const SERVICE_NAME = 'quotePaymentMethodManagementV1';
- const RESOURCE_PATH = '/V1/carts/';
- /**
- * @var \Magento\TestFramework\ObjectManager
- */
- protected $objectManager;
- protected function setUp()
- {
- $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php
- */
- public function testReSetPayment()
- {
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_1_with_payment', 'reserved_order_id');
- $cartId = $quote->getId();
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
- ],
- 'soap' => [
- 'service' => self::SERVICE_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_NAME . 'set',
- ],
- ];
- $requestData = [
- "cartId" => $cartId,
- "method" => [
- 'method' => 'checkmo',
- 'po_number' => null
- ],
- ];
- $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData));
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
- */
- public function testSetPaymentWithVirtualProduct()
- {
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_with_virtual_product', 'reserved_order_id');
- $cartId = $quote->getId();
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
- ],
- 'soap' => [
- 'service' => self::SERVICE_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_NAME . 'set',
- ],
- ];
- $requestData = [
- "cartId" => $cartId,
- "method" => [
- 'method' => 'checkmo',
- 'po_number' => '200'
- ],
- ];
- $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData));
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
- */
- public function testSetPaymentWithSimpleProduct()
- {
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_1', 'reserved_order_id');
- $cartId = $quote->getId();
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
- ],
- 'soap' => [
- 'service' => self::SERVICE_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_NAME . 'set',
- ],
- ];
- $requestData = [
- "cartId" => $cartId,
- "method" => [
- 'method' => 'checkmo',
- 'po_number' => '200'
- ],
- ];
- $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData));
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
- * @expectedException \Exception
- * @expectedExceptionMessage The shipping address is missing. Set the address and try again.
- */
- public function testSetPaymentWithSimpleProductWithoutAddress()
- {
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_with_simple_product_without_address', 'reserved_order_id');
- $cartId = $quote->getId();
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
- ],
- 'soap' => [
- 'service' => self::SERVICE_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_NAME . 'set',
- ],
- ];
- $requestData = [
- "cartId" => $cartId,
- "method" => [
- 'method' => 'checkmo',
- 'po_number' => '200'
- ],
- ];
- $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData));
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
- */
- public function testGetList()
- {
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_1', 'reserved_order_id');
- $cartId = $quote->getId();
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . $cartId . '/payment-methods',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
- ],
- 'soap' => [
- 'service' => self::SERVICE_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_NAME . 'getList',
- ],
- ];
- $requestData = ["cartId" => $cartId];
- $requestResponse = $this->_webApiCall($serviceInfo, $requestData);
- $expectedResponse = [
- 'code' => 'checkmo',
- 'title' => 'Check / Money order',
- ];
- $this->assertGreaterThan(0, count($requestResponse));
- $this->assertContains($expectedResponse, $requestResponse);
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php
- */
- public function testGet()
- {
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_1_with_payment', 'reserved_order_id');
- $cartId = $quote->getId();
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
- ],
- 'soap' => [
- 'service' => self::SERVICE_NAME,
- 'serviceVersion' => self::SERVICE_VERSION,
- 'operation' => self::SERVICE_NAME . 'get',
- ],
- ];
- $requestData = ["cartId" => $cartId];
- $requestResponse = $this->_webApiCall($serviceInfo, $requestData);
- foreach ($this->getPaymentMethodFieldsForAssert() as $field) {
- $this->assertArrayHasKey($field, $requestResponse);
- $this->assertNotNull($requestResponse[$field]);
- }
- $this->assertEquals('checkmo', $requestResponse['method']);
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
- */
- public function testGetListMine()
- {
- $this->_markTestAsRestOnly();
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_1', 'reserved_order_id');
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . 'mine/payment-methods',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
- 'token' => $this->getCustomerToken()
- ]
- ];
- $requestResponse = $this->_webApiCall($serviceInfo);
- $expectedResponse = [
- 'code' => 'checkmo',
- 'title' => 'Check / Money order',
- ];
- $this->assertGreaterThan(0, count($requestResponse));
- $this->assertContains($expectedResponse, $requestResponse);
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php
- */
- public function testGetMine()
- {
- $this->_markTestAsRestOnly();
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_1_with_payment', 'reserved_order_id');
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-method',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
- 'token' => $this->getCustomerToken()
- ]
- ];
- $requestResponse = $this->_webApiCall($serviceInfo);
- foreach ($this->getPaymentMethodFieldsForAssert() as $field) {
- $this->assertArrayHasKey($field, $requestResponse);
- $this->assertNotNull($requestResponse[$field]);
- }
- $this->assertEquals('checkmo', $requestResponse['method']);
- }
- /**
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
- */
- public function testSetPaymentWithSimpleProductMine()
- {
- $this->_markTestAsRestOnly();
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
- $quote->load('test_order_1', 'reserved_order_id');
- $serviceInfo = [
- 'rest' => [
- 'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-method',
- 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
- 'token' => $this->getCustomerToken()
- ]
- ];
- $requestData = [
- "method" => [
- 'method' => 'checkmo',
- 'po_number' => '200'
- ],
- ];
- $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData));
- }
- /**
- * @return array
- */
- protected function getPaymentMethodFieldsForAssert()
- {
- return ['method', 'po_number', 'additional_data'];
- }
- /**
- * Get customer ID token
- *
- * @return string
- */
- protected function getCustomerToken()
- {
- /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
- $customerTokenService = $this->objectManager->create(
- \Magento\Integration\Api\CustomerTokenServiceInterface::class
- );
- $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
- return $token;
- }
- }
|