Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Syncs your AR models with Braintree (Payment Gateway) and offers a lightweight reoccurring billing script

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.textile

RedLine

Braintree via Redline: riding the rails

Redline helps you with Braintree on Rails, it automatically makes customer creation/deletion/update scripts for your model, translating and syncing them with a Braintree customer profile.
Redline also includes a lightweight manual subscription billing system, if you desire that functionality.

Please note: this repository may be a prerelease version, please read the README of the version you have installed.

Heads up

This software is delivered “as is” without warranty. As with any piece of code, please study it if you include it in your project, especially for such a critical component of your application.

While I believe the tests cover the code well, there may be certain cases that I have not experienced or predicted. This is a manual billing script, so dreadful things may occur; please help out and add to the tests if you see, or god forbid experience, any problems.

It is my intention to convert to gateway handled subscriptions, once Braintree adds this functionality to their gem.

Getting started

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 and add the following magic columns to a model of your choice (e.g, User):

  add_column :users, :customer_id,      :integer  # Required
  
  add_column :users, :subscription_key, :string   # Required if User has_a_subscription
  add_column :users, :paid_until,       :date     # Required if User has_a_subscription
  add_column :users, :trial_until,      :date     # Required if User has_a_subscription and trial length is greater than 0.days

And the following definition calls:

  class User < ActiveRecord::Base
  
    has_a_braintree_customer
  
    has_a_subscription do
      plans :mild => {:price => 0.00}, :medium => {:price => 5.00}, :spicy => {:price => 10.00}
    end
  
  end

And then run this daily:

  User.run_billing!

More advanced configuration

If you don’t like the default settings or your user needs a field mapping, you can override many assumptions RedLine makes:

  class User < ActiveRecord::Base
    has_a_braintree_customer do
      attribute_map :first_name => :firstname, :last_name => :lastname
      custom_fields :ip_address, :tax_id
    end

    has_a_subscription do
      plans :mild => {:price => 0.00}, :medium => {:price => 5.00}, :spicy => {:price => 10.00}
      default_plan :medium
      billing_frequency 30.days, :grace_period => 7.days
      free_trial 30.days, :reminder => 7.days
    end
  end

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

Copyright © 2010 MarginLeft, LLC. See LICENSE for details.

Something went wrong with that request. Please try again.