2017 © Pedro Peláez
 

api-client fakturan

REST API client for Fakturan.nu

image

fakturan.nu/fakturan

REST API client for Fakturan.nu

  • Thursday, June 4, 2015
  • by mintcore
  • Repository
  • 9 Watchers
  • 2 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Fakturan.nu REST API client PHP

API-client in PHP for the web based software of Fakturan.nu. Documentation can be viewed at API documentation., (*1)

Getting started

Requirements

  • PHP 5.4+

Installation

You can install the library via Composer by adding the following line to the require block of your composer.json file:, (*2)

"fakturan.nu/fakturan": "1.1.*"

followed by running composer install., (*3)

Setup

You authenticate by simply adding your encrypted key_id and password and then you're good to go! Remember to use sandbox-mode in development. When ready to use in production you can just remove the third parameter., (*4)

Fakturan\Fakturan::setup('KEY_ID', 'PASSWORD', [
  'sandbox' => TRUE 
]);

Examples

Retrieve all your products, (*5)

Fakturan\Model\Product::all();

Create a new product, (*6)

$new_product = new Fakturan\Product();
$new_product->name = 'My new shiny product';
$new_product->unit = 'KG';
$new_product->price = 450;

$new_product->save();

Get a single product with id 54, (*7)

$book = Fakturan\Product::find(54);

Get a single product via search, (*8)

$product = Fakturan\Product::findBy(['product_code' => 2]);

Edit product, (*9)

$book = Fakturan\Product::find(54);
$book->price = 25;
$book->save();

Delete a product, (*10)

$product_to_be_deleted = Fakturan\Product::find(54);
$product_to_be_deleted->destroy();

Create an invoice, (*11)

// Find your client
$client = Fakturan\Client::find(1);

$invoice = new Fakturan\Invoice();
$invoice->client_id = $client->id;
$invoice->date = date('Y-m-d');

// Find a product to use for templating
$product = Fakturan\Product::find(24);

// Add the product to the invoice. The second parameter can override the default values.
// It is used to set the amount and makes it possible to add a discount.
// See https://fakturan.nu/apidocs/2/invoices/create.html for possible attributes on rows.
$invoice->addRow($product, ['amount' => 5]);

// It is also possible to add rows without a preset product by sending an array instead:
$row = [
    'product_name' => 'My custom product',
    'unit' => 'PCS',
    'price' => 500,
    'amount' => 24
];
$invoice->addRow($row)

// Rows only consisting of text can also be added
$invoice->addRow(['text_row' => true, 'text' => 'Performed customizations: purple flames']);

$invoice->save();

Errors

The API will answer with different kinds of Exceptions depending on type of issue:, (*12)

Fakturan\Error\AccessDenied       // Catches 401 (access denied) 
Fakturan\Error\ResourceNotFound   // Catches 404 (Resource not found). 
Fakturan\Error\ConnectionFailed   // Catches 407 (Connection to server failed).
Fakturan\Error\ResourceInvalid    // Catches 422 (Validation errors).
Fakturan\Error\ClientError        // Catches 400-499 (Client errors).
Fakturan\Error\ServerError        // Catches 500-599 (Server related issues).
Fakturan\Error\FakturanException  // Catches all of the above

As they all inherits from Fakturan\Error\FakturanException they can all be caught within one catch-block:, (*13)

try {
    // Methods that sends a request to the server
}
catch(Fakturan\Error\FakturanException $e) 
{
  echo $e->getMessage();
}

When in production we recommend you to always use a try-catch block when using save, update_attributes and delete, (*14)

The Versions

04/06 2015

dev-master

9999999-dev https://fakturan.nu/apidocs

REST API client for Fakturan.nu

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest invoicing invoice fakturan

11/05 2015

1.1.0

1.1.0.0 https://fakturan.nu/apidocs

REST API client for Fakturan.nu

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest invoicing invoice fakturan

28/04 2015

1.0.3

1.0.3.0 https://fakturan.nu/apidocs

REST API client for Fakturan.nu

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest invoicing invoice fakturan

15/04 2015

1.0.2

1.0.2.0 https://fakturan.nu/apidocs

REST API client for Fakturan.nu

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest invoicing invoice fakturan

14/04 2015

1.0.1

1.0.1.0 https://fakturan.nu/apidocs

REST API client for Fakturan.nu

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest invoicing invoice fakturan

14/04 2015

1.0.0

1.0.0.0 https://fakturan.nu/apidocs

REST API client for Fakturan.nu

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest invoicing invoice fakturan