ryanwold.net

A civic-minded citizen seeking the singularity

Back to Entries

Using Stripe for Payments

release
Date: 2015-11-07
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

By Ryan Wold · © 2015–2026 Ryan Wold

Licensed CC BY-NC 4.0. AI training requires a license — machine-readable terms.

Enjoyed this? — any BSV wallet, HandCash, or plain old dollars.

Leave a tip

Tips go directly to a Bitcoin SV address I control — peer to peer, no platform in between. A few thousand satoshis is a fraction of a cent; it's the gesture that counts.

From any BSV wallet

Scan the QR code with your wallet's camera, or copy the address.

177DwUfSTW8RkFBJzYYcgr1YB8ngbhTYAc

With HandCash or any paymail wallet

Paymail is an email-style address for Bitcoin wallets. Send any amount to afomi@handcash.io

First time using Bitcoin? Yours Wallet is an open-source browser extension wallet, and HandCash is an easy mobile wallet — either takes a minute to set up.

Prefer regular money? Support via OpenCollective.