PHP code example of audunru / fiken-api-php-client
1. Go to this page and download the library: Download audunru/fiken-api-php-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
audunru / fiken-api-php-client example snippets
use audunru\FikenClient\FikenClient;
$client = new FikenClient();
// The Fiken API uses basic authentication
// According to their documentation, you should create a separate user for accessing the API
$client->authenticate('username', 'password');
// $user is a User object
$user = $client->user();
echo $user->name; // Art Vandelay
use audunru\FikenClient\FikenClient;
$client = new FikenClient();
$client->authenticate('username', 'password');
// $companies is a Collection, so you can use Laravel Collection methods to filter or get etc.
// See https://laravel.com/docs/5.8/collections
$companies = $client->companies();
$company = $companies->first();
echo $company->name; // Vandelay Industries
use audunru\FikenClient\FikenClient;
$client = new FikenClient();
$client->authenticate('username', 'password');
// $company is a Company object
$company = $client->setCompany('123456789'); // 123456789 is the organization number
echo $company->name; // Vandelay Industries
// These are all collections, so the Laravel Collection methods can be used on them
$bankAccounts = $company->bankAccounts();
$products = $company->products();
$contacts = $company->contacts();
$accounts = $company->accounts(2019); // To get accounts, you need to set a year
// $product is a Product object
$product = $products->firstWhere('name', 'Latex');
use audunru\FikenClient\FikenClient;
use audunru\FikenClient\Models\Contact;
$client = new FikenClient();
$client->authenticate('username', 'password');
$company = $client->setCompany('123456789');
$customer = new Contact(['name' => 'Kel Varnsen', 'customer' => true]);
// $saved is a new FikenCustomer object
$saved = $company->add($customer);
use audunru\FikenClient\FikenClient;
use audunru\FikenClient\Models\Invoice;
use audunru\FikenClient\Models\InvoiceLine;
$client = new FikenClient();
$client->authenticate('username', 'password');
$company = $client->setCompany('123456789');
// Create a new invoice object
$invoice = new Invoice(['issueDate' => '2019-01-01', 'dueDate' => '2019-01-15']);
// Find an existing customer of this company and set it on the invoice
$customer = $company->contacts()->firstWhere('name', 'Kel Varnsen');
$invoice->setCustomer($customer);
// Find a bank account and set it on the invoice
$bankAccount = $company->bankAccounts()->firstWhere('number', '12341234999');
$invoice->setBankAccount($bankAccount);
// Set invoice text
$invoice->invoiceText = 'Payment for import and export services';
// Find a product
$product = $company->products()->firstWhere('name', 'Chips');
// Create a new invoice line
$line = new InvoiceLine(['netAmount' => 8000, 'vatAmount' => 2000, 'grossAmount' => 10000]);
// Set product on the invoice line
$line->setProduct($product);
// Add the invoice line to the invoice
$invoice->add($line);
// Add the invoice to the company
$saved = $company->add($invoice);
// $saved is a new Invoice object