Skip to content

Commit 5771b3e

Browse files
merge magento/2.3-develop into magento-mpi/MAGETWO-99606
2 parents 71fb8e3 + 61f4037 commit 5771b3e

19 files changed

+519
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\AuthorizenetGraphQl\Model;
9+
10+
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
11+
use Magento\Framework\Stdlib\ArrayManager;
12+
use Magento\Framework\GraphQL\DataObjectConverter;
13+
14+
/**
15+
* DataProvider Model for Authorizenet
16+
*/
17+
class AuthorizenetDataProvider implements AdditionalDataProviderInterface
18+
{
19+
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/authorizenet_acceptjs';
20+
21+
/**
22+
* @var ArrayManager
23+
*/
24+
private $arrayManager;
25+
26+
/**
27+
* AuthorizenetDataProvider constructor.
28+
* @param ArrayManager $arrayManager
29+
*/
30+
public function __construct(
31+
ArrayManager $arrayManager
32+
) {
33+
$this->arrayManager = $arrayManager;
34+
}
35+
36+
/**
37+
* Return additional data
38+
*
39+
* @param array $args
40+
* @return array
41+
*/
42+
public function getData(array $args): array
43+
{
44+
$additionalData = $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];
45+
foreach ($additionalData as $key => $value) {
46+
$additionalData[$this->snakeCaseToCamelCase($key)] = $value;
47+
unset($additionalData[$key]);
48+
}
49+
return $additionalData;
50+
}
51+
52+
/**
53+
* Converts an input string from snake_case to camelCase.
54+
*
55+
* @param string $input
56+
* @return string
57+
*/
58+
private function snakeCaseToCamelCase($input)
59+
{
60+
return lcfirst(str_replace('_', '', ucwords($input, '_')));
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AuthorizenetGraphQl
2+
3+
**AuthorizenetGraphQl** defines the data types needed to pass payment information data from the client to Magento.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "magento/module-authorizenet-graph-ql",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.1.3||~7.2.0",
7+
"magento/framework": "*",
8+
"magento/module-quote-graph-ql": "*"
9+
},
10+
"suggest": {
11+
"magento/module-graph-ql": "*"
12+
},
13+
"license": [
14+
"OSL-3.0",
15+
"AFL-3.0"
16+
],
17+
"autoload": {
18+
"files": [
19+
"registration.php"
20+
],
21+
"psr-4": {
22+
"Magento\\AuthorizenetGraphQl\\": ""
23+
}
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<type name="Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool">
10+
<arguments>
11+
<argument name="dataProviders" xsi:type="array">
12+
<item name="authorizenet_acceptjs" xsi:type="object">Magento\AuthorizenetGraphQl\Model\AuthorizenetDataProvider</item>
13+
</argument>
14+
</arguments>
15+
</type>
16+
</config>
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_AuthorizenetGraphQl"/>
10+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
input PaymentMethodAdditionalDataInput {
5+
authorizenet_acceptjs: AuthorizenetInput @doc(description: "Defines the required attributes for Authorize.Net payments")
6+
}
7+
8+
input AuthorizenetInput {
9+
opaque_data_descriptor: String! @doc(description: "Authorize.Net's description of the transaction request")
10+
opaque_data_value: String! @doc(description: "The nonce returned by Authorize.Net")
11+
cc_last_4: Int! @doc(description: "The last four digits of the credit or debit card")
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
use Magento\Framework\Component\ComponentRegistrar;
9+
10+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_AuthorizenetGraphQl', __DIR__);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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\QuoteGraphQl\Model\Cart\Payment;
9+
10+
/**
11+
* Interface for payment method additional data provider
12+
*/
13+
interface AdditionalDataProviderInterface
14+
{
15+
/**
16+
* Return Additional Data
17+
*
18+
* @param array $args
19+
* @return array
20+
*/
21+
public function getData(array $args): array;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\QuoteGraphQl\Model\Cart\Payment;
9+
10+
/**
11+
* Pool model for AdditionalDataProvider
12+
**/
13+
class AdditionalDataProviderPool
14+
{
15+
/**
16+
* @var AdditionalDataProviderInterface[]
17+
*/
18+
private $dataProviders;
19+
20+
/**
21+
* @param array $dataProviders
22+
*/
23+
public function __construct(array $dataProviders = [])
24+
{
25+
$this->dataProviders = $dataProviders;
26+
}
27+
28+
/**
29+
* Return additional data for the payment method
30+
*
31+
* @param string $methodCode
32+
* @param array $args
33+
* @return array
34+
*/
35+
public function getData(string $methodCode, array $args): array
36+
{
37+
$additionalData = [];
38+
if (isset($this->dataProviders[$methodCode])) {
39+
$additionalData = $this->dataProviders[$methodCode]->getData($args);
40+
}
41+
42+
return $additionalData;
43+
}
44+
}

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

+17-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
1919
use Magento\Quote\Api\Data\PaymentInterfaceFactory;
2020
use Magento\Quote\Api\PaymentMethodManagementInterface;
21+
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool;
22+
use Magento\Framework\App\ObjectManager;
2123

2224
/**
2325
* Mutation resolver for setting payment method for shopping cart
@@ -39,19 +41,28 @@ class SetPaymentMethodOnCart implements ResolverInterface
3941
*/
4042
private $paymentFactory;
4143

44+
/**
45+
* @var AdditionalDataProviderPool
46+
*/
47+
private $additionalDataProviderPool;
48+
4249
/**
4350
* @param GetCartForUser $getCartForUser
4451
* @param PaymentMethodManagementInterface $paymentMethodManagement
4552
* @param PaymentInterfaceFactory $paymentFactory
53+
* @param AdditionalDataProviderPool $additionalDataProviderPool
4654
*/
4755
public function __construct(
4856
GetCartForUser $getCartForUser,
4957
PaymentMethodManagementInterface $paymentMethodManagement,
50-
PaymentInterfaceFactory $paymentFactory
58+
PaymentInterfaceFactory $paymentFactory,
59+
AdditionalDataProviderPool $additionalDataProviderPool = null
5160
) {
5261
$this->getCartForUser = $getCartForUser;
5362
$this->paymentMethodManagement = $paymentMethodManagement;
5463
$this->paymentFactory = $paymentFactory;
64+
$this->additionalDataProviderPool = $additionalDataProviderPool
65+
?: ObjectManager::getInstance()->get(AdditionalDataProviderPool::class);
5566
}
5667

5768
/**
@@ -70,16 +81,17 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7081
$paymentMethodCode = $args['input']['payment_method']['code'];
7182

7283
$poNumber = $args['input']['payment_method']['purchase_order_number'] ?? null;
73-
$additionalData = $args['input']['payment_method']['additional_data'] ?? [];
84+
$additionalData = $this->additionalDataProviderPool->getData($paymentMethodCode, $args) ?? [];
7485

7586
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId());
76-
$payment = $this->paymentFactory->create([
87+
$payment = $this->paymentFactory->create(
88+
[
7789
'data' => [
7890
PaymentInterface::KEY_METHOD => $paymentMethodCode,
7991
PaymentInterface::KEY_PO_NUMBER => $poNumber,
8092
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
81-
]
82-
]);
93+
]]
94+
);
8395

8496
try {
8597
$this->paymentMethodManagement->set($cart->getId(), $payment);

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

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ input SetPaymentMethodOnCartInput {
131131
input PaymentMethodInput {
132132
code: String! @doc(description:"Payment method code")
133133
purchase_order_number: String @doc(description:"Purchase order number")
134+
additional_data: PaymentMethodAdditionalDataInput @doc(description: "Additional payment data")
135+
}
136+
137+
input PaymentMethodAdditionalDataInput {
134138
}
135139

136140
input SetGuestEmailOnCartInput {

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"magento/module-authorization": "*",
107107
"magento/module-authorizenet": "*",
108108
"magento/module-authorizenet-acceptjs": "*",
109+
"magento/module-authorizenet-graph-ql": "*",
109110
"magento/module-advanced-search": "*",
110111
"magento/module-backend": "*",
111112
"magento/module-backup": "*",

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ public function post(string $query, array $variables = [], string $operationName
6161
'operationName' => !empty($operationName) ? $operationName : null
6262
];
6363
$postData = $this->json->jsonEncode($requestArray);
64+
try {
65+
$responseBody = $this->curlClient->post($url, $postData, $headers);
66+
} catch (\Exception $e) {
67+
// if response code > 400 then response is the exception message
68+
$responseBody = $e->getMessage();
69+
}
6470

65-
$responseBody = $this->curlClient->post($url, $postData, $headers);
6671
return $this->processResponse($responseBody);
6772
}
6873

0 commit comments

Comments
 (0)