digfish/ivx-api2-php

PHP client implementation of InvoiceXpress API using new json-based API 2.0

2.0 2017-10-02 11:28 UTC

This package is auto-updated.

Last update: 2024-04-16 03:06:48 UTC


README

Is no more than a simple PHP wrapper for making requests with the InvoiceXpress API. It's a fork of the original WidgiLabs/InvoiceXpressRequest-PHP-API, coded by nunomorgadinho.

Made compatible with the new API version 2.0 that now natively responds with JSON format.

This code can be perhaps very low level to the impatient, if you feel that after taking a look at it, and you are a fan of Laravel, as I am too, I would recommend to you as an alternative to take a look at the invoicexpress-api by rpsimao.

If you intend to use this code in a project of yours, I show below some examples on how can be used.

With the following class, which extends the class in InvoiceXpressRequest.php :

use digfish\ivx_api2_php\InvoiceXpressRequest;

<?php class MyInvoiceXpressApi extends InvoiceXpressRequest
{
    public static function init($domain, $token)   {
        parent::init($domain, $token);
    }

    public function __construct($method) {
        self::init(IVX_DOMAIN,IVX_TOKEN);
        parent::__construct($method);
    }

    public function invoke($args = array(), $debug = false)    {
        $this->post($args);
        echo "** Invoking {$this->_method} **\n ";
        $response = $this->getResponse();
        $this->request();

        if (!$this->success()) {
            echo "Something got wrong!\n";
            echo "ERRORS:\n";
            var_dump($this->getError());
        }
        return $response;
    }
}

You should already have assigned values to the IVX_DOMAIN and IVX_TOKEN . If, for example you are using myFirm as the name for your company you should use that name. The IVX_TOKEN is the API Key you can obtain at the InvoiceXpress backoffice in Account >> Integrations >> API .

You can then assign to them:

  define('IVX_DOMAIN','myFirm');
  define('IVX_TOKEN','--- the API key with 40 chars here ----');

You can put these two lines on a separate file with the adequate permissions to not be world-readable and include it in the header of the file of the example code above.

Then, to invoke your new class to get data, like listing invoices, you can do:

  $api = new MyInvoiceXpressApi ( 'invoices.list' );
  $response = $api->invoke($args);

$args is an associative PHP array with the parameters you pass to the API like for example the page number:

 $args['page'] = 3;

The API response should be in the $response variable, which contains a PHP array with the invoice data.

Some things are not implemented

Only the methods to list and manipulate Invoices, Clients and access the Invoice Items are available. Methods that use other things like Estimates, Guides, Purchase Orders, Sequences, Taxes and Accounts were not implemented (yet). Some methods that require that the args are passed through JSON as request (and don't use HTTP GET method) to the API server are still to be implemented.

Implementation project

Have a look at the ivxapi project, which provides a example case of use of this library, along with unitary tests.