All Projects → picqer → Moneybird Php Client

picqer / Moneybird Php Client

Licence: mit
PHP Client for Moneybird V2

Projects that are alternatives of or similar to Moneybird Php Client

Php Quandl
Easy access to the Quandl Data API using PHP
Stars: ✭ 51 (-23.88%)
Mutual labels:  api-client
Quandl Python
Stars: ✭ 1,076 (+1505.97%)
Mutual labels:  api-client
Somfy Open Api
REST API client for the Somfy Open API
Stars: ✭ 59 (-11.94%)
Mutual labels:  api-client
Google Measurement Php Client
PHP Client to send analytics data over the Google Measurement Protocol to Google Analytics
Stars: ✭ 52 (-22.39%)
Mutual labels:  api-client
Wikipedir
R's MediaWiki API client library
Stars: ✭ 54 (-19.4%)
Mutual labels:  api-client
Api Php Client
PHP client of Akeneo PIM API
Stars: ✭ 56 (-16.42%)
Mutual labels:  api-client
Devrant
Unofficial wrapper for the public devRant API.
Stars: ✭ 48 (-28.36%)
Mutual labels:  api-client
Slacko
A neat interface for Slack
Stars: ✭ 64 (-4.48%)
Mutual labels:  api-client
Anaconda
A Go client library for the Twitter 1.1 API
Stars: ✭ 1,077 (+1507.46%)
Mutual labels:  api-client
Avenue
Wrapper around URLSession and URLSessionTask to enable seamless integration with Operation / OperationQueue.
Stars: ✭ 58 (-13.43%)
Mutual labels:  api-client
Morningstar
Morningstar API Client
Stars: ✭ 52 (-22.39%)
Mutual labels:  api-client
Simple Salesforce
A very simple Salesforce.com REST API client for Python
Stars: ✭ 1,072 (+1500%)
Mutual labels:  api-client
Groupy
A simple yet powerful API wrapper for the GroupMe messaging service.
Stars: ✭ 57 (-14.93%)
Mutual labels:  api-client
Alphavantage.net
.Net client library for Alpha Vantage API
Stars: ✭ 52 (-22.39%)
Mutual labels:  api-client
Mvvmdemo
MVVMDemo With ReactiveCocoa
Stars: ✭ 60 (-10.45%)
Mutual labels:  api-client
Apiclientcodegen
A collection of Visual Studio custom tool code generators for Swagger / OpenAPI specification files
Stars: ✭ 50 (-25.37%)
Mutual labels:  api-client
Github
Ruby interface to GitHub API
Stars: ✭ 1,081 (+1513.43%)
Mutual labels:  api-client
Igdb
Go client for the Internet Game Database API
Stars: ✭ 65 (-2.99%)
Mutual labels:  api-client
Redux Api Call
One declarative API to create reducers, action creators and selectors for any API calls
Stars: ✭ 63 (-5.97%)
Mutual labels:  api-client
Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+15771.64%)
Mutual labels:  api-client

moneybird-php-client

Run phpunit

PHP Client for Moneybird V2

Installation

This project can easily be installed through Composer.

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

You need to be able to store some data locally:

  • The three credentials mentioned above
  • Authorizationcode
  • Accesstoken

Authorization code

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

<?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.

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:

$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.

<?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
// *** Officially unsupported in the Moneybird API ***
$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 = '[email protected]';
$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

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].