SaaS: How to code the subscriptions business model?
Software as a Service (SaaS) = leasing = access to software with an end date.
You are charged
to postpone the end date
.
From this perspective, a “One-time payment” = subscription with lifetime access.
Minimalistic Database representation:
Example: Spotify subscription #
In this case a user can buy a premium
subscription for $9,99
for a limited time 1 month
to remove adds.
Here’s how it will work:
# app/models/user.rb
# email :string
# ends_at :datetime
def premium_price
# how much to charge for postponing ends_at
# always keep money in integer. last 2 digits are cents
999.to_i
end
def premium_interval
# by how long to postpone the ends_at
# monthly or yearly or forever
1.month
end
def active_subscription?
ends_at > Time.now
end
def show_annoying_adds?
# business logic
unless active_subscription?
end
# app/models/charge.rb
# user_id :integer
# amount :integer # to track how much was paid at this moment of time
belongs_to :user
# app/controllers/charges_controller.rb
def create
@charge.amount = current_user.premium_price
# PAYMENT PROVIDER LOGIC GOES HERE
if @charge.save
current_user.update(ends_at: Time.now + current_user.premium_interval)
end
end
This way whenever a user makes a payment and creates a charge
,
his subscription ends_at
is set to a later date based on premium_interval
.
Of course, in this simple example charges
are not automatic and the user has to explicitly create
a charge
.
That’s it! đź¤
The SaaS business model can usually have 2 collection_methods
:
charge_automatically
send_invoice
Did you like this article? Did it save you some time?
You might also like: #
- Launching course: Ruby on Rails - Learn to Build a Multitenancy Subscriptions SaaS app MVP
- Discount coupon: Ruby on Rails 6: Learn 25+ gems and build a Startup MVP 2020
- My journey through hackathons and startup weekends
- $1000 in AWS credits for startups (For free)
- Heroku upload local database to production