Skip to content

Commit 93b08f6

Browse files
committed
Prototype BraintreeGraphQl Payments
1 parent f4f62ea commit 93b08f6

File tree

11 files changed

+208
-2
lines changed

11 files changed

+208
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\BraintreeGraphQl\Model;
9+
10+
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
11+
use Magento\Framework\Stdlib\ArrayManager;
12+
13+
class BraintreeDataProvider implements AdditionalDataProviderInterface
14+
{
15+
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree';
16+
17+
/**
18+
* @var ArrayManager
19+
*/
20+
private $arrayManager;
21+
22+
public function __construct(
23+
ArrayManager $arrayManager
24+
) {
25+
$this->arrayManager = $arrayManager;
26+
}
27+
28+
public function getData(array $args): array
29+
{
30+
return $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\BraintreeGraphQl\Model;
9+
10+
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
11+
use Magento\Framework\Stdlib\ArrayManager;
12+
13+
class BraintreeVaultDataProvider implements AdditionalDataProviderInterface
14+
{
15+
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree_vault';
16+
17+
/**
18+
* @var ArrayManager
19+
*/
20+
private $arrayManager;
21+
22+
public function __construct(
23+
ArrayManager $arrayManager
24+
) {
25+
$this->arrayManager = $arrayManager;
26+
}
27+
28+
public function getData(array $args): array
29+
{
30+
return $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];
31+
}
32+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# BraintreeGraphQl
2+
3+
**BraintreeGraphQl** provides type and resolver for method additional
4+
information.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "magento/module-braintree-graph-ql",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.1.3||~7.2.0",
7+
"magento/framework": "*"
8+
},
9+
"suggest": {
10+
"magento/module-graph-ql": "*"
11+
},
12+
"license": [
13+
"OSL-3.0",
14+
"AFL-3.0"
15+
],
16+
"autoload": {
17+
"files": [
18+
"registration.php"
19+
],
20+
"psr-4": {
21+
"Magento\\BraintreeGraphQl\\": ""
22+
}
23+
}
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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="braintree" xsi:type="object">Magento\BraintreeGraphQl\Model\BraintreeDataProvider</item>
13+
<item name="braintree_vault" xsi:type="object">Magento\BraintreeGraphQl\Model\BraintreeVaultDataProvider</item>
14+
</argument>
15+
</arguments>
16+
</type>
17+
</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_BraintreeGraphQl"/>
10+
</config>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
input PaymentMethodAdditionalDataInput {
5+
braintree: BraintreeInput
6+
braintree_vault: BraintreeVaultInput
7+
}
8+
9+
input BraintreeInput {
10+
payment_method_nonce: String!
11+
is_active_payment_token_enabler: Boolean!
12+
}
13+
14+
input BraintreeVaultInput {
15+
payment_method_nonce: String!
16+
public_hash: String!
17+
is_active_payment_token_enabler: Boolean!
18+
}
Lines changed: 10 additions & 0 deletions
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_BraintreeGraphQl', __DIR__);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
public function getData(array $args): array;
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
class AdditionalDataProviderPool
11+
{
12+
/**
13+
* @var AdditionalDataProviderInterface[]
14+
*/
15+
private $dataProviders;
16+
17+
public function __construct(array $dataProviders = [])
18+
{
19+
$this->dataProviders = $dataProviders;
20+
}
21+
22+
public function getData(string $methodCode, array $args): array
23+
{
24+
$additionalData = [];
25+
if (isset($this->dataProviders[$methodCode])) {
26+
$additionalData = $this->dataProviders[$methodCode]->getData($args);
27+
}
28+
29+
return $additionalData;
30+
}
31+
}

0 commit comments

Comments
 (0)