A Go client library for Braintree
Go
Latest commit c766a80 Apr 29, 2017 @leighmcculloch leighmcculloch Tidy the WebhookNotification kind const list.
Reorder the WebhookNotification's kind const list so that they are
grouped by subject and removed extra whitespace.
Permalink
Failed to load latest commit information.
customfields Add custom fields to transactions and customers (#115) Mar 28, 2017
date Parallelize tests Mar 21, 2017
examples Separate structs for Transaction request and response (#129) Apr 19, 2017
nullable Parallelize tests Mar 21, 2017
testhelpers Fix tests that depend on math/rand for uniqueness. May 13, 2016
.default.env Correct the test accounts timezone Apr 2, 2017
.gitignore Add .env to .gitignore for use with autoenv when running tests Feb 20, 2015
.travis.yml Parallelize tests Mar 21, 2017
CHANGELOG.md Add CHANGELOG for v0.10.0 Apr 14, 2017
Makefile Parallelize tests Mar 21, 2017
README.md Added TestWebhookNotification for testing purposes. Apr 29, 2017
TESTING.md update TESTING.md Mar 27, 2017
add_on.go Add AddOns Nov 20, 2013
add_on_gateway.go Add AddOns Nov 20, 2013
add_on_integration_test.go Parallelize tests Mar 21, 2017
address.go Use real time.Time structs for CreatedAt/UpdatedAt Jan 23, 2015
address_gateway.go pass pointer of copied object Jul 9, 2013
address_integration_test.go Parallelize tests Mar 21, 2017
braintree.go Added TestWebhookNotification for testing purposes. Apr 29, 2017
client_token.go Rearrange client token API and add test Aug 9, 2015
client_token_gateway.go Rearrange client token API and add test Aug 9, 2015
client_token_integration_test.go Parallelize tests Mar 21, 2017
credentials.go Hide the credentials Mar 31, 2017
credentials_access_token.go Export the environmentFromName method (#137) Apr 26, 2017
credentials_api_key.go Hide the credentials Mar 31, 2017
credentials_test.go Hide the credentials Mar 31, 2017
credit_card.go Fix go vet and make travis run it Mar 9, 2017
credit_card_gateway.go credit card update and delete Jul 12, 2013
credit_card_integration_test.go Parallelize tests Mar 21, 2017
customer.go Add custom fields to transactions and customers (#115) Mar 28, 2017
customer_gateway.go Remove unnecessary 'reassign ID' function on customer gateway Oct 30, 2015
customer_integration_test.go Merge branch 'master' into michaljemala-issue-38 Mar 31, 2017
decimal.go Fixed decimal bug where NewDecimal(5,2) would print 5.00 instead of .05 Mar 17, 2016
decimal_test.go Parallelize tests Mar 21, 2017
descriptor.go Add descriptor to Transactions and Subscriptions Mar 18, 2017
disbursement.go Resolve merge conflicts Apr 3, 2015
disbursement_details.go Move nullable types to their own package Apr 3, 2015
disbursement_integration_test.go Parallelize tests Mar 21, 2017
discount.go Add Discounts Nov 22, 2013
discount_gateway.go Add Discounts Nov 22, 2013
discount_integration_test.go Parallelize tests Mar 21, 2017
doc.go Hide the credentials Mar 31, 2017
environment.go Export the environmentFromName method (#137) Apr 26, 2017
environment_test.go Restructure environments for easy overriding (#114) Mar 28, 2017
errors.go Fix doc formatting Apr 19, 2016
errors_test.go Parallelize tests Mar 21, 2017
fake_nonces.go Add fake nonces that can be used with sandbox Mar 3, 2017
hmac.go Tighten the depencencies of hmacer Mar 31, 2017
hmac_test.go Remove TODOs Apr 26, 2017
merchant_account.go Added Webhook Notifications Jan 30, 2014
merchant_account_gateway.go Fixes path for merchant account updates May 7, 2014
merchant_account_integration_test.go Separate structs for Transaction request and response (#129) Apr 19, 2017
modification.go Peel back the changes being merged in to SubcriptionRequest only Mar 17, 2017
modification_request.go Use structs for the XML definition instead of coding the marshaler ma… Mar 30, 2017
modification_request_test.go Added additional tests to exercise modifications fully Mar 30, 2017
payment_method.go Merge branch 'master' into payment-method-image-url Mar 6, 2017
payment_method_gateway.go Rename ApiVersion to apiVersion Mar 30, 2017
payment_method_integration_test.go Parallelize tests Mar 21, 2017
paypal_account.go Merge branch 'master' into payment-method Mar 6, 2017
paypal_account_gateway.go Rename ApiVersion to apiVersion Mar 30, 2017
paypal_account_integration_test.go Parallelize tests Mar 21, 2017
paypal_details.go Add PayPalDetails to Transactions Mar 4, 2017
plan.go Make AddOns and Discounts not pointers since even if this was to supp… Mar 9, 2017
plan_gateway.go implement finding plan by id Jul 13, 2013
plan_integration_test.go Parallelize tests Mar 21, 2017
processor_response_code.go Unmarshal transaction processor response code when empty Mar 30, 2017
response.go Merge branch 'master' into michaljemala-issue-38 Mar 31, 2017
search.go Change the time format to match the Braintree Java SDK Mar 21, 2017
search_test.go Merge pull request #111 from lionelbarrow/parallelize-tests Mar 22, 2017
settlement.go Fixed settlement batch summary unmarshaling. Apr 2, 2017
settlement_gateway.go Added Submit For Settlement functionality Jan 8, 2016
settlement_integration_test.go Separate structs for Transaction request and response (#129) Apr 19, 2017
subscription.go Add modifications to subscriptions Mar 30, 2017
subscription_gateway.go Add support for Addons and Discounts for Subscriptions. Jan 17, 2017
subscription_integration_test.go Added additional tests to exercise modifications fully Mar 30, 2017
test_values.go Hide the credentials Mar 31, 2017
testing_gateway.go Added TestWebhookNotification for testing purposes. Apr 29, 2017
testing_integration_test.go Separate structs for Transaction request and response (#129) Apr 19, 2017
transaction.go Add risk data request to transaction (#130) Apr 19, 2017
transaction_gateway.go Separate structs for Transaction request and response (#129) Apr 19, 2017
transaction_integration_test.go Add risk data request to transaction (#130) Apr 19, 2017
transaction_paypal_details_integration_test.go Separate structs for Transaction request and response (#129) Apr 19, 2017
webhook_notification.go Tidy the WebhookNotification kind const list. Apr 30, 2017
webhook_notification_gateway.go Add ParseRequest to WebhookNotificationGateway Apr 26, 2017
webhook_notification_test.go Review feedback Apr 28, 2017
webhook_testing_gateway.go Make payloadTemplate const Apr 29, 2017
webhook_testing_gateway_test.go Added TestWebhookNotification for testing purposes. Apr 29, 2017

README.md

Braintree Go

GoDoc Build Status

A Go client library for Braintree, the payments company behind awesome companies like GitHub, Heroku, and 37signals.

This is not an official client library. Braintree maintains server-side libraries for Ruby, Python, PHP, Perl, Node, C# and Java, but not Go. This package implements the core functionality of the other client libraries, but it's missing a few advanced features.

With that said, this package contains more than enough to get you started accepting payments using Braintree. If there's a feature the other client libraries implement that you really need, open an issue (or better yet, a pull request).

Usage

Setting up your credentials is easy.

import "github.com/lionelbarrow/braintree-go"

bt := braintree.New(
  braintree.Sandbox,
  "YOUR_BRAINTREE_MERCH_ID",
  "YOUR_BRAINTREE_PUB_KEY",
  "YOUR_BRAINTREE_PRIV_KEY",
)

So is creating your first transaction.

tx, err := bt.Transaction().Create(&braintree.TransactionRequest{
  Type: "sale",
  Amount: braintree.NewDecimal(100, 2), // 100 cents
  CreditCard: &braintree.CreditCard{
    Number:         "4111111111111111",
    ExpirationDate: "05/14",
  },
})

The error returned by these calls is typed. The package returns a generic error when something mechanical goes wrong, such as receiving malformed XML or being unable to connect to the Braintree gateway. However, if Braintree was able to process the request correctly, but was unable to fulfill it due to a semantic failure (such as the credit card being declined) then a BraintreeError type is returned.

In addition to creating transactions, you can also tokenize credit card information for repeat or subscription billing using the CreditCard, Customer, and Subscription types. This package is completely compatible with Braintree.js, so if you encrypt your customers' credit cards in the browser, you can pass them on to Braintree without ever seeing them yourself. This decreases your PCI regulatory exposure and helps to secure your users' data. See the examples folder for a working implementation.

Installation

The usual. go get github.com/lionelbarrow/braintree-go

Documentation

Braintree provides a ton of documentation on how to use their API. I recommend you use the Ruby documentation when following along, as the Ruby client library is broadly similar to this one.

For details on this package, see GoDoc.

Testing

The integration tests run against a sandbox account created in the Braintree Sandbox. See TESTING.md for further instructions on how to set up your sandbox for integration testing.

You can run tests locally using the same credentials that Travis CI uses by using the credentials in .default.env. Simply cp .default.env .env if you use a tool that autoloads .env files, or source .default.env to load the credentials into your shell. Then run tests with go test ./....

source .default.env
go test ./...

Webhook Integration Testing

You can use the WebhookTestingGateway to write your own integration tests to verify your application is processing incoming webhook notifications correctly.

A simple example:

package integration_test

import (
  "testing"
  "net/http/httptest"

  "github.com/lionelbarrow/braintree-go"
)

func TestMyWebhook(t *testing.T) {
  bt := braintree.New(
    braintree.Sandbox,
    "merchaint_id",
    "public_key",
    "private_key",
  )

  r, err := bt.WebhookTesting().Request(
    braintree.SubscriptionChargedSuccessfullyWebhook,
    "123", // id
  )
  if err != nil {
    t.Fatal(err)
  }

  // You can now send the payload and signature to your webhook handler
  // and test your application's busines logic

  w := httptest.NewRecorder()
  router.ServeHTTP(w, r)

  // assertions
}

License

The MIT License (MIT)

Copyright (c) 2013 Lionel Barrow

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributors