Billy PHP SDK
, (*1)
PHP SDK for Billy API version 2 only from the Danish accounting program Billy., (*2)
Getting started
Before doing anything you should register yourself with Billy and get access credentials., (*3)
Installation
Composer
Simply add a dependency on lsolesen/billy-php-sdk to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a dependency on Billy PHP SDK 2.1:, (*4)
{
"require": {
"lsolesen/billy-php-sdk": "2.1.*"
}
}
After running composer install, you can take advantage of Composer's autoloader in vendor/autoload.php., (*5)
Usage
Create a new client
First you should create a client instance that is authorized with api_key or provided by Billy., (*6)
$name,
'email' => $email,
)
);
$contact = new Contact();
$contact
->setName($name)
->set('phone', $phone)
->setCountryID($address['country'])
->set('street', $address['thoroughfare'])
->set('cityText', $address['locality'])
->set('stateText', $address['administrative_area'])
->set('zipcodeText', $address['postal_code'])
->set('contactNo', $profile_id)
->set('contactPersons', $persons);
$repository = new ContactRepository($request);
$created_contact = $repository->create($contact);
$contact = $repository->getSingle($created_contact->getID());
$contact
->setName($new_name);
$repository->update($contact);
} catch (Exception $e) {
//...
}
?>
Create and update product
'DKK',
'unitPrice' => '20.25',
);
$product = new Product();
$product
->setAccount($billy_state_account_id)
->setProductNo($product_id)
->setSalesTaxRuleset($billy_vat_model_id)
->set('prices', $prices);
$repository = new ProductRepository($request);
$created_product = $repository->create($product);
$product = $repository->getSingle($created_product->getID());
$product
->setName($new_name);
$repository->update($product);
} catch (Exception $e) {
//...
}
?>
Create an invoice
setProductID($product->getID())
->setQuantity(4)
->set('priority', $priority)
->setDescription('My description')
->setUnitPrice(20.25);
$invoice_line_items[] = $invoice_line->toArray();
$new_invoice = new Billy_Invoice();
$new_invoice->setType('invoice')
->setOrderNumber($order_number)
->setContactID($contact->getID())
->setContactMessage($contact_message)
->setEntryDate($entry_date)
->setPaymentTermsDays(8)
->setCurrencyID('DKK')
->set('lines', $invoice_line_items);
$created_invoice = $repository->create($new_invoice);
$billy_invoice_id = $created_invoice->getID();
} catch (Exception $e) {
//...
}
?>