PHP code example of lsolesen / billy-php-sdk

1. Go to this page and download the library: Download lsolesen/billy-php-sdk 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/ */

    

lsolesen / billy-php-sdk example snippets

5

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) {
    //...
}
5

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) {
    //...
}
5

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) {
    //...
}
5

use Billy\Invoices\InvoicesRepository;

try {
    $invoice_line_items = array();

    $invoice_line = new InvoiceLine();
    $invoice_line->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) {
    //...
}

{
    "  "lsolesen/billy-php-sdk": "2.1.*"
    }
}