Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

Integrating Braintree Auth Allows Customers to Connect Their Braintree Account to Your Platform

Devin Clark

Braintree Auth is a new feature of Braintree that allows customers to link their personal Braintree accounts to a company’s platform. This technology allows the company to do all the heavy lifting by reading transactions and processing payments on the customer’s behalf. The process works similar to the way customers can sign in on other sites using their social media credentials.

Tallan is the first company to ever set up the Braintree Auth feature. We found a need for it on the SmartRaiser platform. Before we used Braintree Auth, customers were required to get their funds from SmartRaiser directly and the process could take several months to allow all payments to settle. With Braintree Auth, customers can access transactional information much faster and receive payments in as little as two business days.

Braintree has created a simple API to get started with this process and their well detailed documentation is available on their website. The first step is to create a sandbox OAuth application to get your test credentials.

braintree-auth-1

Next, we use the ClientId and ClientSecret in our server code to create a URL that Braintree uses to connect the Customer’s Braintree account with our platform.

BraintreeGateway gateway = new BraintreeGateway(
"use_your_client_id",
"use_your_client_secret"
);

string url = gateway.OAuth.ConnectUrl(new OAuthConnectUrlRequest {
RedirectUri = “https://your.redirect.uri”,
Scope = “read_write”,
State = “foo_state”,
LandingPage = “signup”,
User = new OAuthConnectUrlUserRequest {
Country = “USA”,
Email = “foo@example.com”
},
Business = new OAuthConnectUrlBusinessRequest {
Name = “14 Ladders”,
RegisteredAs = “14.0 Ladders”
},
PaymentMethods = new string[] {“credit_card”, “paypal”}
});

The Braintree URL is used on the front end to create a nice Braintree button. Braintree has kindly provided several code snippets in different languages for developers to use for their mobile or web application.

braintree-auth-2

When the customer selects the Braintree button, they will be redirected to the Braintree website to give the company permission to access their account.

braintree-auth-3

After the customer completes the process, they will be redirected back to the company’s website. The query string will contain a MerchantId parameter that identifies the Braintree customer account number. The MerchantId is used with some Braintree API methods and is helpful for support issues. Now we need to use the code parameter in the query string to get an AccessToken for this customer.

BraintreeGateway gateway = new BraintreeGateway(
"use_your_client_id",
"use_your_client_secret"
);

var request = new OAuthCredentialsRequest {
Code = codeFromQueryString
};

Result result = gateway.OAuth.CreateTokenFromCode(request);

string accessToken = result.Target.AccessToken;
DateTime expiresAt = result.Target.ExpiresAt.Value;
string refreshToken = result.Target.RefreshToken;

The AccessToken is a unique key that allows the company to perform actions on the customer’s behalf. A RefreshToken can be used to get a new AccessToken if it has expired or been compromised. When reading transactions or processing payments, the Braintree API will require an active AccessToken to process the request.

Now we have setup the Braintree Auth service with our platform. There is still more that needs to be done depending on the types of transactions or inquiries the application needs to handle. We hope this blog post demonstrated how easy it is to integrate Braintree Auth in your application.

_________________________________________________________________________________________

To learn more on how Tallan can transform your online visitors into customers with our Ecommerce Consulting Services, CLICK HERE.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>