Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rails-stripe-membership-saas

> 编程语言
Open source

An example Rails 4.2 app with Stripe and the Payola gem for a membership or subscription site.

1.1K stars0 likes2 views
WebsiteGitHub

About

An example Rails 4.2 app with Stripe and the Payola gem for a membership or subscription site.

h1. !http://railsapps.github.io/images/rails-36x36.jpg(Rails Application for a Membership, Subscription, or SaaS Site)! Membership Site with Stripe

Rails 4.2 example application demonstrates how to use "Stripe":https://stripe.com/ and the "Payola":https://www.payola.io/ gem for a Rails membership site, subscription site, or SaaS site (software-as-a-service). Use this example application as a starter app for your own web applications.

This application replaces a very popular Rails 3.2 implementation, available in a "Rails 3.2 branch":https://github.com/RailsApps/rails-stripe-membership-saas/tree/rails3.2, and now uses the "Payola":https://www.payola.io/ gem.

!http://railsapps.github.io/images/join/join-railsapps.png(Join the RailsApps Project)!:http://railsapps.github.io/

See the tutorial for a complete explanation of the code:

  • "Membership Site with Stripe":https://tutorials.railsapps.org/rails-stripe-membership-saas

This is a complex application. To understand the code, you'll need the tutorial.

The application uses:

  • "Payola":https://www.payola.io/ for Stripe integration with Rails
  • "Stripe":https://stripe.com/ for credit card payment processing
  • "Devise":https://github.com/plataformatec/devise for user management and authentication
  • "Role-Based Authorization":http://railsapps.github.io/rails-devise-roles for administrator access
  • "Bootstrap":http://getbootstrap.com/ front-end framework

Other tutorials may be helpful:

  • "Signup and Download":https://tutorials.railsapps.org/rails-signup-download
  • "Role-Based Authorization":http://railsapps.github.io/rails-devise-roles
  • "Devise Tutorial":http://railsapps.github.io/rails-devise/
  • "RSpec Tutorial":http://railsapps.github.io/rspec.html

You can build this application in only a few minutes using the "Rails Composer":http://railsapps.github.io/rails-composer/ tool.

!http://railsapps.github.io/images/rails-stripe-membership-saas.png(Rails Application for a Membership, Subscription, or SaaS Site)!

h4. From the RailsApps Project

The "RailsApps":http://railsapps.github.io/ open source project offers starter applications and tutorials for Rails developers. Generate the applications with the Rails Composer tool.

All the code is explained in the Capstone Rails Tutorials. You can purchase the "Capstone Rails Tutorials":https://tutorials.railsapps.org/ to support the project.

h4. If You Are New to Rails

If you're new to Rails, see "What is Ruby on Rails?":http://railsapps.github.io/what-is-ruby-rails.html, the book "Learn Ruby on Rails":http://learn-rails.com/learn-ruby-on-rails.html, and recommendations for a "Rails tutorial":https://tutorials.railsapps.org/rails-tutorial.

h4. Database

The application requires a database. The example application uses SQLite with Rails ActiveRecord. You can easily substitute PostgreSQL, MySQL, or other databases.

h4. Front-end Framework

The example application integrates Bootstrap for a navigation bar and flash messages. The forms are set up to use Bootstrap. You can customize the application to use other front-end frameworks such as Zurb Foundation.

h2. What's Here

Stripe offers two approaches to implementing payment processing. "Stripe Checkout":https://stripe.com/checkout is Stripe’s entry-level approach. Stripe Checkout competes with the button-based payment options from Google, PayPal, or Amazon, adding a pop-up payment form to any web page. Stripe Checkout is very limited because the pop-up payment form cannot be customized for use with a Rails application. Our "Stripe Checkout Tutorial":https://tutorials.railsapps.org/tutorials/rails-stripe-checkout shows how to combine Stripe Checkout with Devise for simple applications.

"Stripe.js":https://stripe.com/docs/stripe.js is optimal for use with a Rails application, allowing full customization of a payment form and integration with Rails form processing. The "rails-stripe-coupons":https://github.com/RailsApps/rails-stripe-coupons starter application implements a payment feature using Stripe JS so a visitor pays to download a PDF file. The application accommodates promotional coupons and adds payment forms to landing pages, for real-world payment processing.

This example application, "rails-stripe-membership-saas":https://github.com/RailsApps/rails-stripe-membership-saas, provides subscription billing using Stripe and the Payola gem.

The application offers these features:

  • tiered pricing for multiple subscription plans
  • optional "free trial" subscription as well as free accounts using Stripe
  • uses Stripe for no local credit card storage
  • Stripe accepts credit card payments from customers in any country or currency
  • PCI compliance using the Stripe JavaScript library
  • Stripe handles recurring billing, retries if payment fails, and cancels subscription if retries fail
  • paid subscriptions are created only after a successful credit card transaction
  • subscribers can upgrade or downgrade subscription plans
  • subscribers can cancel subscription plans

Additionally:

  • background processing adds the email address to a mailing list
  • background processing completes payment for a speedy response

h2. What Is Not Here

There are additional features you may want for a SaaS application, such as:

  • Basecamp-style subdomains (each user gets their own subdomain)
  • "multitenancy":http://en.wikipedia.org/wiki/Multitenancy database segmentation

These features are not included in this application. For multitenancy, try Brad Robertson's "Apartment":https://github.com/bradrobertson/apartment gem.

h2. Similar Examples and Tutorials

