Image source https://blog.charmes.net/images/gopherswrench.jpg

Overview

Braintree is one of the biggest payment gateway provider that providing tons of capabilities to perform payment operations.

Google App Engine is a fully managed platform that completely abstracts away infrastructure so developer only focus on code


Braintree is not providing (yet) official SDK for Go-lang. Gratefully someone has made it perfectly — available for us.

Braintree Go SDK : https://github.com/lionelbarrow/braintree-go

Problem

In past few months ago I was struggled when running it on Google App Engine machine, either in local GAE (dev_appserver) or when it was published to the GAE cloud.

The SDK throwing this error message :

“Unable to generate client token : Post https://api.sandbox.braintreegateway.com:443/merchants/xxxxx/client_token: http.DefaultTransport and http.DefaultClient are not available in App Engine. See https://cloud.google.com/appengine/docs/go/urlfetch/"

Someone has similiar issue with me :

https://github.com/lionelbarrow/braintree-go/issues/49

This issue appears because App Engine doesn’t allow us to perform outbound request directly using native Go-lang http client, everything should be passed over urlfetch.

Solution

So we need to attach custom http client (GAE url fetch client) when we creating Braintree client.

Here’s two example that covered those issue :

  • Create Braintree client ( had a problem here ) :
Iin the code above, app engine will block the outbound requests from the SDK
  • Solution, create Braintree client with custom http client :
create custom httpclient (line 2) then pass it on the braintree client creation (line 8)

Now, it’s working perfectly on GAE machine.

That’s all :)

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Tajhul Faijin Aliyudin

Written by

Code Composer, Earth Traveller

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade