mollie / laravel-mollie

Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite
https://www.mollie.com/
MIT License
322 stars 62 forks source link

Webhook failed with status code 500 (Internal Server Error) #229

Closed AlphaNimmi closed 1 year ago

AlphaNimmi commented 1 year ago

I have called webhook for the payment like this

    $payment = $mollie->payments->create([
            'amount' => [
                'value' => $price_to_charge_formatted, 
                'currency' => 'EUR'
            ],
            'description' => 'Onepayment', 
            'redirectUrl' => site_url('complete_payment'),
            'method' => 'creditcard',
            'metadata' => [
                'user_id' => $user_id,
                'no_of_days' => $no_of_days,
            ],
        'webhookUrl' => site_url('mollie_webhook') 

    ]);

And my webhook public function complete_payment() {

    $api_key = $this->db->where('type', 'mollie')->get('social_keys')->result()[0]->app_id;

    $mollie = new MollieApiClient();
    $mollie->setApiKey($api_key);
    $paymentId = $this->session->userdata('payment_id');
   $payment = $mollie->payments->get($paymentId);
    $status = $payment->status; 
     if ($status === 'paid') {
          .........
          .......... //update code
          ...........

}

}

The code works fine and its updating .but mollie dashboard its showing Webhook failed with status code 500 (Internal Server Error)

Also webhooks works(Webhook called successfully, it took 0.1 seconds) when i commented all code $mollie = new MollieApiClient(); $mollie->setApiKey($api_key);.if i comment this code ans enter die it works

sandervanhooft commented 1 year ago

Hi @AlphaNimmi ,

Can you share the error message with trace from your Laravel logs?

AlphaNimmi commented 1 year ago

Hi @sandervanhooft

No error is showing in the log. I actually need to get the payment status ,so i call
$payment = $mollie->payments->get($paymentId); So for initializin mollie I call $mollie = new MollieApiClient(); $mollie->setApiKey($api_key); this giving the error in dashboard.

If I dont call this $mollie = new MollieApiClient(); $mollie->setApiKey($api_key); no error in mollie dashboard

sandervanhooft commented 1 year ago

Hi @AlphaNimmi ,

  1. There's little I can do without an actual error message. With the provided information I am unable to reproduce the issue. My first and only guess would be to look into the line $paymentId = $this->session->userdata('payment_id'); as I suspect there is no active session available when handling the webhook call.
  2. This Laravel package comes with a mollie() helper that takes care of wiring up the authentication. Why not use that?

There's not much more I can do without an error message. Closing this for now.

sandervanhooft commented 1 year ago

NB consider grabbing the $payment_id from the incoming request (see example here).