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

Achieve Data Reliability with CDOE – Certified DataOps Engineer Program

Introduction The CDOE – Certified DataOps Engineer is established as a critical benchmark for professionals aiming to master the intersection of data engineering and operational excellence. This…

Read More

Explore deeper with Certified MLOps Manager monitoring and automation basics

Introduction The gap between developing a machine learning model and deploying it into a reliable production environment is where most artificial intelligence projects fail. The Certified MLOps…

Read More

Certified MLOps Architect: Skills, Syllabus, and Career Opportunities Explained Clearly

Introduction The Certified MLOps Architect is a comprehensive program designed for professionals who want to bridge the gap between machine learning and production engineering. This guide is…

Read More

Advanced Certified MLOps Professional Program for Scalable AI Model Deployment Systems

Introduction The Certified MLOps Professional program from AIOpsSchool has emerged as a vital benchmark for engineers looking to bridge the gap between data science and production engineering….

Read More

Powerful Certified MLOps Engineer Program to Build Reliable ML Infrastructure

Introduction The integration of Machine Learning into production environments has created a significant gap between data science and traditional software engineering. The Certified MLOps Engineer program is…

Read More

Professional Skill Alignment Around MLOps Foundation Certification in Modern Workplaces

Introduction The MLOps Foundation Certification has emerged as a critical benchmark for professionals looking to bridge the gap between data science and production engineering. This guide is…

Read More