This is one in a series of Rails example apps and tutorials from the "RailsApps Project":http://railsapps.github.io/. See a list of additional "Rails examples, tutorials, and starter apps":http://railsapps.github.io/rails-examples-tutorials.html. Related example applications may be useful:

  • "Learn Rails":https://github.com/RailsApps/learn-rails companion to the book "Learn Ruby on Rails":http://learn-rails.com/learn-ruby-on-rails.html
  • "Foundation and Rails":http://railsapps.github.io/rails-foundation/ shows how to integrate Foundation
  • "Bootstrap and Rails":http://railsapps.github.io/rails-bootstrap/ shows to integrate Bootstrap
  • "Mailing Lists with Active Job":https://tutorials.railsapps.org/rails-mailinglist-activejob for MailChimp subscriptions
  • "OmniAuth and Rails":https://github.com/RailsApps/rails-omniauth uses OmniAuth for authentication
  • "Devise and Rails":https://github.com/RailsApps/rails-devise uses Devise for authentication
  • "Role-Based Authorization":http://railsapps.github.io/rails-devise-roles using simple roles
  • "Pundit and Rails":https://github.com/RailsApps/rails-devise-pundit uses Pundit for authorization
  • "Signup and Download":https://tutorials.railsapps.org/rails-signup-download combines authentication with authorization and a PDF download
  • "Stripe Checkout":https://tutorials.railsapps.org/rails-stripe-checkout/
  • "Stripe JS With Coupons":https://tutorials.railsapps.org/rails-stripe-coupons/

h2. Accounts You Will Need

Get the accounts you will need before deploying the application.

h3. Email

Devise provides a "Forgot Password?" feature that resets a password and sends instructions to the user. You'll need an email service provider to send email from the application. You can use "Gmail":https://accounts.google.com/SignUp?service=mail during development. You can get a free "Gmail":https://accounts.google.com/SignUp?service=mail account if you don't already have one. For production, Gmail is not robust. Use transactional email services, such as "Mandrill":http://mandrill.com/, to send email in production. See the article "Send Email with Rails":http://railsapps.github.io/rails-send-email.html for more information.

h3. Stripe

A "Stripe":https://stripe.com/ account is required. Before you start, go to the "Stripe website":https://stripe.com/ and set up an account. You don’t need a credit card merchant account or payment gateway. There’s no approval process to delay getting started.

h3. Merchant Account

Your business will need a merchant account in order to accept credit card payments. If you already have a merchant account, you can use it with Stripe. Stripe provides a merchant account as part of its service, so you don't need to obtain one.

h3. MailChimp

A "MailChimp":http://mailchimp.com account is optional. The application User model includes a method to subscribe a new user to a MailChimp mailing list when an account is created. If you choose to use this feature, you'll need a MailChimp account.

When visitors submit an email address, the application will add them to a MailChimp list. To access MailChimp, we’ll need a MailChimp API key. "Log in to MailChimp"https://admin.mailchimp.com/ to get your API key. Click your name at the top of the navigation menu, then click "Account". Click "Extras," then "API keys." You have to generate an API key; MailChimp doesn’t create one automatically.

You’ll also need to create a MailChimp mailing list. The MailChimp "Lists" page has a button for "Create List." The list name and other details are up to you. We’ll need the MAILCHIMP_LIST_ID for the mailing list you’ve created. To find the list ID, on the MailChimp "Lists" page, click the "down arrow" for a menu and click "Settings." At the bottom of the "List Settings" page, you’ll find the unique ID for the mailing list.

With MailChimp, you can send a welcome message automatically when the visitor signs up for the mailing list. Use the welcome message to inform the visitor that they've successfully subscribed to the mailing list. It’s a bit difficult to find the MailChimp option to create a welcome message. Strangely, MailChimp considers a welcome message a "form." Here's how to find it. On the MailChimp "Lists" page, click the "down arrow" for a list and click "Signup forms." Then click "General forms." On the "Create Forms" page, there is a drop-down list of "Forms & Response Emails." The gray box shows "Signup form." Click the down arrow. Select the menu item named "Final 'Welcome' Email" and you'll be able to create a welcome message.

h3. Hosting

We provide instructions to deploy the application to "Heroku":https://www.heroku.com/ which provides Rails application hosting. It costs nothing to set up a Heroku account and deploy as many applications as you want. To deploy an app to Heroku, you must have a Heroku account. Visit Heroku "to set up an account":https://id.heroku.com/signup/devcenter.

h3. SSL

Visitors to your website will be sending credit card information from their browser to Stripe’s servers when they sign up for a subscription. The Stripe JavaScript library will open an SSL connection to Stripe’s servers when the form is submitted. You can host your site without SSL and your users’ credit card numbers will be protected on the way to Stripe’s servers. However, your security-conscious visitors will be uneasy if they see that the web URL for your registration page begins with @http://@ and not @https://@ (indicating an SSL connection). For their peace of mind (and the higher conversion rate that comes with trust), you should host your website with an SSL connection. Additionally, as a general practice, it is wise to host any webapp that requires login over an SSL connection.

If you’re deploying with Heroku, you can access any Heroku app over SSL at https://myapp.herokuapp.com/. Setting up an SSL certificate for a custom domain on Heroku can be a hassle but there’s a convenient alternative that is a better value. You can use "CloudFlare":http://cloudflare.com/ to get free SSL without purchasing or installing an SSL certificate. CloudFlare is a content delivery network (CDN) and website optimizer; their free plan includes "SSL":https://www.cloudflare.com/ssl. See the article "Configuring CloudFlare DNS for a Heroku App":http://www.higherorderheroku.com/articles/cloudflare-dns-heroku/. If you’re deploying on Heroku, you can wait until you’ve deployed to

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言