Monetize your Side Hustle with Stripe’s API for Rails

Project setup

  1. Install the Stripe Ruby gem. After adding the following to your Gemfile, run ‘bundle’ in your terminal.

Server code

  • Stripe recognizes 7 different payment methods. Learn more about them here
  • Within the line_items object, you can define product information when you create the Checkout Session with price_data or alternatively use pre-defined prices and pass their IDs.
  • Checkout has three modes: payment, subscription, or setup. Payment is for one-time purchases, and what we’re demonstrating here.

Client code

  • Note that in the code above, one’s able to specify URLs for success and cancel pages, but this can also be handled within the same URL (examples below from Stripe for multiple URLs)

TLDR: Adds a success page — Creates a success page for the URL you provided as the Checkout Session success_url to display order confirmation messaging or order details to your customer.

TLDR: Adds a canceled page — Adds another page for cancel_url. Stripe redirects to this page when the customer clicks the back button in Checkout.

TLDR: Adds an order preview page — Allows the customer to review or modify their order — once a customer is sent to the Checkout page, the order is final.

Almost there!!!

  • Payment succeeds — 4242 4242 4242 4242
  • Payment requires authentication — 4000 0025 0000 3155
  • Payment is declined — 4000 0000 0000 9995

Demo below to see the final product




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

🇸🇪 Swedish fluency bits #10

Convert Input Image to JPG, JPEG Format in Python

Elixir Learnings: Log Early!

7 Ways to Earn Money From Coding and Programming

[Learning]#30 Final: Had Fun Learning JavaScript?

Rotate Linked List

Cost of an Error: Who Pays for Programming Blunders?

Date command and it’s options

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brittani Élan Taylor

Brittani Élan Taylor

More from Medium

Writing, Accessing, and Modifying Nested APIs with Ruby & Sinatra

How to get & build full URLs in Rails

My Ruby Wrap-up

Building a Shopify App with Ruby on Rails in a day