Skip to content

Commit d1ce6a4

Browse files
authored
Merge pull request #3751 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
2 parents b35ded1 + 7023a5e commit d1ce6a4

File tree

19 files changed

+946
-1
lines changed

19 files changed

+946
-1
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromCart.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,36 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10+
use Magento\Framework\Exception\NoSuchEntityException;
1011
use Magento\Quote\Model\Quote;
1112
use Magento\Quote\Model\Quote\Item as QuoteItem;
13+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1214

1315
/**
1416
* Extract data from cart
1517
*/
1618
class ExtractDataFromCart
1719
{
20+
/**
21+
* @var QuoteIdToMaskedQuoteIdInterface
22+
*/
23+
private $quoteIdToMaskedQuoteId;
24+
25+
/**
26+
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
27+
*/
28+
public function __construct(
29+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
30+
) {
31+
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
32+
}
33+
1834
/**
1935
* Extract data from cart
2036
*
2137
* @param Quote $cart
2238
* @return array
39+
* @throws NoSuchEntityException
2340
*/
2441
public function execute(Quote $cart): array
2542
{
@@ -43,6 +60,7 @@ public function execute(Quote $cart): array
4360
$appliedCoupon = $cart->getCouponCode();
4461

4562
return [
63+
'cart_id' => $this->quoteIdToMaskedQuoteId->execute((int)$cart->getId()),
4664
'items' => $items,
4765
'applied_coupon' => $appliedCoupon ? ['code' => $appliedCoupon] : null
4866
];

app/code/Magento/QuoteGraphQl/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<arguments>
1212
<argument name="supportedTypes" xsi:type="array">
1313
<item name="simple" xsi:type="string">SimpleCartItem</item>
14+
<item name="virtual" xsi:type="string">VirtualCartItem</item>
1415
</argument>
1516
</arguments>
1617
</type>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Mutation {
1515
setBillingAddressOnCart(input: SetBillingAddressOnCartInput): SetBillingAddressOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetBillingAddressOnCart")
1616
setShippingMethodsOnCart(input: SetShippingMethodsOnCartInput): SetShippingMethodsOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetShippingMethodsOnCart")
1717
addSimpleProductsToCart(input: AddSimpleProductsToCartInput): AddSimpleProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
18+
addVirtualProductsToCart(input: AddVirtualProductsToCartInput): AddVirtualProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
1819
}
1920

2021
input SetShippingAddressesOnCartInput {
@@ -168,11 +169,21 @@ input AddSimpleProductsToCartInput {
168169
cartItems: [SimpleProductCartItemInput!]!
169170
}
170171

172+
input AddVirtualProductsToCartInput {
173+
cart_id: String!
174+
cartItems: [VirtualProductCartItemInput!]!
175+
}
176+
171177
input SimpleProductCartItemInput {
172178
data: CartItemInput!
173179
customizable_options:[CustomizableOptionInput!]
174180
}
175181

182+
input VirtualProductCartItemInput {
183+
data: CartItemInput!
184+
customizable_options:[CustomizableOptionInput!]
185+
}
186+
176187
input CustomizableOptionInput {
177188
id: Int!
178189
value: String!
@@ -182,10 +193,18 @@ type AddSimpleProductsToCartOutput {
182193
cart: Cart!
183194
}
184195

196+
type AddVirtualProductsToCartOutput {
197+
cart: Cart!
198+
}
199+
185200
type SimpleCartItem implements CartItemInterface @doc(description: "Simple Cart Item") {
186201
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
187202
}
188203

204+
type VirtualCartItem implements CartItemInterface @doc(description: "Virtual Cart Item") {
205+
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
206+
}
207+
189208
input CartItemInput {
190209
sku: String!
191210
qty: Float!
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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\VaultGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Vault\Api\PaymentTokenManagementInterface;
16+
use Magento\Vault\Api\PaymentTokenRepositoryInterface;
17+
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount;
18+
19+
/**
20+
* Delete Payment Token resolver, used for GraphQL mutation processing.
21+
*/
22+
class DeletePaymentToken implements ResolverInterface
23+
{
24+
/**
25+
* @var CheckCustomerAccount
26+
*/
27+
private $checkCustomerAccount;
28+
29+
/**
30+
* @var PaymentTokenManagementInterface
31+
*/
32+
private $paymentTokenManagement;
33+
34+
/**
35+
* @var PaymentTokenRepositoryInterface
36+
*/
37+
private $paymentTokenRepository;
38+
39+
/**
40+
* @param CheckCustomerAccount $checkCustomerAccount
41+
* @param PaymentTokenManagementInterface $paymentTokenManagement
42+
* @param PaymentTokenRepositoryInterface $paymentTokenRepository
43+
*/
44+
public function __construct(
45+
CheckCustomerAccount $checkCustomerAccount,
46+
PaymentTokenManagementInterface $paymentTokenManagement,
47+
PaymentTokenRepositoryInterface $paymentTokenRepository
48+
) {
49+
$this->checkCustomerAccount = $checkCustomerAccount;
50+
$this->paymentTokenManagement = $paymentTokenManagement;
51+
$this->paymentTokenRepository = $paymentTokenRepository;
52+
}
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
public function resolve(
58+
Field $field,
59+
$context,
60+
ResolveInfo $info,
61+
array $value = null,
62+
array $args = null
63+
) {
64+
if (!isset($args['public_hash'])) {
65+
throw new GraphQlInputException(__('Specify the "public_hash" value.'));
66+
}
67+
68+
$currentUserId = $context->getUserId();
69+
$currentUserType = $context->getUserType();
70+
71+
$this->checkCustomerAccount->execute($currentUserId, $currentUserType);
72+
73+
$token = $this->paymentTokenManagement->getByPublicHash($args['public_hash'], $currentUserId);
74+
if (!$token) {
75+
throw new GraphQlNoSuchEntityException(
76+
__('Could not find a token using public hash: %1', $args['public_hash'])
77+
);
78+
}
79+
80+
return ['result' => $this->paymentTokenRepository->delete($token)];
81+
}
82+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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\VaultGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Query\ResolverInterface;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
use Magento\Vault\Model\PaymentTokenManagement;
14+
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount;
15+
16+
/**
17+
* Customers Payment Tokens resolver, used for GraphQL request processing.
18+
*/
19+
class PaymentTokens implements ResolverInterface
20+
{
21+
/**
22+
* @var PaymentTokenManagement
23+
*/
24+
private $paymentTokenManagement;
25+
26+
/**
27+
* @var CheckCustomerAccount
28+
*/
29+
private $checkCustomerAccount;
30+
31+
/**
32+
* @param PaymentTokenManagement $paymentTokenManagement
33+
* @param CheckCustomerAccount $checkCustomerAccount
34+
*/
35+
public function __construct(
36+
PaymentTokenManagement $paymentTokenManagement,
37+
CheckCustomerAccount $checkCustomerAccount
38+
) {
39+
$this->paymentTokenManagement = $paymentTokenManagement;
40+
$this->checkCustomerAccount = $checkCustomerAccount;
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function resolve(
47+
Field $field,
48+
$context,
49+
ResolveInfo $info,
50+
array $value = null,
51+
array $args = null
52+
) {
53+
$currentUserId = $context->getUserId();
54+
$currentUserType = $context->getUserType();
55+
56+
$this->checkCustomerAccount->execute($currentUserId, $currentUserType);
57+
58+
$tokens = $this->paymentTokenManagement->getVisibleAvailableTokens($currentUserId);
59+
$result = [];
60+
61+
foreach ($tokens as $token) {
62+
$result[] = [
63+
'public_hash' => $token->getPublicHash(),
64+
'payment_method_code' => $token->getPaymentMethodCode(),
65+
'type' => $token->getType(),
66+
'details' => $token->getTokenDetails(),
67+
];
68+
}
69+
70+
return ['items' => $result];
71+
}
72+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# VaultGraphQl
2+
3+
**VaultGraphQl** provides type and resolver information for the GraphQl module
4+
to generate Vault (stored payment information) information endpoints. This module also
5+
provides mutations for modifying a payment token.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "magento/module-vault-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-vault": "*",
9+
"magento/module-customer-graph-ql": "*"
10+
},
11+
"license": [
12+
"OSL-3.0",
13+
"AFL-3.0"
14+
],
15+
"autoload": {
16+
"files": [
17+
"registration.php"
18+
],
19+
"psr-4": {
20+
"Magento\\VaultGraphQl\\": ""
21+
}
22+
}
23+
}
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_VaultGraphQl"/>
10+
</config>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
type Mutation {
5+
deletePaymentToken(public_hash: String!): DeletePaymentTokenOutput @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\DeletePaymentToken") @doc(description:"Delete a customer payment token")
6+
}
7+
8+
type DeletePaymentTokenOutput {
9+
result: Boolean!
10+
customerPaymentTokens: CustomerPaymentTokens @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens")
11+
}
12+
13+
type Query {
14+
customerPaymentTokens: CustomerPaymentTokens @doc(description: "Return a list of customer payment tokens") @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens")
15+
}
16+
17+
type CustomerPaymentTokens @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens") {
18+
items: [PaymentToken]! @doc(description: "An array of payment tokens")
19+
}
20+
21+
type PaymentToken @doc(description: "The stored payment method available to the customer") {
22+
public_hash: String! @doc(description: "The public hash of the token")
23+
payment_method_code: String! @doc(description: "The payment method code associated with the token")
24+
type: PaymentTokenTypeEnum!
25+
details: String @doc(description: "Stored account details")
26+
}
27+
28+
enum PaymentTokenTypeEnum @doc(description: "The list of available payment token types") {
29+
card
30+
account
31+
}
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_VaultGraphQl', __DIR__);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
"magento/module-usps": "*",
237237
"magento/module-variable": "*",
238238
"magento/module-vault": "*",
239+
"magento/module-vault-graph-ql": "*",
239240
"magento/module-version": "*",
240241
"magento/module-webapi": "*",
241242
"magento/module-webapi-async": "*",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)