Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit e819382

Browse files
pmclainkeharper
authored andcommitted
BraintreeGraphQl Workflow (#4915)
* BraintreeGraphQl Workflow Corresponds to magento/graphql-ce#392 * Update from review feedback
1 parent 7fa9962 commit e819382

File tree

3 files changed

+219
-0
lines changed

3 files changed

+219
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
group: graphql
3+
title: createBraintreeClientToken mutation
4+
contributor_name: Something Digital
5+
contributor_link: https://www.somethingdigital.com/
6+
---
7+
8+
The `createBraintreeClientToken` mutation creates the client token required by the Braintree SDK for nonce generation.
9+
10+
## Syntax
11+
12+
`mutation: {createBraintreeClientToken}: String`
13+
14+
## Example usage
15+
16+
**Request**
17+
18+
```graphql
19+
mutation {
20+
createBraintreeClientToken
21+
}
22+
```
23+
24+
**Response**
25+
26+
```json
27+
{
28+
"data": {
29+
"createBraintreeClientToken": "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"}
30+
}
31+
}
32+
```
33+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
group: graphql
3+
title: Braintree Vault payment method
4+
contributor_name: Something Digital
5+
contributor_link: https://www.somethingdigital.com/
6+
---
7+
8+
Braintree Vault is a payment gateway that processes debit and credit card payments from the Magento_Vault.
9+
10+
## Braintree Vault workflow
11+
12+
1. Use the [`customerPaymentTokens`]({{page.baseurl}}/graphql/queries/customer-payment-tokens.html) query to retrieve
13+
the payment tokens the customer has stored in the vault.
14+
15+
2. Magento returns an array of payment tokens.
16+
17+
3. The client renders the token information, and the customer selects a payment method.
18+
19+
4. Customer selects stored Braintree payment method.
20+
21+
5. When the customer clicks **Place Order**, the PWA uses the [`setPaymentMethodOnCart`]({{page.baseurl}}/graphql/reference/quote-payment-method.html)
22+
mutation to set the payment method to `braintree_cc_vault`. The vaulted public hash is passed with other optional
23+
properties in the [`braintree_cc_vault`](#braintree_cc_vault-object).
24+
25+
6. Magento returns a `Cart` object.
26+
27+
7. The client runs the [`placeOrder`]({{page.baseurl}}/graphql/reference/quote-place-order.html) mutation.
28+
29+
8. Magento sends an authorization request to the gateway.
30+
31+
9. The gateway sends the response to Magento.
32+
33+
10. Magento creates an order and sends an order ID in response to the `placeOrder` mutation.
34+
35+
## `setPaymentMethodOnCart` mutation
36+
37+
When you set the payment method to Braintree in the [`setPaymentMethodOnCart`]({{page.baseurl}}/graphql/reference/quote-payment-method.html)
38+
mutation, the `payment_method` object must contain a `braintree_cc_vault` object.
39+
40+
### braintree_cc_vault object
41+
42+
The `braintree_cc_vault` object must contain the following attributes:
43+
44+
Attribute | Data Type | Description
45+
--- | --- | ---
46+
`public_hash` | String! | Required input for Magento_Vault public hash for the selected stored payment method
47+
`device_data` | String | Optional. JSON-encoded device data for Kount integration
48+
49+
### Example Usage
50+
51+
The following example shows the `setPaymentMethodOnCart` mutation constructed for the Braintree Vault payment method.
52+
53+
**Request**
54+
55+
```graphql
56+
mutation {
57+
setPaymentMethodOnCart(input: {
58+
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG"
59+
payment_method: {
60+
code: "braintree_cc_vault"
61+
braintree_cc_vault: {
62+
public_hash: "fake-public-hash"
63+
}
64+
}
65+
}) {
66+
cart {
67+
selected_payment_method {
68+
code
69+
}
70+
}
71+
}
72+
```
73+
74+
**Response**
75+
76+
```json
77+
{
78+
"data": {
79+
"setPaymentMethodOnCart": {
80+
"cart": {
81+
"selected_payment_method": {
82+
"code": "braintree_cc_vault"
83+
}
84+
}
85+
}
86+
}
87+
}
88+
```
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
group: graphql
3+
title: Braintree payment method
4+
contributor_name: Something Digital
5+
contributor_link: https://www.somethingdigital.com/
6+
---
7+
8+
Braintree is a payment gateway that processes debit and credit card payments.
9+
10+
## Braintree workflow
11+
12+
1. The client uses [`createBraintreeClientToken`]({{page.baseurl}}/graphql/mutations/braintree-create-client-token.html)
13+
14+
2. Initialize the [Braintree hosted fields](https://developers.braintreepayments.com/guides/hosted-fields/overview/javascript/v3)
15+
using the client token to collect and tokenize payment information via a secure iframe.
16+
17+
3. On the checkout page, the customer selects **Credit Card** as the payment method and inputs payment information using
18+
the Braintree hosted fields.
19+
20+
4. The customer clicks **Place Order**
21+
22+
5. The client requests the Braintree SDK tokenize the user-input payment information.
23+
24+
6. The Braintree SDK submits the payment information to Braintree client-side and returns a [payment token](https://braintree.github.io/braintree-web/3.46.0/HostedFields.html#tokenize)
25+
to the client.
26+
27+
7. The client extracts the payment nonce from the [Tokenized Payload](https://braintree.github.io/braintree-web/3.46.0/HostedFields.html#~tokenizePayload).
28+
29+
8. The client uses the [`setPaymentMethodOnCart`]({{page.baseurl}}/graphql/reference/quote-payment-method.html) mutation
30+
to set the payment method to `braintree`. The payment method nonce is passed with other required and optional
31+
properties in the [`braintree`](#braintree-object).
32+
33+
9. Magento returns a `Cart` object.
34+
35+
10. The client uses the [`placeOrder`]({{page.baseurl}}/graphql/reference/quote-place-order.html) mutation.
36+
37+
11. Magento sends an authorization request to the gateway.
38+
39+
12. The gateway sends the response to Magento.
40+
41+
13. Magento creates an order and sends an order ID in response to the `placeOrder` mutation.
42+
43+
## `setPaymentMethodOnCart` mutation
44+
45+
When you set the payment method to Braintree in the [`setPaymentMethodOnCart`]({{page.baseurl}}/graphql/reference/quote-payment-method.html)
46+
mutation, the `payment_method` object must contain a `braintree` object.
47+
48+
### braintree object
49+
50+
The `braintree` object must contain the following attributes:
51+
52+
Attribute | Data Type | Description
53+
--- | --- | ---
54+
`payment_method_nonce` | String! | Required input for Braintree client-side generated nonce
55+
`is_active_payment_token_enabler` | Boolean! | Required input dictating if payment should be stored in `Magento_Vault`
56+
`device_data` | String | Optional. JSON-encoded device data for Kount integration
57+
58+
## Example Usage
59+
60+
The following example shows the `setPaymentMethodOnCart` mutation constructed for the Braintree payment method.
61+
62+
**Request**
63+
64+
```text
65+
mutation {
66+
setPaymentMethodOnCart(input: {
67+
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG"
68+
payment_method: {
69+
code: "braintree"
70+
braintree: {
71+
payment_method_nonce: "fake-nonce"
72+
is_active_payment_token_enabler: false
73+
}
74+
}
75+
}) {
76+
cart {
77+
selected_payment_method {
78+
code
79+
}
80+
}
81+
}
82+
```
83+
84+
**Response**
85+
86+
```json
87+
{
88+
"data": {
89+
"setPaymentMethodOnCart": {
90+
"cart": {
91+
"selected_payment_method": {
92+
"code": "braintree"
93+
}
94+
}
95+
}
96+
}
97+
}
98+
```

0 commit comments

Comments
 (0)