-
Notifications
You must be signed in to change notification settings - Fork 153
Add endpoint for fetching/deleting vault tokens #307
Conversation
/** | ||
* Vault payment token repository | ||
*/ | ||
class PaymentTokenManagement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about VisibleTokenRetriever
or something similar?
*Management
should be avoided in class names as too generic.
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount; | ||
|
||
/** | ||
* Payment Token resolver, used for GraphQL request processing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update description
|
||
**VaultGraphQl** provides type and resolver information for the GraphQl module | ||
to generate Vault (stored payment information) information endpoints. Also | ||
provides endpoints for modifying a payment token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provides endpoints for modifying a payment token. | |
provides mutations for modifying a payment token. |
"magento/module-customer-graph-ql": "*" | ||
}, | ||
"suggest": { | ||
"magento/module-graph-ql": "*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is interesting, will it even work without GraphQL module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. You caught me copying the composer.json
from another module :)
} | ||
|
||
type DeletePaymentTokenOutput { | ||
result: Boolean! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it makes sense to allow retrieval of updated customerPaymentTokens
value as a result of mutation to prevent subsequent query when rendering the list again.
How about having two fields here:
result: Bolean!
customerPaymentTokens: CustomerPaymentTokens
} | ||
|
||
type CustomerPaymentTokens { | ||
items: [PaymentToken] @doc(description: "An array of payment tokens") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
items: [PaymentToken] @doc(description: "An array of payment tokens") | |
items: [PaymentToken]! @doc(description: "An array of payment tokens") |
I assume at least an empty array will always be returned.
type PaymentToken @doc(description: "Stored payment method available to customer") { | ||
public_hash: String! @doc(description: "Token public hash") | ||
payment_method_code: String! @doc(description: "Payment method code associated with token") | ||
type: String! @doc(description: "Token type [card|account]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be declared as enum if just two values are possible.
QUERY; | ||
$response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); | ||
|
||
$this->assertEquals(1, count($response['customerPaymentTokens']['items'])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we should validate each field
@paliarush Thanks for the feedback. The requested changes have been made. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments are for descriptions and exception messages.
$token = $this->paymentTokenManagement->getByPublicHash($args['public_hash'], $currentUserId); | ||
if (!$token) { | ||
throw new GraphQlNoSuchEntityException( | ||
__('Token could not be found by public hash: %1', $args['public_hash']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__('Token could not be found by public hash: %1', $args['public_hash']) | |
__('Could not find a token using public hash: %1', $args['public_hash']) |
# VaultGraphQl | ||
|
||
**VaultGraphQl** provides type and resolver information for the GraphQl module | ||
to generate Vault (stored payment information) information endpoints. Also |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to generate Vault (stored payment information) information endpoints. Also | |
to generate Vault (stored payment information) information endpoints. This module also |
# See COPYING.txt for license details. | ||
|
||
type Mutation { | ||
deletePaymentToken(public_hash: String!): DeletePaymentTokenOutput @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\DeletePaymentToken") @doc(description:"Delete customer Payment Token") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deletePaymentToken(public_hash: String!): DeletePaymentTokenOutput @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\DeletePaymentToken") @doc(description:"Delete customer Payment Token") | |
deletePaymentToken(public_hash: String!): DeletePaymentTokenOutput @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\DeletePaymentToken") @doc(description:"Delete a customer payment token") |
} | ||
|
||
type Query { | ||
customerPaymentTokens: CustomerPaymentTokens @doc(description: "List of customer payment tokens") @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customerPaymentTokens: CustomerPaymentTokens @doc(description: "List of customer payment tokens") @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens") | |
customerPaymentTokens: CustomerPaymentTokens @doc(description: "Return a list of customer payment tokens") @resolver(class: "\\Magento\\VaultGraphQl\\Model\\Resolver\\PaymentTokens") |
} | ||
|
||
type PaymentToken @doc(description: "Stored payment method available to customer") { | ||
public_hash: String! @doc(description: "Token public hash") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public_hash: String! @doc(description: "Token public hash") | |
public_hash: String! @doc(description: "The public hash of the token") |
items: [PaymentToken]! @doc(description: "An array of payment tokens") | ||
} | ||
|
||
type PaymentToken @doc(description: "Stored payment method available to customer") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type PaymentToken @doc(description: "Stored payment method available to customer") { | |
type PaymentToken @doc(description: "The stored payment method available to the customer") { |
|
||
type PaymentToken @doc(description: "Stored payment method available to customer") { | ||
public_hash: String! @doc(description: "Token public hash") | ||
payment_method_code: String! @doc(description: "Payment method code associated with token") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
payment_method_code: String! @doc(description: "Payment method code associated with token") | |
payment_method_code: String! @doc(description: "The payment method code associated with the token") |
@keharper Thanks for review! The suggested changes have been applied. |
There was 1 failure: 1) Magento\Test\Integrity\DependencyTest::testRedundant Redundant dependencies found! Module Magento\VaultGraphQl: hard [Magento\GraphQl]
# Conflicts: # composer.lock
-- fix static tests
@pmclain
Thanks |
# Conflicts: # composer.lock
-- Update composer lock
Hi @pmclain, thank you for your contribution! |
#46
Description (*)
Add query for fetching visible payment tokens:
The
details
property is the string value ofvault_payment_token.details
. This field contains serialized details that vary by the payment implementation. I'm not sure if we want to expose an interface for formatting this information similar to what is used in Magento_InstantPurchase or leave as-is.Add mutation for deleting payment tokens:
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)