Skip to content

Commit 4c55797

Browse files
ENGCOM-5369: Remove PaymentMethodAdditionalDataInput From Schema #757
- Merge Pull Request magento/graphql-ce#757 from pmclain/graphql-ce:issue/751 - Merged commits: 1. 7f9ccaa 2. 0d0aca1 3. d4a859d 4. 887f33b 5. c221853 6. bad6669
2 parents fb58417 + bad6669 commit 4c55797

File tree

14 files changed

+672
-17
lines changed

14 files changed

+672
-17
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/PaypalGraphQl/Model/Plugin/Resolver/SetPaymentMethodOnCart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SetPaymentMethodOnCart
2525
{
2626
private const PATH_CODE = 'input/payment_method/code';
2727

28-
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data';
28+
private const PATH_PAYMENT_METHOD_DATA = 'input/payment_method';
2929

3030
private $allowedPaymentMethodCodes = [];
3131

@@ -98,7 +98,7 @@ public function afterResolve(
9898
return $resolvedValue;
9999
}
100100

101-
$paypalAdditionalData = $this->arrayManager->get(self::PATH_ADDITIONAL_DATA, $args) ?? [];
101+
$paypalAdditionalData = $this->arrayManager->get(self::PATH_PAYMENT_METHOD_DATA, $args) ?? [];
102102
$payerId = $paypalAdditionalData[$paymentCode]['payer_id'] ?? null;
103103
$token = $paypalAdditionalData[$paymentCode]['token'] ?? null;
104104
$cart = $resolvedValue['cart']['model'];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type PayflowLinkToken {
3131
paypal_url: String @doc(description:"PayPal URL used for requesting Payflow form")
3232
}
3333

34-
input PaymentMethodAdditionalDataInput {
34+
input PaymentMethodInput {
3535
paypal_express: PaypalExpressInput @doc(description:"Required input for PayPal Express Checkout payments")
3636
payflow_express: PayflowExpressInput @doc(description:"Required input for PayPal Payflow Express Checkout payments")
3737
payflow_link: PayflowLinkAdditionalDataInput @doc(description:"Required input for PayPal Payflow Link payments")

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: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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\TestModuleAuthorizenetAcceptjs\Gateway\Http;
9+
10+
use Magento\Framework\Math\Random;
11+
use Magento\Framework\Stdlib\ArrayManager;
12+
use Magento\Payment\Gateway\Http\ClientInterface;
13+
use Magento\Payment\Gateway\Http\TransferInterface;
14+
15+
/**
16+
* A client for mocking communicate with the Authorize.net API
17+
*/
18+
class MockClient implements ClientInterface
19+
{
20+
/**
21+
* @var Random
22+
*/
23+
private $random;
24+
25+
/**
26+
* @var ArrayManager
27+
*/
28+
private $arrayManager;
29+
30+
/**
31+
* @param Random $random
32+
* @param ArrayManager $arrayManager
33+
*/
34+
public function __construct(
35+
Random $random,
36+
ArrayManager $arrayManager
37+
) {
38+
$this->random = $random;
39+
$this->arrayManager = $arrayManager;
40+
}
41+
42+
/**
43+
* Places request to gateway. Returns result as ENV array
44+
*
45+
* @param TransferInterface $transferObject
46+
* @return array
47+
*/
48+
public function placeRequest(TransferInterface $transferObject): array
49+
{
50+
$request = $transferObject->getBody();
51+
$nonce = $this->arrayManager->get('transactionRequest/payment/opaqueData/dataValue', $request);
52+
$descriptor = $this->arrayManager->get('transactionRequest/payment/opaqueData/dataDescriptor', $request);
53+
54+
$approve = true;
55+
if ($nonce !== 'fake-nonce' || $descriptor !== 'COMMON.ACCEPT.INAPP.PAYMENT') {
56+
$approve = false;
57+
}
58+
59+
return $this->createResponse($approve);
60+
}
61+
62+
/**
63+
* Create mock response body
64+
*
65+
* @param bool $approve
66+
* @return array
67+
* @throws \Magento\Framework\Exception\LocalizedException
68+
*/
69+
private function createResponse(bool $approve): array
70+
{
71+
return [
72+
'transactionResponse' => [
73+
'responseCode' => $approve ? '1' : '2',
74+
'authCode' => strtoupper($this->random->getRandomString(6)),
75+
'avsResultCode' => 'Y',
76+
'cvvResultCode' => 'P',
77+
'cavvResultCode' => '2',
78+
'transId' => random_int(10000000000, 99999999999),
79+
'refTransId' => '',
80+
'transHash' => '',
81+
'testRequest' => '0',
82+
'accountNumber' => 'XXXX1111',
83+
'accountType' => 'Visa',
84+
'messages' => $approve ? $this->getApprovalMessage() : $this->getDeclineMessage(),
85+
'userFields' => [
86+
[
87+
'name' => 'transactionType',
88+
'value' => 'authOnlyTransaction',
89+
],
90+
],
91+
'transHashSha2' => 'fake-hash',
92+
'SupplementalDataQualificationIndicator' => '0',
93+
],
94+
'messages' => [
95+
'resultCode' => 'Ok',
96+
'message' => [
97+
[
98+
'code' => 'I00001',
99+
'text' => 'Successful.',
100+
],
101+
],
102+
],
103+
];
104+
}
105+
106+
/**
107+
* Provide approval message for response
108+
*
109+
* @return array
110+
*/
111+
private function getApprovalMessage(): array
112+
{
113+
return [
114+
[
115+
'code' => '1',
116+
'description' => 'This transaction has been approved.',
117+
],
118+
];
119+
}
120+
121+
/**
122+
* Provide decline message for response
123+
*
124+
* @return array
125+
*/
126+
private function getDeclineMessage(): array
127+
{
128+
return [
129+
[
130+
'code' => '2',
131+
'description' => 'This transaction has been declined.',
132+
],
133+
];
134+
}
135+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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\TestModuleAuthorizenetAcceptjs\Gateway\Validator;
9+
10+
use Magento\Payment\Gateway\Validator\AbstractValidator;
11+
use Magento\Payment\Gateway\Validator\ResultInterface;
12+
13+
/**
14+
* Force validation of the transaction hash
15+
*/
16+
class TransactionHashValidator extends AbstractValidator
17+
{
18+
/**
19+
* Skip validation of transaction hash in mock response
20+
*
21+
* @param array $validationSubject
22+
* @return ResultInterface
23+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
24+
*/
25+
public function validate(array $validationSubject): ResultInterface
26+
{
27+
return $this->createResult(true);
28+
}
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<preference for="Magento\AuthorizenetAcceptjs\Gateway\Http\Client" type="Magento\TestModuleAuthorizenetAcceptjs\Gateway\Http\MockClient" />
10+
<preference for="Magento\AuthorizenetAcceptjs\Gateway\Validator\TransactionHashValidator" type="Magento\TestModuleAuthorizenetAcceptjs\Gateway\Validator\TransactionHashValidator" />
11+
</config>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_TestModuleAuthorizenetAcceptjs" />
10+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
$registrar = new ComponentRegistrar();
10+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleAuthorizenetAcceptjs') === null) {
11+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleAuthorizenetAcceptjs', __DIR__);
12+
}

0 commit comments

Comments
 (0)