简体   繁体   中英

Laravel 5 session disappearing after redirection

In laravel 5.7, session is getting disappeared after redirecting to another page. I am working on an application in which I am pushing users to the payment gateway page before which I am storing the data in a session as per laravel documentation . After coming back from the payment gateway when I try to retrieve that session it returns empty. Can anyone please tell me how can I resolve this issue.

My code is something like this

public function processPayment(Request $request)
 {
    //...........
    session()->put('order_checkout_data', [
        'gateway' => 'paypal',
        'data' => $paypalData
    ]);

    //$request->session()->save();  <!-- This i tried after reading some solution but didnt help

    //print_r(session('order_checkout_data')) <!-- I can see the session here

    $paypal = new PayPal();
    $response = $paypal->purchase($paypalData);

    if ($response->isRedirect()) {
        $response->redirect(); //This is where redireting to paypal
            }
}

public function handleGatewayResponse(Request $request){
    print_r(session('order_checkout_data')); //No data
}

I tried with session global function and facade as well , like these

Session::put('order_checkout_data', [
            'gateway' => 'paypal',
            'data' => $paypalData
        ])

and also

session(['order_checkout_data'=>[
            'gateway' => 'paypal',
            'data' => $paypalData
        ]])

But no value. My env settings likes this

SESSION_DRIVER=file
SESSION_LIFETIME=360

I tried to go through some of the links with a similar problem but that didn't help. Here are the links that I have followed :

When you use sessions, a SESSION_ID (or similar) cookie is sent to the browser to know what session is associated with each request.

Your handleGatewayResponse method is called after a request from a user (it's certainly your js script that issues the request but it's the same), and you store data in the session linked to this particular user.

After PayPal finished its job, it does a request to a callback URL. This request is done by PayPal but not by your user you stored the data for. PayPal has no idea of the session cookie, so Laravel start a new empty session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM