I
I
Ivan Nesterovich2014-07-28 10:17:25
Ruby on Rails
Ivan Nesterovich, 2014-07-28 10:17:25

[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

4 answer(s)
D
Dmitry, 2014-07-28
@Dimitriys

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.

F
FanKiLL, 2014-07-28
@FanKiLL

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

This is how I checked and updated in one project when the last time a person was on
the site, the accuracy was not important, therefore + 3 hours Time.now - 3.hours
But you can change it to a day, etc. But this will only work if a person visits the site.
Hang this before_actionin ApplicationControllerand when any page loads, this method will run.

R
Rigorbb, 2014-07-28
@Rigorbb

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

A
Anton Dyachuk, 2014-07-31
@Renius

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 question

Ask a Question

731 491 924 answers to any question