-
-
Save boy-jer/2781804 to your computer and use it in GitHub Desktop.
Tiered SaaS plans w/per use individual service billings. These are just musings,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FreemiumPlan | |
include Billing::Plan | |
def cost | |
0 | |
end | |
def number_of_users | |
5 | |
end | |
def number_of_contacts | |
20 | |
end | |
def storage_space | |
100.megabtyes | |
end | |
def initial_credit | |
100 | |
end | |
end | |
class Costs | |
include Billing::Cost | |
def sms(attributes) | |
case :region | |
when :north_america | |
0.01 | |
when :europe | |
0.05 | |
end | |
end | |
end | |
class Ability | |
include CanCan::Ablity | |
def initialize(user) | |
can :create, Contact if account.contacts.count < plan.number_of_contacts | |
end | |
private | |
def plan | |
acccount.plan | |
end | |
def account | |
user.account | |
end | |
end | |
class SmsController < ApplicationController | |
rescue_from Billing::NotEnoughCredit do | |
render :text => "Your account does not have enough credit", :status => :payment_required | |
end | |
def create | |
@sms = Sms.new params[:sms] | |
bill! :sms, :region => @sms.region | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment