Update field Hello, I'm trying to update a field ('opened') after a success payment
public function return(Request $request): string
{
$validSignature = $this->validateSignature($request->all());
if ($validSignature) {
if ($request->respStatus == 'A') {
$transaction = Transaction::where('paytabs_transaction_reference', $request->tranRef)->first();
$transaction->paid = true;
$transaction->save();
DB::table('carts')->where('user_id', Auth::id())->where('opened', 0 )->update(['opened' => 1]);
return 'Paid Message ' . $request->respMessage;
}
return 'Unpaid Message ' . $request->respMessage;
} else {
return 'Invalid Transaction Signature';
}
}
But it doesn't update , Any help please ?
Is the $transaction updated?
@Sinnbeck yes it's null at first but after success its change
@kazzuya Ok then check if this finds a record
$test = DB::table('carts')->where('user_id', Auth::id())->where('opened', 0 )->first();
dd($test);
@Sinnbeck nothing happend , even the log of (dd)
@kazzuya Ok just below setting $validSignature try this and post the result
dd($validSignature, $request->respStatus);
@Sinnbeck Still nothing happend
$validSignature = $this->validateSignature($request->all());
dd($validSignature, $request->respStatus);
It's correct right ?
@kazzuya If nothing happens, you are never hitting that method. Can you show the route and form?
@Sinnbeck That's the route
Route::post('return', [PaymentController::class, 'return'])->name('return');
The form is the paytabs payment form not in blade
@kazzuya You are calling the index method but the method is named return (which is a bad name as return is a reserved keyword). I am also confused why the url is /index?
A suggestion for better naming
Route::post('payment', [PaymentController::class, 'store'])->name('payment.store');
And controller
public function store(Request $request): string
{
@Sinnbeck a question please, I need to make a (VerifyCsrfToken ) in Providers,
and here
protected $except = [
'stripe/*',
'http://example.com/foo/bar',
'http://example.com/foo/*',
];
It should be the url of my routes ? That belongs to paytabs
@kazzuya Yeah. So just return/*
Maybe pick another name for the route that is easier to remember :) paytabs/* perhaps?
@Sinnbeck ok did it but still not work even (dd) :s
@kazzuya And you followed all of my suggestions or just the csrf one? What happens when you submit that form? Does it get this return message 'Paid Message ' . $request->respMessage;?
@Sinnbeck yes i created the VerifyCsrfToken in providers and a hidden input for csrf_token
@Sinnbeck I don't know if this makes a problem
The return redirect($response['redirect_url']);
It takes me directly to LogIn Page after the success payment
While it should takes me to the home page..
public function index(Request $request): RedirectResponse
{
$response = $this->request(
url: 'https://secure-global.paytabs.com/payment/request',
payload: $this->transactionPayload(
amount: 0
)
);
Transaction::create([
'paytabs_transaction_reference' => $response->json()['tran_ref'] ?? null
]);
Cart::where('opened', '=', 0)->where('user_id', Auth::id())->update(['paytabs_transaction_reference' => $response->json()['tran_ref']]);
return redirect($response['redirect_url']);
}
public function return(Request $request): string
{
$validSignature = $this->validateSignature($request->all());
if ($validSignature) {
if ($request->respStatus == 'A') {
$transaction = Transaction::where('paytabs_transaction_reference', $request->tranRef)->first();
$transaction->paid = true;
$transaction->save();
DB::table('carts')->where('user_id', Auth::id())->where('opened', 0 )->update(['opened' => 1]);
return 'Paid Message ' . $request->respMessage;
}
return 'Unpaid Message ' . $request->respMessage;
} else {
return 'Invalid Transaction Signature';
}
}
@kazzuya What is $response['redirect_url']? dd($response['redirect_url']); Is it an external url?
@Sinnbeck done change it, But still not updating the (opened) field and after the success payment it logged out the user account , sorry..
@kazzuya What happens after you submit their form? Any chance that they expect it to be a GET request (a redirect) and not a post request?
@Sinnbeck after the submit it updates the null value and loged out the user account
@kazzuya Instead of dd() you can try using Log::info() to write debuggin to the log file.
@Sinnbeck tried it and i submitted again, but last thing was yesterday
@Sinnbeck hey sir.. I change the payment route from inside middleware(['verified']);
to outside it
And now i got the message and i tried this
$test = DB::table('carts')->where('user_id', Auth::id())->where('opened', 0 )->first();
dd($test);
It gives null, what i can do now ?
@kazzuya Check if the user is still signed in dd(Auth::user());
@Sinnbeck It's also null , I think because after clicking on pay it directly loged me out but i don't know why
@kazzuya Sounds like it. Maybe you are losing the session. You can try adding something to the session in the index method and see if it is gone in the return method
@Sinnbeck it works Thank you so much
i have change this 'same_site' => 'lax', to this 'same_site' => null,
@kazzuya awesome 👍 mark a best answer to set the thread as solved
Please sign in or create an account to participate in this conversation.