Skip to content

This is a simple Laravel wrapper for Billingo (billingo.hu) API V3 SwaggerHUB PHP SDK.

License

Notifications You must be signed in to change notification settings

deviddev/billingo-api-v3-php-and-laravel-wrapper

Repository files navigation

Billingo API V3 Laravel and PHP Wrapper

This is a simple Laravel (PHP) wrapper for Billingo (billingo.hu) API V3 SwaggerHUB PHP SDK.

Compatible with: Laravel 8.x, 9.x and 10.x or PHP 8.1<=

You can use the wrapper easily with all type of PHP projects (not just Laravel) from 1.0.0 version without changing except downloadInvoice method.

Installation

You can install the package via composer or just download it:

composer require deviddev/billingo-api-v3-wrapper

Usage

Laravel

Publish config file:

php artisan vendor:publish --tag="billingo-config"

First set up your Billingo API V3 key in ./config/billingo-api-v3-wrapper.php config file.

Import wrapper with facade:

use BillingoApiV3Wrapper as BillingoApi;

PHP

Import wrapper:

use Deviddev\BillingoApiV3Wrapper\BillingoApiV3Wrapper as BillingoApi;

You must add your api key to BillingoApi object constructor:

$billingoApi = new BillingoApi('YOUR_API_KEY_HERE');

Available methods

Make an api instance (eg.: BankAccount, Currency, Document, DocumentBlock, DocumentExport, Organization, Partner, Product, Util):

api(string $apiName);

Add some data to model:

make(array $data);

Make a model instance (eg: Address, BankAccount, Currency, Document, etc... - see in ./vendor/deviddev/billingo-api-v3-php-sdk/lib/model):

model(string $modelName, array $data = null);

