How to store existing data in database by using a session

Step 1: Get data from the blade Page and data send to the Store function.

Step 2: In the Controller, Create a store function { store() name as per your choice }.

public function pay(Request $request)
    {
        try {
            Log::info("pay success m kya aa rha h" . $request);

            $response = $this->gateway->purchase(array(
                'amount' => $request->amount,
                'org_slug' => $request->org_slug,
                'admin_email' => $request->admin_email,
                'user_name' => $request->user_name,
                'admin_id' => $request->admin_id,
                'slug' => $request->slug,
                'currency' => env('PAYPAL_CURRENCY'),
                'returnUrl' => url('success'),
                'cancelUrl' => url('error')
            ))->send();

            if ($response->isRedirect()) {
                $response->redirect();
                $request->session()->put('admin_id', $request->admin_id); 
                $request->session()->put('org_slug', $request->org_slug); 
                $request->session()->put('admin_email', $request->admin_email); 
                $request->session()->put('user_name', $request->user_name); 
                $request->session()->put('slug', $request->slug); 
            } else {
                return $response->getMessage();
            }
        } catch (\Throwable $th) {
            return $th->getMessage();
        }
    }

    public function success(Request $request)

    {

        Log::info("paypal success m kya aa rha h" . $request);
        if ($request->input('paymentId') && $request->input('PayerID')) {

            Log::info("paypal request m kya aa rha h" . $request);
            $transaction = $this->gateway->completePurchase(
                array(
                    'payer_id' => $request->input('PayerID'),
                    'admin_id' => $request->input('admin_id'),
                    'user_name' => $request->input('user_name'),
                    'slug' => $request->input('slug'),
                    'admin_email' => $request->input('admin_email'),
                    'org_slug' => $request->input('org_slug'),
                    'transactionReference' => $request->input('paymentId'),
                )
            );


            $response = $transaction->send();
           


            if ($response->isSuccessful()) {

                Log::info("response paypal success m kya aa rha h");

                $arr = $response->getData();

                $payment = new paypal();
                $payment->payment_id = $arr['id'];
                $payment->payer_id = $arr['payer']['payer_info']['payer_id'];
                $payment->payer_email = $arr['payer']['payer_info']['email'];
                $payment->amount = $arr['transactions'][0]['amount']['total'];
                $payment->currency = env('PAYPAL_CURRENCY');
                $payment->payment_status = $arr['state'];
                $payment->admin_id = $request->session()->get('admin_id');
                $payment->user_name = $request->session()->get('user_name');
                $payment->slug = $request->session()->get('slug');
                $payment->admin_email = $request->session()->get('admin_email');
                $payment->org_slug = $request->session()->get('org_slug');
                $payment->save();
                // Store the admin_id in the session
                // $request->session()->put('admin_id', $request->input('admin_id'));
                // return "Payment is Successfull. Your Transaction Id is : " . $arr['id'];
                return back()->with("success", "Payment is Successfull. Your Transaction Id is : " . $arr['id']);
            } else {
                return $response->getMessage();
            }
        } else {
            return back()->with("danger", "Payment declined!!");
        }
    }

Related Posts

How Predictive Monitoring Platforms Optimize Modern DataOps and Data Observability

Introduction Traditional monitoring systems are no longer equipped to handle this level of complexity. Legacy tools depend entirely on static thresholds, which flag problems only after a…

Read More

DataOps Integration Tools: A Guide to Seamless Data Pipeline Integration

Modern enterprise organizations generate vast quantities of information across dozens of isolated systems. Managing this distributed ecosystem requires engineering infrastructure that can ingest, process, and deliver data…

Read More

Transforming Global Healthcare Solutions with Expert Treatment Guidance

Introduction As healthcare networks expand globally, an increasing number of individuals look beyond their geographic borders for solutions. However, exploring foreign medical environments presents its own set…

Read More

Affordable Healthcare Secrets: How MyHospitalNow Helps Patients Find Verified Hospitals and Save Money

Introduction The single greatest hurdle in modern healthcare is the lack of transparent, centralized data. Comparing treatment costs across different institutions is notoriously difficult. A procedure that…

Read More

DataOps Security in Pipelines: Best Practices for Data Engineers

Data has become the primary asset of the modern enterprise, but it is also the most vulnerable. As organizations migrate from static data warehouses to distributed, real-time…

Read More

Evaluating Enterprise DataOps Tools for Secure Automation and Pipeline Orchestration

Introduction Enterprise data systems are expanding at an unprecedented rate. Organizations no longer manage just a few centralized databases. Instead, modern infrastructure spans across hybrid cloud environments,…

Read More