Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .idea
Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 db
Octocat-spinner-32 lib
Octocat-spinner-32 script
Octocat-spinner-32 test
Octocat-spinner-32 .DS_Store
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 stripe_rails.gemspec
README.textile

StripeRails

Stripe Rails was built on top of the official stripe gem to bring ease of use of stripe in your models. The gem also caches the stripe customer response so that if you often use it to check a customers subscription status, it wont have to reach the stripe API on every page load. Lastly, this gem has built in responses for stripe webhooks/callbacks.

Installation

Add the following to your gemfile and run bundle install.

gem 'stripe_rails'

Compatibility

The gem works with rails 3.2.x and mongoid and active:record when using model relationships. It uses rails cache to cache the stripe object for 1 hour on subsequent get requests.

Usage

Models

Stripe Rails is easily used in your model and some configuration can be added to provide some additional functionality.

1. First, add the following module to your model. This will automatically create the stripe customer when a new model instance is created. Future functionality will be provided to add old models to stripe via a rake task, or you can do this manually by calling: MyModel.stripe.create_customer

class MyModel
    include Mongoid::Document
    include StripeRails::ActsLikeCustomer
    ...
end

2. Secondly some configuration can be added to the model to add some additional functionality

class MyModel
    include Mongoid::Document
    include StripeRails::ActsLikeCustomer

    stripe_description :title                           # allows you to provide a method to tell stripe a description for the customer.
    stripe_subscription_plan :monthly_subscription      # will automatically add the customer to the subscription.
    stripe_unit_price 45                                # allows the usage of a per unit price which can be used later in callbacks.
    stripe_units :users                                 # specifies the units to be counted for per unit pricing.

    ...
end

Callbacks

Stripe rails provides a generator that will create a callback in your main application. Use:

    rails g stripe_callback charge.succeeded

**Note: A list of callbacks can be found in stripes API documentation.

This will generate a file like this:

class ChargeSucceededCallback < StripeRails::Callback

  # Some logic to process during the callback
  def actions

    # The response hash
    @response = {success: true}

  end

end

if you choose to send a response it must be set in the actions method with the instance variable of response. It will expect a hash that will be later be converted into JSON to give back to stripe.

Unused callbacks

Unused callbacks will respond with the proper 501 (Not Implemented) response.

How to contribute

  • Fork the project on Github
  • Create a topic branch for your changes
  • Ensure that you provide test coverage for your changes
  • Ensure that all tests pass (`bundle exec rake`)
  • Create a pull request on Github

Project Info

StripeRails was created by Jason Waldrip

The project is hosted on Github: http://github.com/jwaldrip/stripe_rails, where your contributions, forkings, comments, issues and feedback are greatly welcomed.

Copyright © 2012 Jason Waldrip, released under the MIT license.

More to documentation to come in the next versions!

Something went wrong with that request. Please try again.