Discussions

Ask a Question
Back to All

Paymongo 500 internal server error in Live Server

We are currently in the progress setting up the payment portion of our website, and it seemed straightforward enough to setup in the localhost to which it is working fine.

My understanding goes

Request from the front end...

            const url = `${import.meta.env.VITE_API_BASE_URL}/pay?roomName=${roomName}&descriptionData=${descriptionData}&sendTotalAmount=${sendTotalAmount}&payId=${payId}`;
        
            window.location.href = url;

Then the route....
Route::get('pay', [PaymentControllerCheckOut::class, 'pay']);

Then at the Controller
public function pay(Request $request)

Which works fine in localhost
but when deployed it returns with a 500 internal server error

Then we tried to make a function that is meant to test and see if Paymongo Check out can occur in the live server, but once again returned with the same error

public function test_pay(Request $request)
{

    try {
      
        $data = [
            'data' => [
                'attributes' => [
                    'line_items' => [
                        [
                            'currency' => 'PHP',
                            'amount' => 10000,
                            'name' =>'Custard',
                            'quantity' => 1,
                        ]
                    ],
                    'payment_method_types' => [
                        'card',
                        'gcash',
                    ],
                    'success_url' => 'https://api.sirmatafarm.com/success',
                    'cancel_url' => 'https://api.sirmatafarm.com/cancelled',
                    'description' =>'Macha',
                ],
            ],
        ];


        $response = Curl::to('https://api.paymongo.com/v1/checkout_sessions')
            ->withHeader('Content-Type: application/json')
            ->withHeader('accept: application/json')
            ->withHeader('Authorization: Basic ' .env('AUTH_PAY'))
            ->withData($data)
            ->asJson()
            ->post();
        


        \Session::put('session_id', $response->data->id);

        $sessionId = session('session_id');

        return redirect()->to($response->data->attributes->checkout_url);
    } catch (Exception $e) {
        return response()->json(['error' => 'An error occurred while processing the payment.'], 500);
    }
}  public function test_pay(Request $request)
    {   

        try {
          
            $data = [
                'data' => [
                    'attributes' => [
                        'line_items' => [
                            [
                                'currency' => 'PHP',
                                'amount' => 10000,
                                'name' =>'Custard',
                                'quantity' => 1,
                            ]
                        ],
                        'payment_method_types' => [
                            'card',
                            'gcash',
                        ],
                        'success_url' => 'https://api.sirmatafarm.com/success',
                        'cancel_url' => 'https://api.sirmatafarm.com/cancelled',
                        'description' =>'Macha',
                    ],
                ],
            ];

    
            $response = Curl::to('https://api.paymongo.com/v1/checkout_sessions')
                ->withHeader('Content-Type: application/json')
                ->withHeader('accept: application/json')
                ->withHeader('Authorization: Basic ' .env('AUTH_PAY'))
                ->withData($data)
                ->asJson()
                ->post();
            
   
    
            \Session::put('session_id', $response->data->id);
    
            $sessionId = session('session_id');

            return redirect()->to($response->data->attributes->checkout_url);
        } catch (Exception $e) {
            return response()->json(['error' => 'An error occurred while processing the payment.'], 500);
        }
    }



This is a our first time working with a payment gateway and wondering if there was a vital part we missed setting up?