Problem when trying to obtain and delete a session in laravel with $ request-session () - get ('cart') and Session :: get ('cart')

0

I am developing an online store with Payu Latam, what I want to do is that when payu confirms a purchase I can empty the shopping cart of said buyer.

The process is the next ...

I send the purchase data to the Payu gateway so the users leave my store, payu verifies the data and proceeds to let the user pay, once the user pays, payu redirects it to the answer ulr of my example page :: www.mipagina.com/respuesta , here you will be informed about your purchase, this page is only informative. On the other hand there is another url called www.mipagina.com/confirmation , this page will send the data with which you can update the system, these data are sent with the POST methods.

A /confirmation comes with a variable called $state_pol that must be equal to 4 in order to do the following ...

use Session;
use Illuminate\Http\Request;

public function confirmation(Request $request) {
    $state_pol = $_POST['state_pol'];
    if($state_pol == 4) {
        // Eliminar carrito
        session()->forget('cart');

        //Informar en un archivo que el carrito fue elimado
        $fp = fopen('pruebas.txt', "a");
        fwrite($fp, "Carrito eliminado \r\n");
        fclose($fp);
    }
}

The problem is that apparently the line of elimination of the cart is not being executed, I have tried in several ways, using use Session; and Session::forget('cart') . I was doing tests to see if instead of eliminating it I get it and once I have obtained the cart I keep in a .txt file that if there are elements, so ...

use Session;
use Illuminate\Http\Request;

public function confirmation(Request $request) {
    // No funcionó con ninguna de estas formas
    //$cart = $request->session()->get('cart');
    //$cart = session()->get('cart');
    //$cart = Session::get('cart');

    if( isset($cart) ) {
        $fp = fopen('pruebas.txt', "a");
        fwrite($fp, "Hay algo en carrito \r\n");
        fclose($fp);
    }
}

Now, I have to mention that Payu sends the data to the confirmation page if that url is public, that is, it is on a public server, I upload it to a test server on heroku, another thing is that url it should not have any type of verification like what Laravel 5.6 uses, it is @csrf, so it is descative for that specific ulr.

All this works perfectly in local even with the @csrf deactivated, getting the cart and eliminating it work, with each and every one of the forms specified above.

Thank you in advance, I hope you can help me, if you need more information just say.

    
asked by Odannys De La Cruz 19.11.2018 в 19:24
source

1 answer

0

I have used the shopping cart of darryldecode and it has worked very well for me, you take away all those problems, it's good documentation.

    
answered by 20.11.2018 в 17:26