KISO Docs

Subscriptions Quickstart

#Overview

In this tutorial, we're going to quickly use Rails' scaffolding to generate a User model that you might have in a typical app. Then we'll attache Stipe Subscriptions to it.
Note: we deliberately simplify this example by setting the KISO Stripe Payments Admin authenticator to a simple true statement - do note deploy this to production!
  1. Install kiso_stripe_payments
  2. Run the kiso_stripe_payments:install generator
  3. bin/rails g scaffold user name:string email:string
  4. bin/rails db:migrate
  5. bin/rails g kiso_stripe_payments:install_subscriptions user
  6. bin/rails db:migrate
  7. Set the environment variables for STRIPE_SECRET_KEY, STRIPE_PUBLISHABLE_KEY and STRIPE_WEBHOOK_SIGNING_SECRET
  8. Configure the KISO Stripe Payments engine in config/initializers/kiso_stripe_payments_subscriptions.rb and set the admin_authenticator to just return true, and the layout to use sidenav layout:
config.admin_authenticator = lambda { |request, session| true }
config.layout = 'sidenav'
config.subscription_owner_creation_path = 'new_user'
  1. Use the KISO Themes generator kiso_themes:landing_pages home index to generate a basic landing page
  2. Add a root route to routes.rb: root to: 'home#index'
  3. You should be able to hit the KISO Stripe Payments admin at http://localhost:3000/kiso_stripe_payments/admin/subscriptions
  4. Now create a new Stripe product at http://localhost:3000/kiso_stripe_payments/admin/products
  5. Now create some Stripe plans and attach them to the Stripe Product you just created at: http://localhost:3000/kiso_stripe_payments/admin/plans
  6. Once you have created some plans, go back to the stripe product, and click Sync. This will create the product with Stripe and upload your stripe plans as well. You'll also want to click 'Activate' so that the Product is selectable.
  7. Now if you visit http://localhost:3000/plans you'll see the Plans page has auto populated based on the Stripe plans you created, and the Product you activated.
  8. Update UsersController create method to redirect to credit card collection form:
def create
  @user = User.new(user_params)

  if @user.save
    if session['kss_redirect_to_card_collection'].present?
      session['customer_email'] = @user.email
      redirect_to session['kss_redirect_to_card_collection'] and return
    end

    redirect_to @user, notice: 'User was successfully created.'
  else
    render :new
  end
end
  1. Add the render_subscription_details helper to the app/views/users/show.html.erb view, just below the <div class="card-body"> tag:
<% if @user.stripe_customer.present? %>
  <%= render_subscription_details @user.stripe_customer.active_subscription %>
<% end %>
  1. Test out creating a subscription by visiting http://localhost:3000/plans and going through the signup process.
Contents