2017 © Pedro Peláez
 

library moneybird-php-client

A PHP Client for the Moneybird V2 API

image

picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  • Wednesday, July 25, 2018
  • by stephangroen
  • Repository
  • 9 Watchers
  • 44 Stars
  • 31,312 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 42 Forks
  • 5 Open issues
  • 29 Versions
  • 13 % Grown

The README.md

Moneybird PHP Client

Run phpunit, (*1)

PHP Client for the Moneybird API. This client lets you integrate with Moneybird, for example by: - Creating and sending invoices - Creating and updating contact - Uploading incoming invoices of purchases - Create manual journal bookings, (*2)

This library is created and maintained by Picqer. We are looking for PHP developers to join our team!, (*3)

Installation

This project can easily be installed through Composer., (*4)

composer require picqer/moneybird-php-client

Usage

You need to have to following credentials and information ready. You can get this from your Moneybird account. - Client ID - Client Secret - Callback URL, (*5)

You need to be able to store some data locally: - The three credentials mentioned above - Authorizationcode - Accesstoken, (*6)

Authorization code

If you have no authorization code yet, you will need this first. The client supports fetching the authorization code as follows., (*7)

<?php

require __DIR__ . '/vendor/autoload.php';

$connection = new \Picqer\Financials\Moneybird\Connection();
$connection->setRedirectUrl('REDIRECTURL');
$connection->setClientId('CLIENTID');
$connection->setClientSecret('CLIENTSECRET');
$connection->redirectForAuthorization();

This will perform a redirect to Moneybird at which you can login and authorize the app for a specific Moneybird administration. After login, Moneybird will redirect you to the callback URL with request param "code" which you should save as the authorization code., (*8)

Setting the administration ID

Most methods require you to set the Administration ID to fetch the correct data. You can get the Administration ID from the URL at MoneyBird, but you can also list the administrations your user has access to running the following method after connecting. In the code samples below there's an example on how to set the first administrations from the results of the call below:, (*9)

$administrations = $moneybird->administration()->getAll();

Normal actions

After you have the authorization code as described above, you can perform normal requests. The client will take care of the accesstoken automatically., (*10)

<?php

require __DIR__ . '/vendor/autoload.php';

$connection = new \Picqer\Financials\Moneybird\Connection();
$connection->setRedirectUrl('REDIRECTURL');
$connection->setClientId('CLIENTID');
$connection->setClientSecret('CLIENTSECRET');

// Get authorization code as described in readme (always set this when available)
$connection->setAuthorizationCode('AUTHORIZATIONCODE');

// Set this in case you got the access token, otherwise client will fetch it (always set this when available)
$connection->setAccessToken('ACCESSTOKEN');

try {
    $connection->connect();
} catch (\Exception $e) {
    throw new Exception('Could not connect to Moneybird: ' . $e->getMessage());
}

// After connection save the last access token for reuse 
$connection->getAccessToken(); // will return the access token you need to save

// Set up a new Moneybird instance and inject the connection
$moneybird = new \Picqer\Financials\Moneybird\Moneybird($connection);

// Example: Get administrations and set the first result as active administration
$administrations = $moneybird->administration()->getAll();
$connection->setAdministrationId($administrations[0]->id);

// Example: Fetch list of salesinvoices 
$salesInvoices = $moneybird->salesInvoice()->get();
var_dump($salesInvoices); // Array with SalesInvoice objects

// Example: Fetch a sales invoice
$salesInvoice = $moneybird->salesInvoice()->find(3498576378625);
var_dump($salesInvoice); // SalesInvoice object

// Example: Get sales invoice PDF contents
$pdfContents = $salesInvoice->download();

// Example: Create credit invoice based on existing invoice
$creditInvoice = $salesInvoice->duplicateToCreditInvoice();
var_dump($creditInvoice); // SalesInvoice object

// Example: Create a new contact
$contact = $moneybird->contact();

