• Stars
    star
    430
  • Rank 97,305 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 14 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Braintree Ruby library

Braintree Ruby library

The Braintree gem provides integration access to the Braintree Gateway.

Please Note

The Payment Card Industry (PCI) Council has mandated that early versions of TLS be retired from service. All organizations that handle credit card information are required to comply with this standard. As part of this obligation, Braintree is updating its services to require TLS 1.2 for all HTTPS connections. Braintree will also require HTTP/1.1 for all connections. Please see our technical documentation for more information.

Installation

gem install braintree

Or add to your Gemfile:

gem 'braintree'

Optionally, you may also include LibXML for more performant XML parsing. If LibXML is not present, REXML will be used instead.

gem 'libxml-ruby'

Dependencies

  • builder

The Braintree Ruby SDK is tested against Ruby versions 2.6, 2.7 and 3.0.

The Ruby core development community has released End-of-Life branches for Ruby versions lower than 2.6, which are no longer receiving security updates. As a result, Braintree no longer supports these versions of Ruby. We have updated our gem specifications to reflect these updates.

Versions

Braintree employs a deprecation policy for our SDKs. For more information on the statuses of an SDK check our developer docs. Minimum supported versions are also available in our developer docs.

Major version number Status Released Deprecated Unsupported
4.x.x Active May 2021 TBA TBA
3.x.x Deprecated October 2020 May 2023 May 2024
2.x.x Deprecated April 2010 October 2022 October 2023

Documentation

Updating from an Inactive, Deprecated, or Unsupported version of this SDK? Check our Migration Guide for tips.

Quick Start Example

require "rubygems"
require "braintree"

gateway = Braintree::Gateway.new(
  :environment => :sandbox,
  :merchant_id => "your_merchant_id",
  :public_key => "your_public_key",
  :private_key => "your_private_key",
)

result = gateway.transaction.sale(
  :amount => "1000.00",
  :payment_method_nonce => nonce_from_the_client,
  :options => {
    :submit_for_settlement => true
  }
)

if result.success?
  puts "success!: #{result.transaction.id}"
elsif result.transaction
  puts "Error processing transaction:"
  puts "  code: #{result.transaction.processor_response_code}"
  puts "  text: #{result.transaction.processor_response_text}"
else
  p result.errors
end

You retrieve your merchant_id, public_key, and private_key when signing up for Braintree. Signing up for a sandbox account is easy, free, and instant.

Bang Methods

Most methods have a bang and a non-bang version (e.g. gateway.customer.create and gateway.customer.create!). The non-bang version will either return a SuccessfulResult or an ErrorResult. The bang version will either return the created or updated resource, or it will raise a ValidationsFailed exception.

Example of using non-bang method:

result = gateway.customer.create(:first_name => "Josh")
if result.success?
  puts "Created customer #{result.customer.id}"
else
  puts "Validations failed"
  result.errors.for(:customer).each do |error|
    puts error.message
  end
end

Example of using bang method:

begin
  customer = gateway.customer.create!(:first_name => "Josh")
  puts "Created customer #{customer.id}"
rescue Braintree::ValidationsFailed
  puts "Validations failed"
end

We recommend using the bang methods when you assume that the data is valid and do not expect validations to fail. Otherwise, we recommend using the non-bang methods.

Developing (Docker)

The Makefile and Dockerfile will build an image containing the dependencies and drop you to a terminal where you can run tests.

make

Linting

The Rakefile includes commands to run Rubocop. To run the linter commands use rake: rake lint.

Tests

The unit specs can be run by anyone on any system, but the integration specs are meant to be run against a local development server of our gateway code. These integration specs are not meant for public consumption and will likely fail if run on your system. To run unit tests use rake: rake test:unit.

Suppress Braintree Logs

To suppress logs from Braintree on environments where they are considered noise (e.g. test) use the following configuration:

logger = Logger.new("/dev/null")
logger.level = Logger::INFO
gateway.config.logger = logger

License

See the LICENSE file for more info.

More Repositories

1

manners

A polite Go HTTP server that shuts down gracefully.
Go
987
star
2

credit-card-type

A library for determining credit card type
TypeScript
916
star
3

card-validator

Validate credit cards as users type.
TypeScript
822
star
4

runbook

A framework for gradual system automation
Ruby
700
star
5

braintree_ios

Braintree SDK for iOS
Swift
542
star
6

braintree_php

Braintree PHP library
PHP
535
star
7

braintree_android

Braintree SDK for Android
Java
402
star
8

android-card-form

A ready-made card form layout that can be included in your Android app, making it easy to accept credit and debit cards.
Java
360
star
9

curator

Model and repository framework
Ruby
354
star
10

braintree_node

Braintree Node.js library
JavaScript
325
star
11

sanitize-url

TypeScript
253
star
12

braintree_python

Braintree Python library
Python
235
star
13

pg_ha_migrations

Enforces DDL/migration safety in Ruby on Rails project with an emphasis on explicitly choosing trade-offs and avoiding unnecessary magic.
Ruby
182
star
14

braintree_express_example

An example Braintree integration for Express
CSS
175
star
15

jsdoc-template

A clean, responsive documentation template with search and navigation highlighting for JSDoc 3
CSS
172
star
16

framebus

A message bus that operates across iframes
TypeScript
150
star
17

braintree_java

Braintree Java library
Java
147
star
18

braintree_dotnet

Braintree .NET library
C#
132
star
19

braintree_php_example

An example Braintree integration for PHP
CSS
124
star
20

braintree-android-drop-in

Braintree Drop-In SDK for Android
Java
118
star
21

braintree_flask_example

An example Braintree integration for Flask
CSS
103
star
22

braintree-ios-drop-in

Braintree Drop-in for iOS
Objective-C
97
star
23

braintree_rails_example

An example Braintree integration for Ruby on Rails
HTML
85
star
24

braintree_spring_example

An example Braintree integration for Spring (Java)
CSS
80
star
25

braintree-encryption.js

Javascript Library for Client-side Encryption with Braintree
JavaScript
77
star
26

pg_column_byte_packer

Auto-order table columns for optimize disk space usage
Ruby
71
star
27

restricted-input

Restrict <input>s to certain valid characters (e.g. formatting phone or card numbers)
TypeScript
64
star
28

browser-detection

A utility for detecting browsers in Braintree libs.
TypeScript
60
star
29

braintree_aspnet_example

An example Braintree integration in the ASP.NET framework
CSS
59
star
30

graphql-api

Schemas, changelogs and feature requests for Braintree's GraphQL API
57
star
31

mallory

Reverse proxy for HTTPS services, with SSL verification.
Python
57
star
32

us-bank-account-validator

A library for validating US bank account routing and account numbers
TypeScript
51
star
33

popup-bridge-android

PopupBridge allows WebViews to open popup windows in a browser and send data back to the WebView
Java
49
star
34

popup-bridge-ios

Enable your web view to open pages in a Safari View Controller
Swift
32
star
35

litmus_paper

Backend health tester for HA Services
Ruby
32
star
36

open_api_parser

A parser for Open API specifications
Ruby
30
star
37

big_brother

a daemon to monitor and administer servers in a LVS cluster of load balanced virtual servers
Ruby
28
star
38

mysql_to_postgresql

ruby script which migrates data from a MySQL database to PostgreSQL
Ruby
26
star
39

fake-wallet-app-ios

A fake version of the {PayPal,Venmo} Wallet for development
Objective-C
25
star
40

braintree_android_encryption

braintree_android_encryption
Java
24
star
41

browser-switch-android

Open a url in a browser or Chrome Custom Tab and receive a response as the result of user interaction.
Java
23
star
42

braintree_slim_example

An example Braintree integration for Slim (PHP)
CSS
22
star
43

form-napper

Hijack, submit, and inject data into forms.
JavaScript
21
star
44

braintree_perl

Braintree Perl library
Perl
18
star
45

braintree-auth-example

A Ruby/Sinatra application that demonstrates the Braintree Auth API
JavaScript
17
star
46

curator_rails_example

Example Rails application for curator
Ruby
16
star
47

activerecord-postgresql-citext

citext support for rails 4
Ruby
15
star
48

braintreehttp_php

PHP
15
star
49

wrap-promise

Small module to help support APIs that return a promise or use a callback.
TypeScript
15
star
50

iframer

Create consistent iframes
TypeScript
14
star
51

mallorca

Man-in-the-middle proxying for HTTPS.
JavaScript
14
star
52

braintree_graphql_rails_example

An example Braintree integration with the GraphQL API using Ruby on Rails
HTML
14
star
53

inject-stylesheet

Create a <style> element with CSS properties, filtering input using an allowlist or blocklist.
TypeScript
14
star
54

apollo-tracing-uploader-java

Upload Java GraphQL tracing metrics to Apollo Graph Manager
Java
13
star
55

braintree_client_side_encryption

javascript library for client-side encryption with braintree
JavaScript
13
star
56

braintree-ios-visa-checkout

Visa Checkout component for our Braintree iOS SDK
Objective-C
9
star
57

braintree_android_encryption_examples

Java
8
star
58

braintree-web-bower

JavaScript
8
star
59

braintree-android-visa-checkout

Visa Checkout component for our Braintree Android SDK
Java
7
star
60

spidersuite

Configurable crawler and reporting tool for verifying websites
JavaScript
6
star
61

eslint-config

Shared linting configuration for braintree js projects
TypeScript
5
star
62

qsagi

A friendly way to talk to RabbitMQ
Ruby
5
star
63

braintree-types

TypeScript definitions for Braintree Custom Actions
TypeScript
4
star
64

heckler

Heckler's aim is to allow you to correlate code changes with Puppet noop output!
Go
4
star
65

braintree.github.io

Braintree open source website
HTML
3
star
66

braintreehttp_java

Java
3
star
67

event-emitter

A simple JS based event emitter
TypeScript
3
star
68

asset-loader

A module to load frontend assets.
TypeScript
3
star
69

braintreehttp_python

Python
3
star
70

braintreehttp_ruby

Ruby
2
star
71

braintree_windows_phone_encryption

.net library for client-side encryption with braintree
C#
2
star
72

custom-actions-docs

⚠️ These docs have moved to Gitbook!
2
star
73

class-list

A helper for applying classes to dom nodes.
TypeScript
2
star
74

fluent-plugin-s3

Ruby
2
star
75

braintree-android-samsung-pay

Samsung Pay component for our Braintree Android SDK
Java
2
star
76

braintreehttp_node

JavaScript
1
star
77

braintree-web-drop-in-bower

Braintree Drop-in for the web
JavaScript
1
star
78

webhint-configuration-braintree-sdk

Beta Webhint configuration for Braintree's sdk-related packages
1
star
79

destructor

TypeScript
1
star
80

extended-promise

TypeScript
1
star
81

braintree_windows_phone_encryption_examples

C#
1
star
82

credit-card-form

Name TBD
1
star
83

popup-bridge-example

Example site for Popup Bridge mobile library
HTML
1
star
84

uuid

A simple node js implementation of uuid v4 for use with Braintree's JS based SDKs.
JavaScript
1
star