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

Commit 1f3ed3a

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

File tree

3 files changed

+209
-0
lines changed

3 files changed

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