Braintree GraphQL

Overview

In this article, we'll explore how to connect to Braintree's new Graph QL API.

The scenario we'll use is an Order-to-Cash, for an eCommerce, as illustrated by the sequence diagram below. However, the concepts explained can be extrapolated and used in other contexts. Keep in mind that the destination endpoint is NetSuite for illustration purposes and could easily be replaced by any other ERP or order management software.

Here's an outline of the steps within this scenario.

  1. A customer places an order through the website (in our case, implemented with BigCommerce).
  2. BigCommerce communicates directly with Braintree to capture details, such as the payment method, and (pre)authorize the transaction. At this point, Braintree returns to BigCommerce a transaction ID.
  3. BigCommerce sends the Order details (including the Braintree transaction ID) to NetSuite, via a Celigo integration.
  4. Once the order is ready to be fulfilled (e.g. in Pending Fulfilment State), NetSuite sends a request to Braintree to submit the transaction for settlement, via a Celigo Integration, thus obtaining payment from the customer's payment method. Braintree returns the status of the transaction, which is saved in NetSuite. At this point, one of two things can happen, as listed below.
    1. If the request is successful and the status of the transaction is "SETTLED", then the order can be fulfilled.
    2. If the request is unsuccessful or the status of the transaction is something other than "SETTLED", then the order would not be fulfilled.
Variations
A similar approach to the above could be used to handle refunds as well.

Assumptions

As this post focused primarily on Braintree, steps necessary to setup the eCommerce platform and ERP/Order management have been left out. It's assumed that you have either already set these up or can find other resources to help with that. If you require assistance, please get in touch with your contact person within Celigo.

Steps

To replicate this scenario, go ahead and follow the steps below.

1. Create a sandbox account in Braintree using the form available here.

2. Head over to the API section.

The screenshot below has hidden the public key but you should see yours. Select view.

Save the API keys (public & private) as well as the merchant ID from here.

3. Create a connection to Braintree in Integrator.io, as described below.

Connection

Name : Braintree GraphQL (or something else meaningful to you)
Connection Type : HTTP
Mode : cloud
Authentication Type : Token
Configure HTTP Headers
> Content-Type : application/json
> Braintree-Version : 2020-05-07
Base URI : https://payments.sandbox.braintree-api.com/graphql
Media Type : JSON
Token: BASIC : PUBLIC_KEY:PRIVATE_KEY

Note: For the token, be sure to encode the sequence PUBLIC_KEY:PRIVATE_KEY with base64 encoding. A good resource to do this is base64encore.org

How to send token?

Location : Header
Scheme : Bearer

4. Test the connection

To test the connection, define the parameters as follows.

Ping Method: POST
Ping Body: { "query": "query { ping }" }

5. Create an integration flow, where Braintree is one of the imports.

Here's an example flow

Define the import to Braintree, as described below.

Name: Braintree - Capture Transaction
Input Mode: Records
Method: POST
Request Media Type: JSON
Response Id Path: (e.g. /data/transaction/id)
Error Path: /errors
Success Media Type: JSON
Error Media Type: JSON

6. Test your integration flow.

From here, you should be able to test your flow.
 

Resources

Below are some of the resources used to understand how the Braintree GraphQL API works.

 

0

Comments

9 comments
Date Votes
  • Official comment

    Sara Parsons Danny Rojas

    I want to let you know that we are working on GraphQL generic connector and it is targeted for Q2 2022 platform release. Below is a preview of what's coming and the feature capability so that building integration with GraphQL endpoints will be less complex and tedious. Thanks

     

  • Have you dealt with paginating through the results when calling a search query on transactions? I've tried using Post Body pagination method but I can't figure out how to reference the endCursor in my paging post body request. Any ideas?

    0
  • Hey Danny Rojas,

    Thank-you for your question, glad to see you're trying out the Braintree GraphQL API.

    I'm yet to try the pagination myself but I can have a look at the use-case and provide some feedback. Can you attach screenshots of how you've configured the pagination on the Celigo side?

    0
  • Thanks for replying Adel, on the first screenshot I have preview data that shows the pageInfo property with the pagination so in my second screenshot in the paging post body I basically add the same query I'm doing the first time but I now add the handlebar in the parameter "after" to reference the endCursor of the current page but I can see I don't have that resource in the handlebar editor. Any help on how to do this would be appreciated. Thanks again.

    0
  • Hi Danny Rojas

    You're code looks correct. Even if the data doesn't show up in the editor, you still have access to whatever is in the payload in runtime at the moment of processing the pagination request.

    What error / behaviour are you seeing on your end?

    0
  • Adel, 

    All I'm getting when running flow is the first page of results so it's not paginating and I don't get any errors. So I'm not sure what's going on.

    I have tried different handlebars paths but still with no success:

    1. result.pageInfo.endCursor

    2. record.pageInfo.endCursor

    3. pageInfo.endCursor

    4. data.search.transactions.pageInfo.endCursor (took out the resource path)

     

    0
  • Hi Danny Rojas

    Let's set up a call next week to dig into this together. :)

    • Where are you based?
    • What's your email address?
    0
  • Adel, I'm in Mountain Time and my email is dannyr@squire.com. I can be flexible anytime.

    0
  • Hello, 

    Any updates to the pagination issue with GraphQL?  I'm looking to integrate two APIs, one is REST and the other is Graph.  When I receive multiple pages of results, I'm having trouble figuring out how to configure pagination to get the next page's worth of information.

    ============================
    UPDATED 8/2022: Answer now found at Manage Braintree GraphQL pagination.

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post