mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
552 stars 191 forks source link

ErrorException: Undefined index: id in mollie webhook #202

Closed jimkaler closed 6 years ago

jimkaler commented 6 years ago

Hi, I am using laravel framework, I am getting error ErrorException: Undefined index: id while retrieving payment. I am using testing mode. here is the code

$mollie = new \Mollie_API_Client(); $mollie->setApiKey("APKIKEY");

try { $payment = $mollie->payments->get($_POST['id']); $order_id = $payment->metadata->order_id; // File::put(public_path('/aaaaaaaa.txt'),); //Update Database Actest_QunbwFVUMEsGsbCSUj3x5PvsRNEvRdcording Payment status if ($payment->isPaid()) {
$report = Report::where('order_id',$order_id)->first(); $report["status"] = 'Paid'; $report->save(); //Stock Getting Update after Payment has been done. $CoinValue = $report->btc_value; $stock = AvalableStock::where('type',$report->coins_type)->first(); $UpdateStock = $stock->coins-$CoinValue; $stock['coins'] = $UpdateStock; $stock->save();

            }

else {

                    $report = Report::where('order_id',$order_id)->first();
                    $report["status"] = 'Pending';
                    // $report["account_number"] = $payment->details->consumerAccount;
                    $report->save();
            }

        // File::put(public_path('/aa1.txt'),$order_id);   

    }
    catch(\Exception $e)
    {test_QunbwFVUMEsGsbCSUj3x5PvsRNEvRd
        $data = $e;
        File::put(public_path('/aaaaaaaa.txt'),$data);
    }

Thanks in advance.

Smitsel commented 6 years ago

Hi @jimkaler,

Are u running the script directly? Because this is probably because your $_POST["id"] is undefined.

The webhook is called by our server with an id in the POST. So to test your script you should POST an id to it.

See: https://docs.mollie.com/guides/webhooks

jimkaler commented 6 years ago

@Smitsel i am not running it directly, I am calling it after payment. It was running fine but suddenly it stopped working. i have changed API key, is it causing problem?

flowroma commented 6 years ago

Jim, I had the same issue. You need to use the live API key and for testing purposes use a hardcoded ID like this:

$payment = $mollie->payments->get('tr_WFF8qARVHQ');

jimkaler commented 6 years ago

Thanks for reply , may i use that same id? or from where will i get that id dude?

flowroma commented 6 years ago

The ID is given to you by Mollie once you make payment requests in live mode. Testing mode won't give you that. Yes, use some random ID for testing purpose

jimkaler commented 6 years ago

Ok ok Thanks @flowroma .

flowroma commented 6 years ago

You can, but you need to use a hardcoded ID

jimkaler commented 6 years ago

@flowroma still not getting result. :( Its saying "The payment id is invalid".

Smitsel commented 6 years ago

Hi @jimkaler can you email us at techsupport@mollie.com with an example of your code?

Closing the issue for now.