ryanwold.net

A civic-minded citizen seeking the singularity

An entry

Using Stripe for Payments

Date: 2015-11-07
Status: release
Tags: api payments ruby javascript

Recently, I built a feature in a Rails web application to take payments for an annual subscription service. There are many options for accepting credit card payments available. I was encouraged by a colleague to consider using Stripe.

A day later, I was happy I did. Able to accept payments in a PCI compliant way, the feature was quite a pleasure to build.

I found these resources particularly helpful:

A rundown of how it works.

  • Use a basic html form and add data-stripe=attributes for Credit Card, Expiration Month and Year, and CVC number
  • Use jQuery to handle the form submission instead of the browser's default form handling
  • In the browser, use Stripe.js to generate a one-time use token from the 4 credit card fields (the library provides methods for it)
  • Send the one-time use token from the browser to your Server. I used jQuery's $.ajax function
  • From your Server, send the token to Stripe using stripe-ruby .gem, and create either a Customer or a Charge
  • A Customer object will have an ID that you can store and re-bill at a later date