Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 1ea089f

Browse files
committed
Remove empty PaymentMethodAdditionalDataInput from schema
This removes the empty input `PaymentMethodAdditionalDataInput` and provides an update to the backend implementation responislbe for resolving online payment method details. Fixes #751
1 parent 7f9ccaa commit 1ea089f

File tree

7 files changed

+460
-14
lines changed

7 files changed

+460
-14
lines changed

app/code/Magento/AuthorizenetGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright © Magento, Inc. All rights reserved.
22
# See COPYING.txt for license details.
33

4-
input PaymentMethodAdditionalDataInput {
4+
input PaymentMethodInput {
55
authorizenet_acceptjs: AuthorizenetInput @doc(description: "Defines the required attributes for Authorize.Net payments")
66
}
77

app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,15 @@ public function execute(Quote $cart, array $paymentData): void
6868
$paymentMethodCode = $paymentData['code'];
6969

7070
$poNumber = $paymentData['purchase_order_number'] ?? null;
71-
$additionalData = isset($paymentData['additional_data'])
72-
? $this->additionalDataProviderPool->getData($paymentMethodCode, $paymentData['additional_data'])
73-
: [];
71+
$additionalData = $this->additionalDataProviderPool->getData($paymentMethodCode, $paymentData);
7472

7573
$payment = $this->paymentFactory->create(
7674
[
77-
'data' =>
78-
[
79-
PaymentInterface::KEY_METHOD => $paymentMethodCode,
80-
PaymentInterface::KEY_PO_NUMBER => $poNumber,
81-
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
82-
],
75+
'data' => [
76+
PaymentInterface::KEY_METHOD => $paymentMethodCode,
77+
PaymentInterface::KEY_PO_NUMBER => $poNumber,
78+
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
79+
],
8380
]
8481
);
8582

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ input SetPaymentMethodOnCartInput {
138138
input PaymentMethodInput {
139139
code: String! @doc(description:"Payment method code")
140140
purchase_order_number: String @doc(description:"Purchase order number")
141-
additional_data: PaymentMethodAdditionalDataInput @doc(description: "Additional payment data")
142-
}
143-
144-
input PaymentMethodAdditionalDataInput {
145141
}
146142

147143
input SetGuestEmailOnCartInput {
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\AuthorizenetAcceptjs\Customer;
9+
10+
use Magento\Framework\Registry;
11+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
12+
use Magento\Integration\Api\CustomerTokenServiceInterface;
13+
use Magento\Sales\Api\OrderRepositoryInterface;
14+
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\TestFramework\TestCase\GraphQlAbstract;
17+
18+
/**
19+
* Test setting payment method and placing order with AuthorizenetAcceptjs
20+
*/
21+
class SetPaymentMethodTest extends GraphQlAbstract
22+
{
23+
private const VALID_DESCRIPTOR = 'COMMON.ACCEPT.INAPP.PAYMENT';
24+
private const VALID_NONCE = 'fake-nonce';
25+
26+
/**
27+
* @var CustomerTokenServiceInterface
28+
*/
29+
private $customerTokenService;
30+
31+
/**
32+
* @var GetMaskedQuoteIdByReservedOrderId
33+
*/
34+
private $getMaskedQuoteIdByReservedOrderId;
35+
36+
/**
37+
* @var CollectionFactory
38+
*/
39+
private $orderCollectionFactory;
40+
41+
/**
42+
* @var OrderRepositoryInterface
43+
*/
44+
private $orderRepository;
45+
46+
/**
47+
* @var Registry
48+
*/
49+
private $registry;
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
protected function setUp()
55+
{
56+
$objectManager = Bootstrap::getObjectManager();
57+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
58+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
59+
$this->orderCollectionFactory = $objectManager->get(CollectionFactory::class);
60+
$this->orderRepository = $objectManager->get(OrderRepositoryInterface::class);
61+
$this->registry = Bootstrap::getObjectManager()->get(Registry::class);
62+
}
63+
64+
/**
65+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
66+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
67+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php
68+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
69+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
70+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
71+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
72+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
73+
* @magentoApiDataFixture Magento/Graphql/AuthorizenetAcceptjs/_files/enable_authorizenetacceptjs.php
74+
* @param string $nonce
75+
* @param string $descriptor
76+
* @param bool $expectSuccess
77+
* @dataProvider dataProviderTestPlaceOrder
78+
*/
79+
public function testPlaceOrder(string $nonce, string $descriptor, bool $expectSuccess)
80+
{
81+
$reservedOrderId = 'test_quote';
82+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
83+
84+
$setPaymentMutation = $this->getSetPaymentMutation($maskedQuoteId, $descriptor, $nonce);
85+
$setPaymentResponse = $this->graphQlMutation($setPaymentMutation, [], '', $this->getHeaderMap());
86+
87+
$this->assertSetPaymentMethodResponse($setPaymentResponse, 'authorizenet_acceptjs');
88+
89+
$placeOrderQuery = $this->getPlaceOrderMutation($maskedQuoteId);
90+
91+
if (!$expectSuccess) {
92+
$this->expectException(\Exception::class);
93+
$this->expectExceptionMessage('Transaction has been declined. Please try again later.');
94+
}
95+
96+
$placeOrderResponse = $this->graphQlMutation($placeOrderQuery, [], '', $this->getHeaderMap());
97+
98+
$this->assertPlaceOrderResponse($placeOrderResponse, $reservedOrderId);
99+
}
100+
101+
public function dataProviderTestPlaceOrder(): array
102+
{
103+
return [
104+
[static::VALID_NONCE, static::VALID_DESCRIPTOR, true],
105+
['nonce', static::VALID_DESCRIPTOR, false],
106+
[static::VALID_NONCE, 'descriptor', false],
107+
];
108+
}
109+
110+
private function assertPlaceOrderResponse(array $response, string $reservedOrderId): void
111+
{
112+
self::assertArrayHasKey('placeOrder', $response);
113+
self::assertArrayHasKey('order', $response['placeOrder']);
114+
self::assertArrayHasKey('order_id', $response['placeOrder']['order']);
115+
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_id']);
116+
}
117+
118+
private function assertSetPaymentMethodResponse(array $response, string $methodCode): void
119+
{
120+
self::assertArrayHasKey('setPaymentMethodOnCart', $response);
121+
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']);
122+
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']);
123+
self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']);
124+
self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']);
125+
}
126+
127+
/**
128+
* Create setPaymentMethodOnCart mutation
129+
*
130+
* @param string $maskedQuoteId
131+
* @param string $descriptor
132+
* @param string $nonce
133+
* @return string
134+
*/
135+
private function getSetPaymentMutation(string $maskedQuoteId, string $descriptor, string $nonce): string
136+
{
137+
return <<<QUERY
138+
mutation {
139+
setPaymentMethodOnCart(input:{
140+
cart_id:"{$maskedQuoteId}"
141+
payment_method:{
142+
code:"authorizenet_acceptjs"
143+
authorizenet_acceptjs:{
144+
opaque_data_descriptor: "{$descriptor}"
145+
opaque_data_value: "{$nonce}"
146+
cc_last_4: 1111
147+
}
148+
}
149+
}) {
150+
cart {
151+
selected_payment_method {
152+
code
153+
}
154+
}
155+
}
156+
}
157+
QUERY;
158+
}
159+
160+
/**
161+
* Create placeOrder mutation
162+
*
163+
* @param string $maskedQuoteId
164+
* @return string
165+
*/
166+
private function getPlaceOrderMutation(string $maskedQuoteId): string
167+
{
168+
return <<<QUERY
169+
mutation {
170+
placeOrder(input: {cart_id: "{$maskedQuoteId}"}) {
171+
order {
172+
order_id
173+
}
174+
}
175+
}
176+
QUERY;
177+
}
178+
179+
/**
180+
* Get authorization headers for requests
181+
*
182+
* @param string $username
183+
* @param string $password
184+
* @return array
185+
* @throws \Magento\Framework\Exception\AuthenticationException
186+
*/
187+
private function getHeaderMap(string $username = '[email protected]', string $password = 'password'): array
188+
{
189+
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password);
190+
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
191+
return $headerMap;
192+
}
193+
194+
/**
195+
* @inheritdoc
196+
*/
197+
public function tearDown()
198+
{
199+
$this->registry->unregister('isSecureArea');
200+
$this->registry->register('isSecureArea', true);
201+
202+
$orderCollection = $this->orderCollectionFactory->create();
203+
foreach ($orderCollection as $order) {
204+
$this->orderRepository->delete($order);
205+
}
206+
$this->registry->unregister('isSecureArea');
207+
$this->registry->register('isSecureArea', false);
208+
209+
parent::tearDown();
210+
}
211+
}

0 commit comments

Comments
 (0)