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

GraphQl-644: [Checkout] Support of "Braintree" payment method #392

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
93b08f6
Prototype BraintreeGraphQl Payments
pmclain Feb 23, 2019
7f226f6
Merge remote-tracking branch 'origin/2.3-develop' into feature/braint…
naydav Mar 6, 2019
c7fd250
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
pmclain May 17, 2019
a59a919
Braintree CC and Vault Support and Tests
pmclain May 21, 2019
411a559
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
pmclain Jun 15, 2019
a784526
Add braintree mock for testing
pmclain Jun 16, 2019
5f25fdd
fix static test failures
pmclain Jun 18, 2019
4527ea2
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
pmclain Jun 21, 2019
d57d076
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
pmclain Jun 28, 2019
05632a8
Move Method Specific input into PaymentMethodInput
pmclain Jun 28, 2019
3720ec0
Revert error reporting change committed by mistake
pmclain Jul 8, 2019
a6e32e8
Mutation for creating braintree client token
pmclain Jul 9, 2019
c4609cc
Generate nonce from public hash server-side
pmclain Jul 9, 2019
c1eee4f
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
pmclain Jul 14, 2019
4939d9c
Validate additional input is present for associated payment method
pmclain Jul 14, 2019
ba459a1
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
pmclain Jul 23, 2019
fe23996
Add validation for additonal data input
pmclain Jul 24, 2019
2448894
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
pmclain Jul 24, 2019
c552e35
Add parent-compatible typehint to constructor docblock
pmclain Jul 27, 2019
e49df5b
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
pmclain Jul 30, 2019
169ac1b
Get storeId from resolver context
pmclain Jul 30, 2019
f69b080
Add composer deps to module sequence
pmclain Jul 30, 2019
ec719be
Update php reqs in BraintreeGraphQl composer.json
pmclain Jul 30, 2019
d757fb5
Update tests to use @magentoConfigFixture
pmclain Jul 30, 2019
1132a47
Replace static with self
pmclain Jul 31, 2019
6fc0322
Merge remote-tracking branch 'origin/2.3-develop' into feature/braint…
naydav Aug 4, 2019
00002f4
magento/graphql-ce#644: [Checkout] Support of "Braintree" payment method
naydav Aug 4, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/code/Magento/BraintreeGraphQl/Model/BraintreeDataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\BraintreeGraphQl\Model;

use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
use Magento\Framework\Stdlib\ArrayManager;

class BraintreeDataProvider implements AdditionalDataProviderInterface
{
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree';

/**
* @var ArrayManager
*/
private $arrayManager;

public function __construct(
ArrayManager $arrayManager
) {
$this->arrayManager = $arrayManager;
}

public function getData(array $args): array
{
return $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\BraintreeGraphQl\Model;

use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
use Magento\Framework\Stdlib\ArrayManager;

class BraintreeVaultDataProvider implements AdditionalDataProviderInterface
{
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree_vault';

/**
* @var ArrayManager
*/
private $arrayManager;

public function __construct(
ArrayManager $arrayManager
) {
$this->arrayManager = $arrayManager;
}

public function getData(array $args): array
{
return $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/BraintreeGraphQl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# BraintreeGraphQl

**BraintreeGraphQl** provides type and resolver for method additional
information.
24 changes: 24 additions & 0 deletions app/code/Magento/BraintreeGraphQl/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "magento/module-braintree-graph-ql",
"description": "N/A",
"type": "magento2-module",
"require": {
"php": "~7.1.3||~7.2.0",
"magento/framework": "*"
},
"suggest": {
"magento/module-graph-ql": "*"
},
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\\BraintreeGraphQl\\": ""
}
}
}
17 changes: 17 additions & 0 deletions app/code/Magento/BraintreeGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool">
<arguments>
<argument name="dataProviders" xsi:type="array">
<item name="braintree" xsi:type="object">Magento\BraintreeGraphQl\Model\BraintreeDataProvider</item>
<item name="braintree_vault" xsi:type="object">Magento\BraintreeGraphQl\Model\BraintreeVaultDataProvider</item>
</argument>
</arguments>
</type>
</config>
10 changes: 10 additions & 0 deletions app/code/Magento/BraintreeGraphQl/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_BraintreeGraphQl"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add composer dependencies here in order to avoid installation sequence issues.

</config>
18 changes: 18 additions & 0 deletions app/code/Magento/BraintreeGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.

input PaymentMethodAdditionalDataInput {
braintree: BraintreeInput
braintree_vault: BraintreeVaultInput
}

input BraintreeInput {
lenaorobei marked this conversation as resolved.
Show resolved Hide resolved
payment_method_nonce: String!
is_active_payment_token_enabler: Boolean!
}

input BraintreeVaultInput {
payment_method_nonce: String!
public_hash: String!
is_active_payment_token_enabler: Boolean!
}
10 changes: 10 additions & 0 deletions app/code/Magento/BraintreeGraphQl/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_BraintreeGraphQl', __DIR__);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\QuoteGraphQl\Model\Cart\Payment;

/**
* Interface for payment method additional data provider
*/
interface AdditionalDataProviderInterface
{
public function getData(array $args): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\QuoteGraphQl\Model\Cart\Payment;

class AdditionalDataProviderPool
{
/**
* @var AdditionalDataProviderInterface[]
*/
private $dataProviders;

public function __construct(array $dataProviders = [])
{
$this->dataProviders = $dataProviders;
}

public function getData(string $methodCode, array $args): array
{
$additionalData = [];
if (isset($this->dataProviders[$methodCode])) {
$additionalData = $this->dataProviders[$methodCode]->getData($args);
}

return $additionalData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
use Magento\Quote\Api\Data\PaymentInterfaceFactory;
use Magento\Quote\Api\PaymentMethodManagementInterface;
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool;

/**
* Mutation resolver for setting payment method for shopping cart
Expand All @@ -39,19 +40,27 @@ class SetPaymentMethodOnCart implements ResolverInterface
*/
private $paymentFactory;

/**
* @var AdditionalDataProviderPool
*/
private $additionalDataProviderPool;

/**
* @param GetCartForUser $getCartForUser
* @param PaymentMethodManagementInterface $paymentMethodManagement
* @param PaymentInterfaceFactory $paymentFactory
* @param AdditionalDataProviderPool $additionalDataProviderPool
*/
public function __construct(
GetCartForUser $getCartForUser,
PaymentMethodManagementInterface $paymentMethodManagement,
PaymentInterfaceFactory $paymentFactory
PaymentInterfaceFactory $paymentFactory,
AdditionalDataProviderPool $additionalDataProviderPool
) {
$this->getCartForUser = $getCartForUser;
$this->paymentMethodManagement = $paymentMethodManagement;
$this->paymentFactory = $paymentFactory;
$this->additionalDataProviderPool = $additionalDataProviderPool;
}

/**
Expand Down Expand Up @@ -79,7 +88,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
'data' => [
PaymentInterface::KEY_METHOD => $paymentMethodCode,
PaymentInterface::KEY_PO_NUMBER => $poNumber,
PaymentInterface::KEY_ADDITIONAL_DATA => [],
PaymentInterface::KEY_ADDITIONAL_DATA => $this->additionalDataProviderPool->getData(
$paymentMethodCode,
$args
),
]
]);

Expand Down