Hi, I would like to know how can I run my code after the Laravel return something.
I'm building a payment function.
Here's my code.
// 1st : Initialize BillPlz details
$bill = $bill->create(
'PutUniqueCodeHere',
$user->email,
$user->parents->phone_code . $user->parents->contact_number,
$user->name,
MYR::given($request->amount * 100),
url('/parents/invoices'),
'Payment testing',
['redirect_url' => route('parents.invoices.show', ['invoice' => $selectedInvoice->id])]
);
// 2nd : After the user clicks to pay, go to BillPlz payment and redirect to this URL.
return redirect($bill->toArray()['url']);
// 3rd : change invoice status from draft to complete.
Invoice::where('id', $selectedInvoice->id)->update([
'status' => 'complete'
]);
Right now, If I run this code, the 1st and 2nd flows are okay. But not the 3rd flow.
And If I change the 3rd flow to the 2nd, there will have a problem. Which is if the user decided not to pay after click the button, the invoice status will change from Draft to Complete.
So what I can think right now is to run the code (change Invoice status logic) on the 3rd flow. But I need to use the return statement on 2nd flow.
Any advice?