Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hjortur17's avatar

How to use Laravel Session?

Hi, I'm building a booking system in Vue, and I have a web payment on a other site. What I need to do is store my data in the session while the customer goes over to the other site and pay's and then he will be redirect to my site and then a from will be posted and store the booking.

I just can't figure out the best way to store the data in the session. I was thinking to use session key to send over to the payment site and when the customer is redirected I will match the key with the key on my site and post the form. Any good ways, to do this?

Here is my data in vue:

booking: {
                    carNumber: null,
                    carSize: "Bíltegund",
                    carMake: null,
                    carType: null,
                    carColor: null,

                    name: null,
                    socialId: null,
                    email: null,
                    phone: null,

                    dropOffDate: this.dropOffDate,
                    pickUpDate: this.pickUpDate,
                    dropOffTime: "Hvenær mættiru á Leifstöð",
                    pickUpTime: "Hvenær viltu sækja bílinn?",
                    flightNumber: null,
                },
0 likes
10 replies
martinbean's avatar

@hjortur17 Usually you create an order in a "new" or "unpaid" state, redirect to the off-site payment gateway (passing the order ID), then your website marks the order as paid when returning from the gateway after a successful payment.

jlrdw's avatar

The payment Gateway site will usually have an API with examples.

hjortur17's avatar

I talked to them and they said to me to store the data in session and the proceed it when I'm redirected back to my site.

Cronix's avatar

Generally you supply a callback url that the payment processor would redirect the customer to after a successful charge. You'll have to read the docs for your payment processor on how to do that.

But if you tell them to redirect to http://yoursite.com/complete/1234, where 1234 is the order number and complete is some controller you created to handle it, you handle it there on your site when it gets redirected just like any other time you load something by an id in the url from a route.

Store the order number, send payment info and callback url to payment processor, payment goes through, payment processor redirects back to the url you specified, you complete the order on your end (marking paid in a db or whatever you are doing).

hjortur17's avatar

Alright so you are saying that I should store the booking in my DB, then send over the customer to pay and when they redirect back to my site I will overwrite the Paid field in the DB?

But this is what it says in the docs:

<input name="refermethod" type="hidden" value="POST">
<input name="refertarget" type="hidden" value="_top">
<input name="downloadurl" type="hidden" value="http://www.korta.is/"> // my website link
<input name="reference" type="hidden" value="1234567890"> // for example booking.id / session key

Here is the full docs: https://www.korta.is/docs/web-payments/#using-iframe

Cronix's avatar

So store the order_id/booking_id or whatever you're doing in the db, and use that number for the reference in the form. Then load that reference number from your db when they are sent back.

What is downloadurl for? Your comment just says "website link", but link to what specifically? Just the homepage?

hjortur17's avatar

downloadurl is the link the payment site will redirect back to.

hjortur17's avatar

@cronix - How will I fill in the rest of the form? Am I using session or not to keep the data or ?

hjortur17's avatar
hjortur17
OP
Best Answer
Level 14

Did it like this. I created my own sessionKey

if ($request->input('reference') === $request->session()->get('form.sessionKey')) {
            $booking = Booking::create([
                'carNumber' => $request->session()->get('form.carNumber'),
                'carSize' => $request->session()->get('form.carSize'),
                'carMake' => $request->session()->get('form.carMake'),
                'carType' => $request->session()->get('form.carType'),
                'carColor' => $request->session()->get('form.carColor'),

                'name' => $request->session()->get('form.name'),
                'socialId' => $request->session()->get('form.socialId'),
                'email' => $request->session()->get('form.email'),
                'phone' => $request->session()->get('form.phone'),

                'dropOffDate' => $request->session()->get('form.dropOffDate'),
                'dropOffTime' => $request->session()->get('form.dropOffTime'),
                'pickUpDate' => $request->session()->get('form.pickUpDate'),
                'pickUpTime' => $request->session()->get('form.pickUpTime'),

                'flightNumber' => $request->session()->get('form.flightNumber'),

                'numberOfDays' => $request->session()->get('form.numberOfDays'),
                'priceForDays' => $request->session()->get('form.priceForDays'),

                'paidPrice' => $request->session()->get('form.paidPrice'),

                'korta_authcode' => $request->input('authcode')
            ]);

            // $booking->services()->attach($request->session()->get('form.selectedServicesId'));

            // \Mail::to($request->session()->get('form.email'))
            //  ->cc('[email protected]')
            //  ->bcc('[email protected]')
            //  ->bcc('[email protected]')
            //  ->send(new BookingConfirmed($booking));

            return redirect('/');
        } else {
            dd($request->all());
        }

Please or to participate in this conversation.