mollie / mollie-api-php

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

Get payment exception, invalid payment id #77

Closed AntonShumin closed 7 years ago

AntonShumin commented 7 years ago

I am trying to process the webhook and check the payment status, but keep getting the "payment id is invalid". And i know that it's valid, i've created it a few seconds earlier, plus its a _POST parameter. (i've also tried hardcoding the payment_id (tr_fKme26vE7m), the same issue)

I am making payments in Testmode, Oauth for authentication.

$mollie_token = "access_89..";
$mollie_payment_id = $_POST['id'];

$mollie = new Mollie_API_Client;
$mollie->setAccessToken($mollie_token);

try {
    $payment = $mollie->payments->get( $mollie_payment_id, array("testmode" => true) );
    var_dump($payment);
} catch (Exception $e) {
    var_dump($e);
}

This gives me an exception: protected 'message' => string 'Error executing API call (request): The payment id is invalid.' (length=62) protected 'code' => int 0 protected 'file' => string 'C:\wamp64\www\kivalo\inc\vendor\mollie\mollie-api-php\src\Mollie\API\Resource\Base.php' (length=86) protected 'line' => int 353

AntonShumin commented 7 years ago

I ran through all of my code a few times. It seems that this specific payment tr_fKme26vE7m was made using a regular API key authentication and not on behalf of the Oauth authenticated profile. Once i created a new payment properly, patments->get worked as advertised

willemstuursma commented 7 years ago

Hi @AntonShumin. The payment tr_fKme26vE7m was created in test mode.

You can retrieve it by adding ?testmode=true to the API call to get the payment when using an OAuth access token.

In our client, you can do this by sending:

$mollie->payments->get('tr_fKme26vE7m', ['testmode'=>'true']);