(if you don't want use make() method simply add necessary data as second parameter)

With http info (get http info (headers, response code, etc...)):

withHttpInfo();

Get invoice, partner, product(call api class method with model instance):

get(int $id);

Delete partner, product (call api class method with model instance):

delete(int $id);

Delete payment (call api class method with model instance):

deletePayment(int $id);

Create model (call api class method with model instance):

create();

Update model (call api class method with model instance and model id):

update(int $id);

Cancel invoice:

cancelInvoice(int $invoiceId);

Create invoice from proforma invoice:

createInvoiceFromProforma(int $invoiceId);

Check tax number:

checkTaxNumber(string $taxNumber);

List model (call api class method with model instance):

list(array $conditions);

*** All conditions is optional!

Download invoice to server:

downloadInvoice(int $invoiceId, string $path = null, string $extension = null);

Send invoice in email:

sendInvoice(int $invoiceId);

Get invoice public url response:

getPublicUrl(int $id);

Get Billingo API response:

getResponse();

Get Billingo API response id (eg.: partner id, invoice id, etc.):

getId();

Method chaining:

All pulic methods are chainable, except getResponse() and getId() methods. If you don't add some data to model(string $modelName, array $data = null) method second array $data = null parameter, you MUST use make(array $data) method BEFORE model() method, see in examples. The withHttpInfo() method MUST be called IMMEDIATELY AFTER the api(), make() or model() methods.

Examples

Create partner example:

Partner array:

$partner = [
    'name' => 'Test Company',
    'address' => [
        'country_code' => 'HU',
        'post_code' => '1010',
        'city' => 'Budapest',
        'address' => 'Nagy Lajos 12.',
    ],
    'emails' => ['[email protected]'],
    'taxcode' => '',
];

Laravel

Create partner and get response:

BillingoApi::api('Partner')->model('PartnerUpsert', $partner)->create()->getResponse();

OR

Create partner with make and get response:

BillingoApi::api('Partner')->make($partner)->model('PartnerUpsert')->create()->getResponse();

OR

Create partner and get partner id:

BillingoApi::api('Partner')->model('PartnerUpsert', $partner)->create()->getId();

OR

Create partner with make and get partner id:

BillingoApi::api('Partner')->make($partner)->model('PartnerUpsert')->create()->getId();

PHP

Create partner and get response:

$billingoApi->api('Partner')->model('PartnerUpsert', $partner)->create()->getResponse();

OR

Create partner with make and get response:

$billingoApi->api('Partner')->make($partner)->model('PartnerUpsert')->create()->getResponse();

OR

Create partner and get partner id:

$billingoApi->api('Partner')->model('PartnerUpsert', $partner)->create()->getId();

OR

Create partner with make and get partner id:

$billingoApi->api('Partner')->make($partner)->model('PartnerUpsert')->create()->getId();

Update partner example:

Partner array:

$partner = [
    'name' => 'Test Company updated',
    'address' => [
        'country_code' => 'HU',
        'post_code' => '1010',
        'city' => 'Budapest',
        'address' => 'Nagy Lajos 12.',
    ],
    'emails' => ['[email protected]'],
    'taxcode' => '',
];

Laravel

Update partner and get response:

BillingoApi::api('Partner')->model('Partner', $partner)->update('BILLINGO_PARTNER_ID')->getResponse();

OR

Update partner with make and get response:

BillingoApi::api('Partner')->make($partner)->model('Partner')->update('BILLINGO_PARTNER_ID')->getResponse();

OR

Update partner and get partner id:

BillingoApi::api('Partner')->model('Partner', $partner)->update('BILLINGO_PARTNER_ID')->getId();

OR

Update partner with make and get partner id:

BillingoApi::api('Partner')->make($partner)->model('Partner')->update('BILLINGO_PARTNER_ID')->getId();

PHP

Update partner and get response:

$billingoApi->api('Partner')->model('Partner', $partner)->update('BILLINGO_PARTNER_ID')->getResponse();

OR

Update partner with make and get response:

$billingoApi->api('Partner')->make($partner)->model('Partner')->update('BILLINGO_PARTNER_ID')->getResponse();

OR

Update partner and get partner id:

$billingoApi->api('Partner')->model('Partner', $partner)->update('BILLINGO_PARTNER_ID')->getId();

OR

Update partner with make and get partner id:

$billingoApi->api('Partner')->make($partner)->model('Partner')->update('BILLINGO_PARTNER_ID')->getId();

Create invoice example:

Invoice array:

$invoice = [
    'partner_id' => BILLINGO_PARTNER_ID, // REQUIRED int
    'block_id' => YOUR_BILLINGO_BLOCK_ID, // REQUIRED int
    'bank_account_id' => YOUR_BILLINGO_BANK_ACCOUNT_ID, // int
    'type' => 'invoice', // REQUIRED
    'fulfillment_date' => Carbon::now('Europe/Budapest')->format('Y-m-d'), // REQUIRED, set up other time zone if it's necessaray
    'due_date' => Carbon::now('Europe/Budapest')->format('Y-m-d'), // REQUIRED, set up other time zone if it's necessaray
    'payment_method' => 'online_bankcard', // REQUIRED, see other types in billingo documentation
    'language' => 'hu', // REQUIRED, see others in billingo documentation
    'currency' => 'HUF', // REQUIRED, see others in billingo documentation
    'conversion_rate' => 1, // see others in billingo documentation
    'electronic' => false, // see others in billingo documentation
    'paid' => false, // see others in billingo documentation
    'items' =>  [
        [
            'name' => 'Laptop', // REQUIRED
            'unit_price' => '100000', // REQUIRED
            'unit_price_type' => 'gross', // REQUIRED
            'quantity' => 2, // REQUIRED int
            'unit' => 'db', // REQUIRED
            'vat' => '27%', // REQUIRED
            'comment' => 'some comment here...',
        ],
    ],
    'comment' => 'some comment here...',
    'settings' => [
        'mediated_servicĂ­e' => false,
        'without_financial_fulfillment' => false,
        'online_payment' => '',
        'round' => 'five',
        'place_id' => 0,
    ],
];

Laravel

Create invoice and get response:

BillingoApi::api('Document')->model('DocumentInsert', $invoice)->create()->getResponse();

OR

Create invoice with make and get response:

BillingoApi::api('Document')->make($invoice)->model('DocumentInsert')->create()->getResponse();

OR

Create invoice and get invoice id:

BillingoApi::api('Document')->model('DocumentInsert', $invoice)->create()->getId();

OR

Create invoice with make and get invoice id:

BillingoApi::api('Document')->make($invoice)->model('DocumentInsert')->create()->getId();

PHP

Create invoice and get response:

$billingo->api('Document')->model('DocumentInsert', $invoice)->create()->getResponse();

OR

Create invoice with make and get response:

$billingo->api('Document')->make($invoice)->model('DocumentInsert')->create()->getResponse();

OR

Create invoice and get invoice id:

$billingo->api('Document')->model('DocumentInsert', $invoice)->create()->getId();

OR

Create invoice with make and get invoice id:

$billingo->api('Document')->make($invoice)->model('DocumentInsert')->create()->getId();

List invoices, partners, blocks, etc example:

Laravel

List invoices:

BillingoApi::api('Document')->list([
    'page' => 1,
    'per_page' => 25,
    'block_id' => 42432,
    'partner_id' => 13123123,
    'payment_method' => 'cash',
    'payment_status' => 'paid',
    'start_date' => '2020-05-10',
    'end_date' => '2020-05-15',
    'start_number' => '1',
    'end_number' => '10',
    'start_year' => 2020,
    'end_year' => 2020
])->getResponse();

List partners:

BillingoApi::api('Partner')->list([
    'page' => 1,
    'per_page' => 5
])->getResponse();

List partners with query string:

BillingoApi::api('Partner')->list([
    'page' => 1,
    'per_page' => 5,
    'query' => 'Teszt partner'
])->getResponse();

List blocks:

BillingoApi::api('DocumentBlock')->list([
    'page' => 1,
    'per_page' => 5
])->getResponse();

List banks accounts:

BillingoApi::api('BankAccount')->list([
    'page' => 1,
    'per_page' => 5
])->getResponse();

List products:

BillingoApi::api('Products')->list([
    'page' => 1,
    'per_page' => 5
])->getResponse();

PHP

List invoices:

$billingoApi->api('Document')->list([
    'page' => 1,
    'per_page' => 25,
    'block_id' => 42432,
    'partner_id' => 13123123,
    'payment_method' => 'cash',
    'payment_status' => 'paid',
    'start_date' => '2020-05-10',
    'end_date' => '2020-05-15',
    'start_number' => '1',
    'end_number' => '10',
    'start_year' => 2020,
    'end_year' => 2020
])->getResponse();

List partners:

$billingoApi->api('Partner')->list([
    'page' => 1,
    'per_page' => 5
])->getResponse();

List partners with query string:

$billingoApi->api('Partner')->list([
    'page' => 1,
    'per_page' => 5,
    'query' => 'Teszt partner'
])->getResponse();

List blocks:

$billingoApi->api('DocumentBlock')->list([
    'page' => 1,
    'per_page' => 5
])->getResponse();

List banks accounts:

$billingoApi->api('BankAccount')->list([
    'page' => 1,
    'per_page' => 5
])->getResponse();

List products:

$billingoApi->api('Products')->list([
    'page' => 1,
    'per_page' => 5
])->getResponse();

Download invoice example:

Laravel

Default path is: ./storage/app/invoices

Default extension is: .pdf

File name is invoice id.

Return the path in the response, eg.:

path: "invoices/11246867.pdf"

Download invoice:

BillingoApi::api('Document')->downloadInvoice(INVOICE_ID)->getResponse();

OR

Download to specified path and extension:

BillingoApi::api('Document')->downloadInvoice(INVOICE_ID, 'PATH', 'EXTENSION')->getResponse();

PHP

Come in version 1.1.

Send invoice in e-mail example:

Return the e-mails array where to send the invoce, eg.:

emails: [
    "[email protected]"
]

Laravel

Send invoice:

BillingoApi::api('Document')->sendInvoice(INVOICE_ID)->getResponse();

PHP

Send invoice:

$billingoApi->api('Document')->sendInvoice(INVOICE_ID)->getResponse();

Get invoice public url example:

Return the public url array, eg.:

[
    public_url: "https://api.billingo.hu/document-access/K3drE0Gvb2eRwQNYlypfasdOlJADB4Y"
]

Laravel

Get invoice public url:

BillingoApi::api('Document')->getPublicUrl(INVOICE_ID)->getResponse();

PHP

Get invoice public url:

$billingoApi->api('Document')->getPublicUrl(INVOICE_ID)->getResponse();

Cancel invoice example:

Laravel

Cancel invoice:

BillingoApi::api('Document')->cancelInvoice(INVOICE_ID)->getResponse();

PHP

Cancel invoice:

$billingoApi->api('Document')->cancelInvoice(INVOICE_ID)->getResponse();

Create invoice from proforma invoice example:

Laravel

Create invoice from proforma invoice:

BillingoApi::api('Document')->createInvoiceFromProforma(INVOICE_ID)->getResponse();

PHP

Create invoice from proforma invoice:

$billingoApi->api('Document')->createInvoiceFromProforma(INVOICE_ID)->getResponse();

Check tax number example:

First set up your NAV connection in your billingo account, because it always return "Invalid tax number!"

Laravel

Check tax number:

BillingoApi::api('Util')->checkTaxNumber('tax_number')->getResponse();

PHP

Check tax number:

$billingoApi->api('Util')->checkTaxNumber('tax_number')->getResponse();

Get invoice, product, partner example:

Laravel

Get invoice:

BillingoApi::api('Document')->get(INVOICE_ID)->getResponse();

Get partner:

BillingoApi::api('Partner')->get(PARTNER_ID)->getResponse();

Get product:

BillingoApi::api('Product')->get(PRODUCT_ID)->getResponse();

PHP

Get invoice:

$billingoApi->api('Document')->get(INVOICE_ID)->getResponse();

Get partner:

$billingoApi->api('Partner')->get(PARTNER_ID)->getResponse();

Get product:

$billingoApi->api('Product')->get(PRODUCT_ID)->getResponse();

Delete product, partner example:

Laravel

Delete partner:

BillingoApi::api('Partner')->delete(PARTNER_ID)->getResponse();

Delete product:

BillingoApi::api('Product')->get(PRODUCT_ID)->getResponse();

PHP

Delete partner:

$billingoApi->api('Partner')->delete(PARTNER_ID)->getResponse();

Delete product:

$billingoApi->api('Product')->get(PRODUCT_ID)->getResponse();

Delete payment example:

Laravel

Get partner:

BillingoApi::api('Partner')->deletePayment(PAYMENT_ID)->getResponse();

PHP

Get partner:

$billingoApi->api('Partner')->deletePayment(PAYMENT_ID)->getResponse();

With http info example:

Laravel

With http info:

BillingoApi::api('Product')->withHttpInfo()->list(['page' => 1, 'per_page' => 5])->getResponse();

PHP

With http info:

$billingoApi->api('Product')->withHttpInfo()->list(['page' => 1, 'per_page' => 5])->getResponse();

Testing

First set up your Billingo API V3 Key in config/config.php file.

Linux, MAC OS

$ ./vendor/bin/phpunit

OR

$ composer test

Windows

$ vendor\bin\phpunit

OR

$ composer test-win

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

About

This is a simple Laravel wrapper for Billingo (billingo.hu) API V3 SwaggerHUB PHP SDK.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages