Giter Club home page Giter Club logo

flyover-subscriptions's Introduction

Flyover Subscriptions

Setup

Environment Variables

You must set ENV["STRIPE_SECRET"] and ENV["STRIPE_PUBLIC_KEY"] with your API Secret and Publishable Keys so the gem can communicate with Stripe

Models

FlyoverSubscriptions has two models, Subscription and Plan. You can run rake db:migrate to install the migrations. A subscription needs to belong to a subscriber, which is a model in your host app. To designate a model as a subscriber (maybe a User, Company, or Site) just add acts_as_subscriber to the model and make sure it has an email attribute (or delegates the method to another associated model)

class User
  acts_as_subscriber
end

Nested form fields

Once you have added acts_as_subscriber, the subscriber will accept nested attributes for the subscription and you can use the form fields partial inside the form for your subscriber model as follows:

= simple_form_for @subscriber do |f|
  = f.simple_fields_for :subscription do |sf|
    = sf.association :plan, as: :hidden
    = render "subscription_fields", f: sf

Remember to build a subscription model for the subscriber in the #new action of your controller and add subscription_attributes: [:plan_id, :stripe_card_token] to permitted params. You'll also need a way to set the plan id. You can set it in the controller based on the route and add a hidden field like in the example above, or add a select field before the subscription fields.

Stripe JS

You also need to add the js necessary for Stripe to work. In your application.js, add //= require flyover_subscriptions and inside your <head> tag, add <%= render 'stripe_js' %>. Then add class="stripe-form" to any forms that have the subscription fields.

Configuration Settings

Customize the following settings in an initializer:

FlyoverSubscriptions.configure do |config|
  config.base_controller = "::ApplicationController"
  config.current_subscriber_method = "current_subscriber"
end

This project rocks and uses MIT-LICENSE.

flyover-subscriptions's People

Contributors

bcroesch avatar dvanderbeek avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.