Answer the question
In order to leave comments, you need to log in
[Rails] How do I set up monthly billing?
I need to bill the user monthly on the site, which is formed based on the parameters that he has set. So far, apart from the crown, nothing comes to mind. But in my opinion this is a crutch, there should be a better option. If someone faced such a task, how did you organize it?
Ps I am writing in ruby with rails, although in this case it probably does not matter.
Answer the question
In order to leave comments, you need to log in
Once a day at 00:01 run cron which will generate invoices for all users.
Everything else is from the evil one :)
Of course, when a user enters his personal account, the first thing to do is to check if there is an account, if there is no account, create it.
if id > 0 the invoice is found, show it to the user and highlight that there is an unpaid invoice.
if id = 0 no account, create.
before_action :update_last_seen
def update_last_seen
if current_user
if (Time.now - 3.hours) >= current_user.last_seen
current_user.last_seen = Time.now
current_user.save
end
end
Time.now - 3.hours
before_action
in ApplicationController
and when any page loads, this method will run.
I think cron is a good choice. Use the gem https://github.com/javan/whenever
And in the schedule just specify
every :month do
runner "User.set_bill" # метод выставления счета для пользователей по вашим параметрам
end
mperham.github.io/sidekiq
https://github.com/tobiassvn/sidetiq
class MyWorker
include Sidekiq::Worker
include Sidetiq::Schedulable
recurrence { monthly }
def perform
# do stuff ...
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question