Giter Site home page Giter Site logo

billingo-api-connector's Introduction

Billingo API Connector - FORKED

This package is forked from: https://github.com/voov/Billingo-API-Connector

This package is the PHP connector for the Billingo API 2.0. The full API documentation is available here.

Installing

The easiest way to install the Connector is using Composer:

composer require froccsos/billingo-api-connector

Then use your framework's autoload, or simply add:

<?php
  require 'vendor/autoload.php';

Manual install

If you with to omit using Composer altogether, you can download the sources from the repository and use any PSR-4 compatible autoloader.

Registering your own autoloader is also a way (altough not recommended):

<?php
// Source: http://www.php-fig.org/psr/psr-4/examples/
spl_autoload_register(function ($class) {

    // project-specific namespace prefix
    $prefix = 'Billingo\\API\\Connector';

    // base directory for the namespace prefix
    $base_dir = __DIR__ . '/src/';

    // does the class use the namespace prefix?
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        // no, move to the next registered autoloader
        return;
    }

    // get the relative class name
    $relative_class = substr($class, $len);

    // replace the namespace prefix with the base directory, replace namespace
    // separators with directory separators in the relative class name, append
    // with .php
    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';

    // if the file exists, require it
    if (file_exists($file)) {
        require $file;
    }
});

Getting started

You can start making requests to the Billingo API just by creating a new Request instance

<?php
  use Billingo\API\Connector\HTTP\Request;

  $billingo = new Request([
	  'public_key' => 'YOUR_PUBLIC_KEY',
	  'private_key' => 'YOUR_PRIVATE_KEY'
  ]);

The Request class takes care of the communication between your app and the Billingo API server with JWT authorization handled in the background.

JWT Time leeway

To adjust for some time skew between the client and the API server, you can set the leeway parameter when creating the new instance. The leeway is measured in seconds and the default value is 60. This modifies the nbf, iat and exp claims of the JWT, so in the case of the default leeway, the token is valid one minute before and after the issue time.

General usage

Get resource

<?php
// Return the first page of the clients
$clients = $billingo->get('clients');
// Return the next page
$clients = $billingo->get('clients', ['page' => 2]);

// Return one client
$client = $billingo->get('clients/123456789');

Save resource

<?php
// save a new client
$clientData = [
  "name" => "Gigazoom LLC.",
  "email" => "[email protected]",
  "billing_address" => [
      "street_name" => "Moulton",
      "street_type" => "Terrace",
      "house_nr" => "2797",
      "city" => "Preston",
      "postcode" => "PR1",
      "country" => "United Kingdom"
  ]
]
$billingo->post('clients', $clientData);

Update resource

<?php
// save client
$billingo->put('clients/123456789', $newData);

Delete resource

<?php
// delete client
$billingo->delete('clients/123456789');

Download invoice

You can download the generated invoice in a PDF format

When passing the second parameter, you can specify a filename or a resource opened with fopen where the PDF will be saved. Otherwise a GuzzleHttp\Psr7\Stream is returned which you can read from.

<?php
  $billingo->downloadInvoice('123456789', 'filename.pdf');

Using the stream interface

<?php
  $invoice = $billingo->downloadInvoice('123456789');
  if($invoice->isReadable()) {
      while(!$invoice->eof()) {
          echo $invoice->read(1);
      }    
  }

billingo-api-connector's People

Contributors

danfekete avatar froccsos avatar nxu avatar saboteur777 avatar szepeviktor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.