Stripe Payments in Rails

Will Holcomb

12 June 2013


Stripe is an online credit card processing service. Stripe charges 2.9% + 30ยข per charge. One of the primary advantages of Stripe is card verification takes place in the browser so the only information stored on the server is authentication tokens.

Quick Start

A sample of the application is running at


First, sign up for a Stripe account. Under the "Your Account" menu in the upper right hand corner select "Account Settings." From there choose "API Keys" and this will give you the keys for accessing your account. Save these in an initializer:


Using environment variables for your keys allows you to avoid recording them on disk. To specify them when starting a server do:

STRIPE_SECRET_KEY=sk_test_… rails s

Next, include the javascript in your application and add error notifications.


Next add the appropriate gems for authentication and Stripe.


After running bundle install the gems are installed. Next we run the following commands to set up the payments model.

This generates the product views. We begin by editing the payment form. This payment form includes saved card info.


Next we add javascript tp the page to handle authenticating cards.


Finally is the controller to handle the charge creation logic.