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

Commit a8e045f

Browse files
committed
BraintreeGraphQl Workflow
Corresponds to magento/graphql-ce#392
1 parent ba01d6c commit a8e045f

File tree

3 files changed

+205
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)