⚡
LightningRails
  • 👋Welcome
  • Access the Repo
  • Getting Started
    • 🚀Quickstart
    • 🎨Themes
    • 🖼️Customize the views
    • 🔮DaisyUI Library
    • ⚡Lightning Landing
      • Quickstart
      • Theme and branding
      • Page structure
      • Publish your landing page
  • Features setup
    • 📸Images & media
    • 🔐Admin Dashboard
    • Search Engine Optimization
    • 📧Automatic Emails
      • 🟨Postmark
      • 🔲Resend
    • 🚪Login with Devise
    • 🪄Magic Link Signup
    • 💳Stripe Payment Gateway
    • Github Signup
    • Lucide icons
    • 🤖Multi-provider AI
    • Open AI API
    • 🧙‍♂️Multi-Step Form Wizard
  • UI Components
    • 🦸Heros
    • ❔FAQs
    • 🃏cards
    • 💬Testimonials
    • 👋Call To Actions
    • 🔦Features
  • Deploying to production
    • ⬆️Heroku Deploy
    • 🛡️Security
      • 🎛️Rate Limiting
  • RESOURCES
    • 🚀Vote for new features
    • Report an issue
    • 🆘Get help on Slack
    • 🍭Design Resources
      • Maria Ba Illustrations
      • Assets Mockup Generator
      • Logo Generator
      • Tailwind Cheatsheet
      • HyperUI Tailwind Library
Powered by GitBook
On this page
  • Stripe setup
  • Create account
  • Install stripe CLI in your terminal
  • API keys and webhook secrets
  • Pay gem
  • Set your pricing
  • Premium Authorisation

Was this helpful?

  1. Features setup

Stripe Payment Gateway

PreviousMagic Link SignupNextGithub Signup

Last updated 7 months ago

Was this helpful?

Stripe setup

The boilerplate comes by default with Single payments stripe checkout. We are working on adding subscriptions, in the meantime, you can modify the existing checkout controller with a few lines to activate subscriptions.

We use stripe checkout and pay gem for easy paywall setup and webhooks. To start using Stripe follow this guide:

Create account

Go to and create an account.

Install stripe CLI in your terminal

For us to listen to stripe webhooks and test in development, we need to install stripe CLI in our terminal:

For macOS:

brew install stripe/stripe-cli/stripe

Or for Ubuntu, check the

Then login:

stripe login -i

This should ask you for an API key, you will find it in > Secret Key

API keys and webhook secrets

Start listening to your webhook events by running in your terminal:

stripe listen --forward-to localhost:3000/pay/webhooks/stripe

Add the API Keys in the Rails credentials file. Open the file from the terminal with the following line:

EDITOR="code --wait" rails credentials:edit

Add the keys in the file with this exact wording for the keys and save:

Pay gem

  • Go to application.rb and replace the example domain with your domain so Pay can generate links (for features like Stripe Checkout).

  • Create a product on the stripe product catalog, copy the product ID, and paste it on the checkouts_controller.rb action Show:

# controllers/checkouts_controller.rb

  def show
    current_user.set_payment_processor :stripe
    current_user.payment_processor.customer

    @checkout_session = current_user.payment_processor.checkout(
      mode: 'payment',
      line_items: 'price_1JZ9J3J9jgZ2Qj5vz1ZzZzZz',
      success_url: checkout_success_url
    )
  end

Set your pricing

Now that you have created your product on Stripe, ensure all the UI has the correct pricing, and modify the price on the _price_cards.rb component.

Premium Authorisation

Hide your premium features behind the paywall by adding the following line in the premium controllers/actions

class MyPremiumController < ApplicationController
before_action :verify_premium, only: [:some_action]

[...]

def verify_premium
   unless current_user.premium? # This is an instance method in the user.rb model
     flash[:notice] = "Go premium to access this feature"
     redirect_to checkout_path
   end
end

This webhook comes by default with the pay gem. If you wish to create custom webhooks refer to the documentation.

All the setup is taken care of by LightningRails, the only setup needed from your side to get the gem to work is:

💳
Stripe
official documentation.
Test > Developers > API Keys
Pay Gem
Pay Gem
Credentials Edit file