Billingo API DataMapper
WARNING: The functions of this package are highly experimental, and not yet recommended for production use!
This library provides CRUD access for Billingo API with data mapped models created for every API endpoint:
- Invoices (
- Invoice blocks (
- Bank accounts (
- Expenses (
- Clients (
- Payment methods (
- Vat (
While you can use the included models without using the Billingo Factory it is not recommended.
use Billingo\API\Connector\HTTP\Request; use Billingo\API\DataMapper\BillingoFactory; $client = new Request([ 'public_key' => 'YOUR_PUBLIC_KEY', 'private_key' => 'YOUR_PRIVATE_KEY', ]); $factory = new BillingoFactory($client);
When using PHP 5.6+, you can use the
::class constant when specifying the model to make
use Billingo\API\DataMapper\Models\Clients; $clients = $factory->make(Clients::class)->loadAll();
Load class using the name of the class.
$vat = $factory->makeFromName('vat')->loadAll();
Instead of loading every model using
loadAll you can use the
load function to load a single resource.
$client = $factory->make(Clients::class)->load('12344567');
To create a new resource, you use the same factory method.
use Billingo\API\DataMapper\Models\Clients; $client = $factory->make(Clients::class); // you can either use magic variables $client->name = 'Test Client Co.'; // or simple fill the whole model with an array $client->fill([ 'name' => 'Test Client Co.' // ... ]); $client->save();
You can easily update an already saved resource by first loading it then modifying the neccessary fields and calling the
save method. The underlying library knows that it needs to update the resource instead of creating a new.
use Billingo\API\DataMapper\Models\Clients; $client = $factory->make(Clients::class)->load('12344567'); $client->name = 'Test Client Updated Co.'; $client->save();
To delete a resource first simple load the resource and then call the
use Billingo\API\DataMapper\Models\Clients; $client = $factory->make(Clients::class)->load('12344567')->delete();
There are a couple of auxilary functions in the Invoice model that can make the usage even easier.
use Billingo\API\DataMapper\Models\Invoices; $invoice = $factory->make(Invoices::class)->load('12344567'); $invoice->pay(3500, 1);
Set invoice paid, or partially paid
public function pay($amount, $paymentMethodId, $date=null)
Cancel the invoice. The function returns the new cancel invoice.
public function cancel()
Send the invoice to the client
public function send()