I don't actually have a nextInvoice date but I do have starts_at which specifies when the subscription started, every month when the new payment is made it will be rewriten with the current date now which specifies thet new cycle (period). So I actually need to check the different between starts_at and now if it passed 30 days already so I can charge the user again. The billing history (invoices) will be generated every month when the user is charged (with the date, amount, etc).
So, if each account has a nextInvoice date, at some point in every day you can run a job that fetches all accounts that are overdue (next invoice is today or in the past) and not on hold.
Then, create a billing job for each account that is due.
With that you mean two different jobs right? One for checking and another one for billing, is that corrent?
Run the billing and as each account is confirmed as payed, move the billing date out to the next 30 days.
I have a webhook configured to receive when a payment is made so I can just make those changes, Not sure tho if I need to create a job for this one too.
If you have a billing failure, record the failure reason and mark the account as on hold and then have an admin task that you perform at your convenience to check all accounts that are on hold and see if they need new card details or whatever.
That is something interesting because the payment gateway has a payment checking to see if the credit card is valid and it can take up to seconds or 48 hours*. I created a field called waiting_since that specifies if the subscription is waiting on the gateway to process the payment, it will wait until the payment gateway returns failed or paid for 48 hours, it's enough room for the payment gateway to send me a notification if the payment has been made or not. I think I will have to create a job to cancel expired waiting payment subscriptions just to be sure (in case - God knows how - the payment gateway doesn't send a notification about the payment) - not sure tho.
Be very careful how you handle failed jobs. Users will not take kindly to being billed multiple times for the same period so if there is an issue, back out and investigate. Don't just keep trying.
That is true, how would you recommend me doing that? As the @aurawindsurfing, is it better to use commands instead?
@aurawindsurfing
Ok that changes the perspective a bit however I would still go for a scheduled command.
Queue and jobs are not meant for storing this kind of information. Imagine you generate a job and wait for it to be executed 30 days + 30 days + 30 days and so on. Once you reset your queues you might lose data and money.
I would put all the subscription renewal dates for a client on a table. Run scheduled command every day to check what subscriptions need renewal and then run those directly or maybe put them only then on a queue if they might be taking longer to execute or be too many of them
Valid points. The site is estimated to have more than 5000 subscriptions (active).