forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request magento#3751 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
- Loading branch information
Showing
19 changed files
with
946 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/code/Magento/VaultGraphQl/Model/Resolver/DeletePaymentToken.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\VaultGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Vault\Api\PaymentTokenManagementInterface; | ||
use Magento\Vault\Api\PaymentTokenRepositoryInterface; | ||
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount; | ||
|
||
/** | ||
* Delete Payment Token resolver, used for GraphQL mutation processing. | ||
*/ | ||
class DeletePaymentToken implements ResolverInterface | ||
{ | ||
/** | ||
* @var CheckCustomerAccount | ||
*/ | ||
private $checkCustomerAccount; | ||
|
||
/** | ||
* @var PaymentTokenManagementInterface | ||
*/ | ||
private $paymentTokenManagement; | ||
|
||
/** | ||
* @var PaymentTokenRepositoryInterface | ||
*/ | ||
private $paymentTokenRepository; | ||
|
||
/** | ||
* @param CheckCustomerAccount $checkCustomerAccount | ||
* @param PaymentTokenManagementInterface $paymentTokenManagement | ||
* @param PaymentTokenRepositoryInterface $paymentTokenRepository | ||
*/ | ||
public function __construct( | ||
CheckCustomerAccount $checkCustomerAccount, | ||
PaymentTokenManagementInterface $paymentTokenManagement, | ||
PaymentTokenRepositoryInterface $paymentTokenRepository | ||
) { | ||
$this->checkCustomerAccount = $checkCustomerAccount; | ||
$this->paymentTokenManagement = $paymentTokenManagement; | ||
$this->paymentTokenRepository = $paymentTokenRepository; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!isset($args['public_hash'])) { | ||
throw new GraphQlInputException(__('Specify the "public_hash" value.')); | ||
} | ||
|
||
$currentUserId = $context->getUserId(); | ||
$currentUserType = $context->getUserType(); | ||
|
||
$this->checkCustomerAccount->execute($currentUserId, $currentUserType); | ||
|
||
$token = $this->paymentTokenManagement->getByPublicHash($args['public_hash'], $currentUserId); | ||
if (!$token) { | ||
throw new GraphQlNoSuchEntityException( | ||
__('Could not find a token using public hash: %1', $args['public_hash']) | ||
); | ||
} | ||
|
||
return ['result' => $this->paymentTokenRepository->delete($token)]; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
app/code/Magento/VaultGraphQl/Model/Resolver/PaymentTokens.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\VaultGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Vault\Model\PaymentTokenManagement; | ||
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount; | ||
|
||
/** | ||
* Customers Payment Tokens resolver, used for GraphQL request processing. | ||
*/ | ||
class PaymentTokens implements ResolverInterface | ||
{ | ||
/** | ||
* @var PaymentTokenManagement | ||
*/ | ||
private $paymentTokenManagement; | ||
|
||
/** | ||
* @var CheckCustomerAccount | ||
*/ | ||
private $checkCustomerAccount; | ||
|
||
/** | ||
* @param PaymentTokenManagement $paymentTokenManagement | ||
* @param CheckCustomerAccount $checkCustomerAccount | ||
*/ | ||
public function __construct( | ||
PaymentTokenManagement $paymentTokenManagement, | ||
CheckCustomerAccount $checkCustomerAccount | ||
) { | ||
$this->paymentTokenManagement = $paymentTokenManagement; | ||
$this->checkCustomerAccount = $checkCustomerAccount; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
$currentUserId = $context->getUserId(); | ||
$currentUserType = $context->getUserType(); | ||
|
||
$this->checkCustomerAccount->execute($currentUserId, $currentUserType); | ||
|
||
$tokens = $this->paymentTokenManagement->getVisibleAvailableTokens($currentUserId); | ||
$result = []; | ||
|
||
foreach ($tokens as $token) { | ||
$result[] = [ | ||
'public_hash' => $token->getPublicHash(), | ||
'payment_method_code' => $token->getPaymentMethodCode(), | ||
'type' => $token->getType(), | ||
'details' => $token->getTokenDetails(), | ||
]; | ||
} | ||
|
||
return ['items' => $result]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# VaultGraphQl | ||
|
||
**VaultGraphQl** provides type and resolver information for the GraphQl module | ||
to generate Vault (stored payment information) information endpoints. This module also | ||
provides mutations for modifying a payment token. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "magento/module-vault-graph-ql", | ||
"description": "N/A", | ||
"type": "magento2-module", | ||
"require": { | ||
"php": "~7.1.3||~7.2.0", | ||
"magento/framework": "*", | ||
"magento/module-vault": "*", | ||
"magento/module-customer-graph-ql": "*" | ||
}, | ||
"license": [ | ||
"OSL-3.0", | ||
"AFL-3.0" | ||
], | ||
"autoload": { | ||
"files": [ | ||
"registration.php" | ||
], | ||
"psr-4": { | ||
"Magento\\VaultGraphQl\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_VaultGraphQl"/> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright © Magento, Inc. All rights reserved. | ||
# See COPYING.txt for license details. | ||
|
||
type Mutation { | ||
deletePaymentToken(public_hash: String!): DeletePaymentTokenOutput @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\DeletePaymentToken") @doc(description:"Delete a customer payment token") | ||
} | ||
|
||
type DeletePaymentTokenOutput { | ||
result: Boolean! | ||
customerPaymentTokens: CustomerPaymentTokens @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens") | ||
} | ||
|
||
type Query { | ||
customerPaymentTokens: CustomerPaymentTokens @doc(description: "Return a list of customer payment tokens") @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens") | ||
} | ||
|
||
type CustomerPaymentTokens @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens") { | ||
items: [PaymentToken]! @doc(description: "An array of payment tokens") | ||
} | ||
|
||
type PaymentToken @doc(description: "The stored payment method available to the customer") { | ||
public_hash: String! @doc(description: "The public hash of the token") | ||
payment_method_code: String! @doc(description: "The payment method code associated with the token") | ||
type: PaymentTokenTypeEnum! | ||
details: String @doc(description: "Stored account details") | ||
} | ||
|
||
enum PaymentTokenTypeEnum @doc(description: "The list of available payment token types") { | ||
card | ||
account | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_VaultGraphQl', __DIR__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.