Custom HTTP Client Braintree Go-lang Google App Engine
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
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 :
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.
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 ) :
- Solution, create Braintree client with custom http client :
Now, it’s working perfectly on GAE machine.
That’s all :)