Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.67k stars 1.73k forks source link

Return Url to my website clears the Cart::content() #650

Open abdulrehman3725 opened 3 years ago

abdulrehman3725 commented 3 years ago

I am using payment api for payment. After successful payment a return URL hits to my website. But now cart::content() is empty

Why?

How to persist data?

I am using laravel 8.

abdulrehman3725 commented 3 years ago

@Crinsane Please help

I think the problem is with session. Session destroy after return URL form payment gateway.

abdulrehman3725 commented 3 years ago

My problem is solved.

I have changed the following in config/session.php file:

'same_site' => 'lax',

To the below value:

'same_site' => null,

Now session are persistent even after return URL from payment gateway!

Humourrack commented 3 years ago

Check your Callback function.

Because the cart can be cleared when it exists in your callback function.

I hope you understand what I mean by "callback"?

Take for instance, FLUTTERWAVE Payment 💲 Gateway.......

public function callback() { 
$status = request()->status; //if payment is successful 

if ($status == 'successful') { 
$transactionID = Flutterwave::getTransactionIDFromCallback();

$data = Flutterwave::verifyTransaction($transactionID);

dd($data); 
} elseif ($status == 'cancelled'){

 //Put desired action/code after transaction has been cancelled here } else{ //Put desired action/code after transaction has failed here 
} 

// Get the transaction from your DB using the transaction reference (txref) 

// Check if you have previously given value for the transaction. If you have, redirect to your successpage else, continue 

// Confirm that the currency on your db transaction is equal to the returned currency 

// Confirm that the db transaction amount is equal to the returned amount 

// Update the db transaction record (including parameters that didn't exist before the transaction is completed. for audit purposes) 

// Give value for the transaction 

// Update the transaction to note that you have given value for the transaction 

// You can also redirect to your success page from here 

}

Check this link for a better understanding _https://laravelrave.netlify.app/getting-started/payment-implementation.html#_3-setup-your-controller_