StripeWrapper

StripeWrapper is a Wrapper around the Stripe Gem, simplifying the amount of work you need to do in order to generate charges and customers using Stripe. The main purpose of this gem is to allow you to implement an easy solution using Stripe in just a few lines of code.

Installation

Add this line to your application's Gemfile:

gem 'stripe_wrapper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install stripe_wrapper

Then execute the installer in order to generate the migrations and mount the engine

$ rails generate stripe_wrapper:install

This will copy the two core models of the Wrapper:

  1. Charges (StripeWrapper::Charge)

  2. Customers (StripeWrapper::Customer)

You can also copy all the controllers, views and models by running in order to customize the views and scaffolds as you like

$ rails generate stripe_wrapper:copy_files

Usage

After installing the gem and running the generators, using this gem is very easy. These are the steps you must follow in order to use it.

  1. You must add the main helper to your main_app's ApplicationController, as follows:
  class ApplicationController < ActionController::Base
      include StripeWrapper::StripeWrapperHelper
      #More Code
  end
  1. Go to an action where you decide to charge the customer. Here you must set the amount you're charging your customer. You can do this easily by using the following method:
    def my_cool_action
      stripe_set_amount(@amount)
    end
  1. In the corresponding view, render stripe_wrapper's partial, passing as argument the URL you desire to be redirected to after the charge is processed.
  = render partial: 'stripe_wrapper/charges/pay',locals:{redirect_url: your_cool_path}
  1. After the payment is processed, you will be redirected to the path you specified, with the charge_id param as response. Let's say you were redirected to the action payment_processed, you'd get the Charge ID like this
  def payment_processed
    charge_id = params[:charge_id]
    redirect_to root_path, notice: "Payment with ID #{charge_id} was created"
  end
  1. You can access stripe_wrapper's dashboard by going to the engine's route (by default /stripe_wrapper). You'll be able to see the scaffolds of both Charges and Customers.

Contributing

Contribution directions go here.

TODO

Tests are missing, and ideally charts are needed in both scaffolds

Development

To be more clear - this is the for when you are working on this gem. Not for when you are implementing it into your Rails app.

First, to get started, migrate and seed the database (SQLite by default):

bundle
# Create, migrate, and seed the development database with fake forum users, topics, and posts:
rake db:create db:migrate db:seed

Then, start the dummy app server:

rake dev:server

License

The gem is available as open source under the terms of the MIT License.