<?php
require_once 'moneybird_php_api/Api.php';
try {
$customerId = 2;
$mbapi = new MoneybirdApi('subdomain', 'api', 'xxxxxx');
$contact = $mbapi->getContactByCustomerId($customerId);
$invoices = $contact->getInvoices('sent');
$table = "<table>\n";
foreach($invoices as $invoice){
$table .= "<tr>\n";
$table .= "<td><a href=\"".$invoice->url."\">".$invoice->invoice_id."</a></td>\n";
$table .= "<td>".$invoice->invoice_date->format("d-m-Y")."</td>\n";
$table .= "<td>".$invoice->currency." ".number_format($invoice->total_price_incl_tax, 2, ",", "")."</td>\n";
$table .= "<td>".$invoice->state."</td>\n";
$table .= "</tr>\n";
}
$table .= "</table>";
echo $table;
} catch (MoneybirdAuthorizationRequiredException $e) {
echo "Authorization failed";
} catch (MoneybirdItemNotFoundException $e) {
echo "Contact not found";
}