A Go client library for Braintree
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
customfields Add build tags for unit and integration tests (#202) Dec 23, 2017
date Add build tags for unit and integration tests (#202) Dec 23, 2017
examples Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
testhelpers Add BIN field to ApplePayCard and ApplePayDetails (#262) Oct 3, 2018
xmlnil Add build tags for unit and integration tests (#202) Dec 23, 2017
.default.env Add a test merchant account ID with AVS and CVV checking enabled. May 3, 2017
.gitignore Add Visual Studio Code common project files Nov 4, 2018
.travis.yml Reduce the number of builds that run on CI Nov 16, 2018
CHANGELOG.md Add changelog for v0.22.0 Nov 20, 2018
Makefile Remove the apicompat backwards compatibility check Jul 22, 2018
README.md Fix build link in README Nov 3, 2018
TESTING.md Correct test documentation Jul 21, 2018
account_updater_daily_report.go Add account updater daily report to webhooks (#260) Aug 9, 2018
add_on.go Add AddOns Nov 20, 2013
add_on_gateway.go Added comments to exported methods and structs (#238) Jun 7, 2018
add_on_integration_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
address.go Add AddressRequest (#211) Feb 28, 2018
address_gateway.go Added comments to exported methods and structs (#238) Jun 7, 2018
address_integration_test.go Added Addresses to Customer and Update to AddressGateway (#209) Mar 2, 2018
android_pay_card.go Remove omitempty from structs only used for deserialization (#201) Dec 23, 2017
android_pay_card_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
android_pay_details.go Remove omitempty from structs only used for deserialization (#201) Dec 23, 2017
android_pay_details_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
apple_pay_card.go Add BIN field to ApplePayCard and ApplePayDetails (#262) Oct 3, 2018
apple_pay_details.go Add BIN field to ApplePayCard and ApplePayDetails (#262) Oct 3, 2018
avs_response_code.go Add AVSResponseCode type and constants. May 3, 2017
braintree.go Intoduce 3DS support (bis repetita) (continued) (#253) Jul 31, 2018
client_token.go Add more fields and options to client token generate (#265) Nov 6, 2018
client_token_gateway.go Add more fields and options to client token generate (#265) Nov 6, 2018
client_token_integration_test.go Add more tests around client token marshalling (#269) Nov 8, 2018
client_token_test.go Add more tests around client token marshalling (#269) Nov 8, 2018
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 Add build tags for unit and integration tests (#202) Dec 23, 2017
credit_card.go Add ProductID to CreditCard (#274) Nov 16, 2018
credit_card_gateway.go Add ExpiringBetween methods to CreditCardGateway (#244) Jul 20, 2018
credit_card_integration_test.go Add ProductID to CreditCard (#274) Nov 16, 2018
credit_card_test.go Add tests for xml serializing (#271) Nov 16, 2018
customer.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
customer_android_pay_integration_test.go Add CustomerRequest (#212) Feb 28, 2018
customer_apple_pay_integration_test.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
customer_gateway.go Add SearchIDs and SearchPage to CustomerGateway (#257) Jul 24, 2018
customer_integration_test.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
customer_paypal_account_integration_test.go Add CustomerRequest (#212) Feb 28, 2018
customer_venmo_account_integration_test.go Revert "Temporarily skip the Customer Venmo Account integration test" Nov 15, 2018
cvv_response_code.go Added comments to exported methods and structs (#238) Jun 7, 2018
decimal.go Fixed decimal bug where NewDecimal(5,2) would print 5.00 instead of .05 Mar 17, 2016
decimal_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
descriptor.go Add descriptor to Transactions and Subscriptions Mar 18, 2017
disbursement.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
disbursement_details.go Replace *NullBool/*NullInt64 with *bool/*int and bool/int (#176) Jul 23, 2017
disbursement_integration_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
discount.go Add Discounts Nov 22, 2013
discount_gateway.go Add context.Context to exported functions that make outgoing remote c… Nov 11, 2017
discount_integration_test.go Add CurrentBillingCycle field to Modification (#236) Jun 2, 2018
dispute.go Added DisputeGateway, Disputes, etc (#231) Jun 9, 2018
dispute_evidence.go Added DisputeGateway, Disputes, etc (#231) Jun 9, 2018
dispute_gateway.go Added DisputeGateway, Disputes, etc (#231) Jun 9, 2018
dispute_integration_test.go Remove the winning and losing dispute tests (#261) Sep 26, 2018
doc.go Add context.Context to exported functions that make outgoing remote c… Nov 11, 2017
environment.go Update the API sandbox and production URLs (#169) Jun 23, 2017
environment_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
errors.go Rewrite validation errors handling (#222) May 9, 2018
errors_test.go Rewrite validation errors handling (#222) May 9, 2018
escrow_status.go Escrow Support (continued from #124) (#186) Sep 15, 2017
fake_nonces.go Add payment-method-nonce to Customer (#159) May 31, 2017
gateway_rejection_reason.go Add types to the rest of the GatewayRejectionReason constants. May 1, 2017
go.mod Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
go.sum Add go.mod and go.sum (#250) Aug 17, 2018
go_fixes_bug_5452_xml_omitempty.go Add tests for xml serializing (#271) Nov 16, 2018
hmac.go Cleanup return values of getMatchingSignature Apr 30, 2017
hmac_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
init_test.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
merchant_account.go Added Webhook Notifications Jan 30, 2014
merchant_account_gateway.go Add context.Context to exported functions that make outgoing remote c… Nov 11, 2017
merchant_account_integration_test.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
modification.go Add CurrentBillingCycle field to Modification (#236) Jun 2, 2018
modification_request.go Use structs for the XML definition instead of coding the marshaler ma… Mar 30, 2017
modification_request_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
payment_method.go Merge branch 'master' into payment-method-image-url Mar 6, 2017
payment_method_gateway.go Add context.Context to exported functions that make outgoing remote c… Nov 11, 2017
payment_method_integration_test.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
payment_method_nonce.go Intoduce 3DS support (bis repetita) (continued) (#253) Jul 31, 2018
payment_method_nonce_gateway.go Intoduce 3DS support (bis repetita) (continued) (#253) Jul 31, 2018
payment_method_nonce_integration_test.go Intoduce 3DS support (bis repetita) (continued) (#253) Jul 31, 2018
payment_method_test.go Add tests for xml serializing (#271) Nov 16, 2018
paypal_account.go Reduce the many for loops in PaymentMethods (#168) Jun 23, 2017
paypal_account_gateway.go Add context.Context to exported functions that make outgoing remote c… Nov 11, 2017
paypal_account_integration_test.go Add CustomerRequest (#212) Feb 28, 2018
paypal_details.go Add PayPalDetails to Transactions Mar 4, 2017
plan.go Replace *NullBool/*NullInt64 with *bool/*int and bool/int (#176) Jul 23, 2017
plan_gateway.go Add context.Context to exported functions that make outgoing remote c… Nov 11, 2017
plan_integration_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
processor_response_code.go Unmarshal transaction processor response code when empty Mar 30, 2017
processor_response_type.go Add ProcessorResponseType to Transaction (#273) Nov 9, 2018
response.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
search.go Add SearchPage to TransactionGateway and SubscriptionGateway (#247) Jul 20, 2018
search_test.go Allow TransactionGateway.Search to return more than 50 transactions. (#… Mar 3, 2018
settlement.go Fixed settlement batch summary unmarshaling. Apr 2, 2017
settlement_gateway.go Add context.Context to exported functions that make outgoing remote c… Nov 11, 2017
settlement_integration_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
subscription.go Add CreatedAt and UpdatedAt to Subscription (#245) Jul 5, 2018
subscription_gateway.go Add errors for paging outside of bounds Jul 20, 2018
subscription_integration_test.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
subscription_status_history.go Add StatusEvents to Subscription (#220) May 2, 2018
testing_gateway.go Add context.Context to exported functions that make outgoing remote c… Nov 11, 2017
testing_integration_test.go Change test card map to constants Jul 21, 2018
three_d_secure.go Intoduce 3DS support (bis repetita) (continued) (#253) Jul 31, 2018
transaction.go Add RefundWithRequest to TransactionGateway (#277) Nov 20, 2018
transaction_3ds_integration_test.go Intoduce 3DS support (bis repetita) (continued) (#253) Jul 31, 2018
transaction_android_pay_details_integration_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
transaction_apple_pay_details_integration_test.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
transaction_clone.go Add channel (#188) Sep 16, 2017
transaction_clone_integration_test.go Change test card map to constants Jul 21, 2018
transaction_gateway.go Add RefundWithRequest to TransactionGateway (#277) Nov 20, 2018
transaction_integration_test.go Add RefundWithRequest to TransactionGateway (#277) Nov 20, 2018
transaction_line_item.go Add transaction line items (#214) May 31, 2018
transaction_line_item_gateway.go Add transaction line items (#214) May 31, 2018
transaction_line_item_gateway_test.go Add transaction line items (#214) May 31, 2018
transaction_paypal_details_integration_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
transaction_venmo_account_details_integration_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017
venmo_account.go Remove omitempty from structs only used for deserialization (#201) Dec 23, 2017
venmo_account_details.go Add support for VenmoAccount payment methods (#163) Jun 23, 2017
version.go Bump version to v0.22.0 Nov 20, 2018
webhook_notification.go Add account updater daily report to webhooks (#260) Aug 9, 2018
webhook_notification_gateway.go Update import path to github.com/braintree-go/braintree-go (#263) Oct 17, 2018
webhook_notification_test.go Add account updater daily report to webhooks (#260) Aug 9, 2018
webhook_testing_gateway.go Tidy the WebhookTestingGateway Apr 30, 2017
webhook_testing_gateway_test.go Add build tags for unit and integration tests (#202) Dec 23, 2017

README.md

Braintree Go

GoDoc Build Status Go Report Card

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/braintree-go/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.

ctx := context.Background()
tx, err := bt.Transaction().Create(ctx, &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/braintree-go/braintree-go

Supported Go Versions

  • 1.7
  • 1.8
  • 1.9
  • 1.10
  • 1.11

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 -tags='unit integration' ./....

source .default.env
go test -tags='unit integration' ./...

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/braintree-go/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