$contact->company_name = 'Picqer';
$contact->firstname = 'Stephan';
$contact->lastname = 'Groen';
$contact->save();
var_dump($contact); // Contact object (as saved in Moneybird)

// Example: Update existing contact, change email address
$contact = $moneybird->contact()->find(89672345789233);
$contact->email = 'example@example.org';
$contact->save();
var_dump($contact); // Contact object (as saved in Moneybird)

// Example: Use the Moneybird synchronisation API
$contactVersions = $moneybird->contact()->listVersions();
var_dump($contactVersions); // Array with ids and versions to compare to your own

// Example: Use the Moneybird synchronisation API to get new versions of specific ids
$contacts = $moneybird->contact()->getVersions([
  2389475623478568,
  2384563478959922
]);
var_dump($contacts); // Array with two Contact objects

// Example: List sales invoices that are in draft (max 100)
$salesInvoices = $moneybird->salesInvoice()->filter([
  'state' => 'draft'
]);
var_dump($salesInvoices); // Array with filtered SalesInvoice objects

// Example: Get import mappings for contacts
$mappings = $moneybird->importMapping()->setType('contact')->get();
var_dump($mappings); // Array with ImportMapping objects

// Example: Register a payment for a sales invoice
$salesInvoicePayment = $moneybird->salesInvoicePayment();
$salesInvoicePayment->price = 153.75;
$salesInvoicePayment->payment_date = '2015-12-03';

$salesInvoice = $moneybird->salesInvoice()->find(3498576378625);
$salesInvoice->registerPayment($salesInvoicePayment);

// How to add SalesInvoiceDetails (invoice lines) to a SalesInvoice
$salesInvoiceDetailsArray = [];

foreach ($invoiceLines as $invoiceLine) { // Your invoice lines
   $salesInvoiceDetail = $moneybird->salesInvoiceDetail();
   $salesInvoiceDetail->price = 34.33;
   ...

   $salesInvoiceDetailsArray[] = $salesInvoiceDetail;
}

$salesInvoice = $moneybird->salesInvoice();
$salesInvoice->details = $salesInvoiceDetailsArray;

Code example

See for example: example/example.php, (*11)

TODO

  • Receiving webhooks support (would be nice)
  • Some linked/nested entities (notes, attachments etcetera)
  • Dedicated Exception for RateLimit reached and return of Retry-After value

The Versions

25/07 2018

dev-master

9999999-dev https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

25/07 2018

v0.18.1

0.18.1.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

11/07 2018

v0.18.0

0.18.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

22/06 2018

v0.17.0

0.17.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

11/05 2018

v0.16.0

0.16.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

24/10 2017

v0.15.0

0.15.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

21/09 2017

v0.14.0

0.14.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

20/06 2017

v0.13.0

0.13.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

08/05 2017

v0.12.0

0.12.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

11/04 2017

v0.11.0

0.11.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

10/02 2017

v0.10.0

0.10.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

24/01 2017

v0.9.0

0.9.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

30/12 2016

v0.8.0

0.8.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

24/11 2016

v0.7.2

0.7.2.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

06/10 2016

v0.7.1

0.7.1.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

20/09 2016

v0.7.0

0.7.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

15/07 2016

v0.6.0

0.6.0.0 https://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

06/06 2016

v0.5.1

0.5.1.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

24/05 2016

v0.5.0

0.5.0.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

11/05 2016

v0.4.0

0.4.0.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

07/03 2016

v0.3.3

0.3.3.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

04/03 2016

v0.3.2

0.3.2.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

15/02 2016

v0.3.1

0.3.1.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

04/02 2016

v0.3.0

0.3.0.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

22/12 2015

v0.2.1

0.2.1.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

22/12 2015

v0.2.0

0.2.0.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

17/12 2015

v0.1.2

0.1.2.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

15/12 2015

v0.1.1

0.1.1.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird

27/11 2015

v0.1.0

0.1.0.0 http://github.com/picqer/moneybird-php-client

A PHP Client for the Moneybird V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php moneybird