Created
September 8, 2016 11:45
-
-
Save edwinv/ac151fa1e0337e0d347455b7dc20a28c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example code from http://www.moneybird.nl/blog | |
require_once 'moneybird_php_api/Api.php'; | |
try { | |
// The customer id from the current user | |
$customerId = 2; | |
// Initialize the MoneyBird api | |
$mbapi = new MoneybirdApi('subdomain', 'api', 'xxxxxx'); | |
// Get the MoneyBird contact belonging to the customer id | |
$contact = $mbapi->getContactByCustomerId($customerId); | |
// Retreive the sent invoices of the contact | |
$invoices = $contact->getInvoices('sent'); | |
// Create a table with the invoices | |
$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"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment