Skip to content

Instantly share code, notes, and snippets.

@boy-jer
Forked from ahawkins/billing_musings.rb
Created May 24, 2012 14:12
Show Gist options
  • Save boy-jer/2781804 to your computer and use it in GitHub Desktop.
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,
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