Braintree via Redline: riding the rails
Redline helps you with Braintree on Rails, it automatically makes creation/deletion/update scripts for your model, translating and syncing them with a Braintree customer profile. In the future I plan to increase the capabilities with helpers for Braintree models and light-weight subscription support, perhaps using Braintree's reoccurring billing.
Set up the gem dependancies in environment.rb:
config.gem 'braintree' config.gem 'redline'
Run your install task:
$ rake gems:install
Configure Braintree normally in an initializer:
Braintree::Configuration.environment = CONFIG[:braintree][:environment].to_sym Braintree::Configuration.merchant_id = CONFIG[:braintree][:merchant_id] Braintree::Configuration.public_key = CONFIG[:braintree][:public_key] Braintree::Configuration.private_key = CONFIG[:braintree][:private_key]
Add acts_as_braintree_customer and a column customer_id:integer to a model of your choice:
add_column :users, :customer_id, :integer Class User < ActiveRecord::Base acts_as_braintree_customer end
Example and configuration
acts_as_braintree_customer takes an optional series of attributes that represent an attribute mapper
class User < ActiveRecord::Base acts_as_braintree_customer :business_name => :company, :firstname => :first_name, :lastname => :last_name attr_accessible :firstname, :lastname, :website, :email, :business_name, :password, :password_confirmation end james = User.find(1) #=> <User id: 1, firstname: "James", lastname: "Daniels", business_name: "MarginLeft, LLC", email: 'email@example.com', website: 'http://www.marginleft.com', crypted_password: "45fres8...", persistence_token: "4jsdf88...", ...> james.customer #=> <Braintree::Customer id: "9999999", first_name: "James", last_name: "Daniels", company: "MarginLeft, LLC", email: "firstname.lastname@example.org", website: "http://www.marginleft.com", ..., addresses: , credit_cards: >
More to come.
Note on Patches/Pull Requests
Fork the project.
Make your feature addition or bug fix.
Add tests for it. This is important so I don't break it in a future version unintentionally.
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
Send me a pull request. Bonus points for topic branches.
Copyright © 2010 MarginLeft, LLC. See LICENSE for details.