Search code examples
phpbitcoincoinbase-apicoinbase-php

Coinbase-php throws 401 error when using functions other than createButton()


I'm using coinbase-php to generate payment pages and process orders on my website. I'm able to create buttons and payment pages without any problems, but when I attempt to check an order's status, I get a 401 error. The code I'm using is:

$coinbase = Coinbase::withApiKey($coinbase_key, $coinbase_secret);
$data = json_decode($coinbase->get('/orders/'.$order_id));

And this is the relevant error message:

Notice: exception 'Coinbase_ApiException' with message 'Status code 401' in lib\Coinbase\Requestor.php:22  
Stack trace:  
#0 lib\Coinbase\Rpc.php(95): Coinbase_Requestor->doCurlRequest(Resource id #50)  
#1 lib\Coinbase\Coinbase.php(64): Coinbase_Rpc->request('GET', '/orders/6c00ec5...', Array)  
#2 inc\admin\orders.inc.php(214): Coinbase->get('/orders/N1263OA...')  

I tested several other functions from the library and createButton() seems to be the only one that works.


Solution

  • I found that there is a getOrder() function included in coinbase-php, it's just not in the documentation. This code is working:

    $coinbase = Coinbase::withApiKey($coinbase_key, $coinbase_secret);
    $status = $coinbase->getOrder($order_id)->status;
    

    I'm still not sure exactly why my original code failed, but at least I have a solution.