mollie / mollie-api-python

Mollie API client for Python
http://www.mollie.com
BSD 2-Clause "Simplified" License
113 stars 55 forks source link

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

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

whyscream commented 1 year ago

Hello @AlphaNimmi,

My first observation: your code example seems to configure the complete_payment method for the redirectUrl, not the webhookUrl. So you might not be showing us the correct code sample for an issue with the webhook? Note that the request for the webhook call is not related in any way to your customer visiting the website and starting the payment, so the $paymentId cannot come from session data.

If the Mollie dashboard shows a HTTP 500 error for the webhook, there must be a related HTTP 500 error in your application logging for the webhook. My best guess is that you look into that, rather than trying random code changes: if the webhook fails somewhere in the //update code block, it mag still issue a HTTP 500.

Apart from that: this is the issue tracker for the Python API client, not the PHP one :) (but feel free to ask questions, your issue doesn't seem to be related to an actual client issue).

AlphaNimmi commented 1 year ago

Hi @whyscream The issue is from side.The way I am getting the payment id. Its Solved. Sorry For the wrong post ,but I am commenting my answer ,if it helps anyone public function mollie_webhook() {

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

    try {
        $mollie = new MollieApiClient();
        $mollie->setApiKey($api_key);
   $payment = $mollie->payments->get($_POST["id"]);

.............................. } catch (\Mollie\Api\Exceptions\ApiException $e) {

        // Log or handle the error as per your requirements

}
whyscream commented 1 year ago

Closing, issue resolved. Related issue in PHP repo: https://github.com/mollie/laravel-mollie/issues/229