|
| 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 | +``` |
0 commit comments