Welcome Guest, Not a member yet? Register   Sign In
How to continue a Code Igniter function after rendering a view
#1

I am building a system (in code igniter 3) in which the user has to make a payment before they can register. I plan on implementing this by having the user fill in a form, when they submit the form they are redirected to a payment page (on a different website), after a given time the system will make a new call to the payment system the check whether the specific order was successfully paid, if so then the system adds the new user info to the database. The code would look a bit like:

    public function process_form(){
      *get form data
      *redirect user to payment page
      *wait for 5 minutes
      *make a request to payment system to check if given order was successfully paid
      if(paid)
        add new user to database
    }

I tried to implement the following code by using php sleep function but that waits before executing any code in the function. How can I go about implementing this?
Reply
#2

Sleep isn't the right way to go about this.

The best and most scalable way would be to use a cron-job to have a background job run and check for successful payments. Use your db to have "pending payments" and a cron job that checks pending payments every 5 minutes.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

Or the payment system should return information/status about the initiated payment. It usualy does it by a http-request to your server - then you could update payment status within the database. If the http-request fails due to an outside technical reason, the payment system usually tries to confirm again in a certain schedule.
Reply
#4

(07-07-2020, 09:17 PM)albertleao Wrote: Sleep isn't the right way to go about this.

The best and most scalable way would be to use a cron-job to have a background job run and check for successful payments. Use your db to have "pending payments" and a cron job that checks pending payments every 5 minutes.
I have been doing some research on cron jobs since this. I think this will get the job. Thank you for the assist. I'll update upon the successful completion of the feature.
Reply
#5

(07-08-2020, 02:46 AM)ivantcholakov Wrote: Or the payment system should return information/status about the initiated payment. It usualy does it by a http-request to your server - then you could update payment status within the database. If the http-request fails due to an outside technical reason, the payment system usually tries to confirm again in a certain schedule.
Thanks. I'll go back to check the payment system documentation to learn I can set the return url
Reply




Theme © iAndrew 2016 - Forum software by © MyBB