Skip to content

Commit

Permalink
Merge 9826a0f into 917d63c
Browse files Browse the repository at this point in the history
  • Loading branch information
lsolesen committed Apr 17, 2016
2 parents 917d63c + 9826a0f commit aa9f218
Show file tree
Hide file tree
Showing 42 changed files with 1,929 additions and 396 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
vendor/
composer.lock
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## CHANGELOG

## 2.0.0 - 2016-03-20

- First versioned release of Billy PHP Client for Billy api v2 in the namespace BillysBilling.
189 changes: 94 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,128 +1,127 @@
# Billy's Billing PHP SDK
# Billy PHP SDK
[![Build Status](https://travis-ci.org/lsolesen/billysbilling.svg?branch=master)](https://travis-ci.org/lsolesen/billysbilling) [![Coverage Status](https://coveralls.io/repos/lsolesen/billysbilling/badge.svg)](https://coveralls.io/r/lsolesen/billysbilling) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lsolesen/billysbilling/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lsolesen/billysbilling/?branch=master) [![Latest Stable Version](https://poser.pugx.org/lsolesen/billysbilling/v/stable)](https://packagist.org/packages/lsolesen/billysbilling) [![Total Downloads](https://poser.pugx.org/lsolesen/billysbilling/downloads)](https://packagist.org/packages/lsolesen/billysbilling) [![License](https://poser.pugx.org/lsolesen/billysbilling/license)](https://packagist.org/packages/lsolesen/billysbilling)

PHP SDK for [Billy's Billing API](https://billysbilling.com/api) version 2 only from the Danish accounting program [Billy's Billing](http://www.billysbilling.dk/).
PHP SDK for [Billy API](https://billy.dk/api) version 2 only from the Danish accounting program [Billy](http://www.billy.dk/).

## Getting started

Before doing anything you should register yourself with Billy's Billing and get access credentials.
Before doing anything you should register yourself with Billy and get access credentials.

### Create a new client

First you should create a client instance that is authorized with `api_key` or provided by BillysBilling.
First you should create a client instance that is authorized with `api_key` or provided by Billy.

```php5
<?php
use BillysBilling\Client\Client as Billy_Client;
use BillysBilling\Client\Request as Billy_Request;

try {
$request = new Billy_Request($api_key);
$client = new Billy_Client($request);
} catch (Exception $e) {
//...
}
use Billy\Client\Client as Billy_Client;
use Billy\Client\Request as Billy_Request;

try {
$request = new Billy_Request($api_key);
$client = new Billy_Client($request);
} catch (Exception $e) {
//...
}
?>
```

### Create and update contact

```php5
<?php
use BillysBilling\Contacts\ContactRepository;

try {
// @todo: This will probably end up becoming an object of its own.
$persons = array(
array(
'name' => $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) {
//...
}
use Billy\Contacts\ContactRepository;

try {
// @todo: This will probably end up becoming an object of its own.
$persons = array(
array(
'name' => $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

```php5
<?php
use BillysBilling\Products\ProductsRepository;

try {
$prices = array();
$prices[] = array(
'currencyId' => 'DKK',
'unitPrice' => '20.25',
);
$product = new Product();
$product
->setAccount($billysbilling_state_account_id)
->setProductNo($product_id)
->setSalesTaxRuleset($billysbilling_vat_model_id)
// Should this be ID or SKU?
->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) {
//...
}
use Billy\Products\ProductsRepository;

try {
$prices = array();
$prices[] = array(
'currencyId' => '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

```php5
<?php
use BillysBilling\Invoices\InvoicesRepository;

try {
$invoice_line = new InvoiceLine();
$invoice_line->setProductID($product->getID())
->setQuantity(4)
->set('priority', $priority)
->setDescription('My description')
->setUnitPrice(20.25);

$new_invoice = new Billy_Invoice();
$new_invoice->setType('invoice')
->setContactID($contact->getID())
->setContactMessage($contact_message)
->setEntryDate($entry_date)
->setPaymentTermsDays(8)
->setCurrencyID('DKK')
->set('lines', $invoice_line->toArray(););

$created_invoice = $repository->create($new_invoice);
$billysbilling_invoice_id = $created_invoice->getID();
} catch (Exception $e) {
//...
}
use Billy\Invoices\InvoicesRepository;

try {
$invoice_line = new InvoiceLine();
$invoice_line->setProductID($product->getID())
->setQuantity(4)
->set('priority', $priority)
->setDescription('My description')
->setUnitPrice(20.25);

$new_invoice = new Billy_Invoice();
$new_invoice->setType('invoice')
->setContactID($contact->getID())
->setContactMessage($contact_message)
->setEntryDate($entry_date)
->setPaymentTermsDays(8)
->setCurrencyID('DKK')
->set('lines', $invoice_line->toArray(););

$created_invoice = $repository->create($new_invoice);
$billy_invoice_id = $created_invoice->getID();
} catch (Exception $e) {
//...
}
?>
```
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lsolesen/billysbilling",
"name": "lsolesen/billy-php-sdk",
"type": "library",
"description": "PHP-SDK to communicate with BillysBilling",
"description": "PHP-SDK to communicate with Billy (http://www.billy.dk)",
"homepage": "http://github.com/lsolesen/billy-php-sdk",
"license": "MIT",
"authors": [
Expand All @@ -16,16 +16,17 @@
],
"autoload": {
"psr-4": {
"BillysBilling\\": "src/"
"Billy\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"BillysBilling\\Tests\\": "tests"
"Billy\\Tests\\": "tests"
}
},
"require": {
"php": ">=5.3.2"
"php": ">=5.3.2",
"lib/curl": "*"
},
"require-dev": {
"php": ">=5.5.0",
Expand Down

0 comments on commit aa9f218

Please sign in to comment.