I want to prevent user to make payout request from his wallet for specific time

210 Views Asked by At

I'm working on e-learning academy system like udemy every instructor have wallets and wallets have three type of balance 1- total balance and it present total earning 2- available balance and it present earning that he can make payout or transfer it to his bank account 3- hold balance and it present earning that is not available for specific time then will be available to transfer it.

Project build by Laravel my issue how can I hold money for 14 days and after that make this money available without any action from my side I need logical idea to make it can use cron job, or is anyone have this experience before ?

1

There are 1 best solutions below

0
On

Let me break down the issue as per my understanding so we make sure I'm answering the correct question;

You have a system that has a wallet feature.

This wallet needs to hold some money and make the money unavailable to be paid out (hold status)

Then after 14 days, the money gets paid automatically without any interaction.

If I'm correct, then keep reading the answer below. If i'm not, correct me with a comment and I'll update my answer accordingly.


Answer:

  1. We will create a new table. Let's call it pending_payments. It'll have the following information: user_id, payment_amount, pay_at

  2. That table will hold information about pending payments and to which user they should be paid as well as the amount and the date it should be paid at.

  3. We'll have a Laravel job that can be automated ( read this for more information: https://laravel.com/docs/9.x/scheduling) which will do the following:

    a. Run daily on a specific time. Let's say at 13:00 daily for ease.

    b. It'll check the pending_payments table for payments that should be paid today.

    c. Pay them ( which means run whatever function/task you have to run in order to process the payment).

    d. On a successful payment, remove the row from pending_payments table. And on a failure payment, log the error and insert the row again with a later date to be retried again later.

That's it.