zidance's avatar

How to check which http request to execute first in php backend?

I have received both main response request and backend response request from payment side.

It will run my function to update my transaction table to record payment details. There's will be a unique payment id pass into my function.

for example,

 public function response(Request $request) {
    $id = $request->id_trans;
    $trans = new Transaction;
    $trans->id_trans = $id;
    $trans->....
    $trans->save();
}

public function backend_response(Request $request) {
   $id = $request->id_trans;
   $check_trans = DB::table('transaction')->where('id_trans', $id)->first();
   if($check_trans)
       echo "OK";
       exit;
   else
       // insert here..
}

I found that it by pass my checking condition in backend_response() due to it execute before transaction insert into my table. How can i prevent this issue update my table twice? How can i ensure response() to execute first before backend_response()?

0 likes
1 reply
bobbybouwmann's avatar

I'm not sure what you mean here...

You get two requests, but you want to perform one first and then the other? It's really unclear.

PHP is transactional. So whenever you get a request it will handle it and give a response. There is no way that you can block another request from happening.

1 like

Please or to participate in this conversation.