An example Rails 4.2 app with Stripe and the Payola gem for a membership or subscription site.
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:
This is a complex application. To understand the code, you'll need the tutorial.
The application uses:
Other tutorials may be helpful:
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:
Additionally:
h2. What Is Not Here
There are additional features you may want for a SaaS application, such as:
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:
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
No open issues yet, or sync has not completed.