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

dilfdo's avatar

laravel 5 omnipay with Rest API

i want to integrate paypal with the data which i received from POST

my controller function for get booking data


public function postPhoneBookingDetails(Request $request)
{
   try {
   $PhoneBookings = $request->only('symptoms', 'fee_total');
   $PhoneBooking = new PhoneBooking;
   $PhoneBooking->symptoms = $request->input('symptoms');
   $PhoneBooking->fee_total = $request->input('fee_total');
   $PhoneBooking->save(); 

   return $PhoneBooking;
   }


route :
Route::post('api/phonebooking', 'PhoneBookingController@postPhoneBookingDetails');


i want to pass relevant data through paypal integration please advice

this is my current settings

    public function postPayment()
    {
            $params = array(
                    'cancelUrl'     => 'http://localhost/gastrodr1/cancel_order',
                    'returnUrl'     => 'http://localhost/gastrodr1/payment_success',
                    'name'      => Input::get('name'),
                    'description'   => Input::get('symptoms'),
                    'amount'    => Input::get('fee_total'),
                    'currency'  => 'USD'
            );
            
            Session::put('params', $params);
            Session::save();  
        
        $gateway = Omnipay::create('PayPal_Express');
        $gateway->setUsername(' ');
        $gateway->setPassword(' ');
        $gateway->setSignature(' ');
        $gateway->setTestMode(true);
        $response = $gateway->purchase($params)->send();
            if ($response->isSuccessful()) {
          
                // payment was successful: update database
                print_r($response);
        } elseif ($response->isRedirect()) {

                // redirect to offsite payment gateway
                $response->redirect();
        } else {
              // payment failed: display message to customer
              echo $response->getMessage();
        }
    }

    public function getSuccessPayment()
    {
        $gateway = Omnipay::create('PayPal_Express');
        $gateway->setUsername(' ');
        $gateway->setPassword(' ');
        $gateway->setSignature(' ');
        $gateway->setTestMode(true);
        
        $params = Session::get('params');
        $response = $gateway->completePurchase($params)->send();
        $paypalResponse = $response->getData(); // this is the raw response object
    
        if(isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') {
                // Response
                // print_r($paypalResponse);
        
        } else {
                
                //Failed transaction
                
        }
            return View::make('result');
    }

```
0 likes
1 reply
connor11528's avatar

Did you figure out an answer to this problem? I too would like to build a payment API with omnipay

Please or to participate in this conversation.