easyapis.io/easyinvoice

A wrapper package for easyapis.io invoice creator API.

1.0.0 2021-06-09 09:46 UTC

This package is auto-updated.

Last update: 2021-07-15 13:33:42 UTC


README

Easy Invoice logo

Easy Invoice is a package that will help you to create beautiful PDF invoices with ease.

If this package helped you out please star us on Github!
Much appreciated!

Pull Request's Welcome

Platform support

Platform Repository Supported Link
PHP Composer Yes! Available on Composer
Javascript NPM Yes! Available on NPM
Python PIP Yes! Available on PIP
Java Maven In progress...

Sample

Easy Invoice Sample Logo Only Easy Invoice Sample With Background

Demo

Sample 1:
PHPSandbox Notebook

Sample 2:
PHPSandbox Notebook

Installing

Using composer:

$ composer require easyapis.io/easyinvoice

Example

<?php

require __DIR__ . '/vendor/autoload.php';

use EasyApis\EasyInvoice;

//Set the data you wish to see on your invoice
$invoiceData = [
    //"documentTitle" => "RECEIPT", //Defaults to INVOICE
    //"locale" => "de-DE", //Defaults to en-US, used for number formatting (see docs)
    'currency' => 'USD',
    'taxNotation' => 'vat',
    'marginTop' => 25,
    'marginRight' => 25,
    'marginLeft' => 25,
    'marginBottom' => 25,
    'logo' => 'https://public.easyinvoice.cloud/img/logo_en_original.png',
    'background' => 'https://public.easyinvoice.cloud/img/watermark-draft.jpg',
    'sender' => [
        'company' => 'Sample Corp',
        'address' => 'Sample Street 123',
        'zip' => '1234 AB',
        'city' => 'Sampletown',
        'country' => 'Samplecountry',
        //"custom1" => "custom value 1",
        //"custom2" => "custom value 2",
        //"custom3" => "custom value 3"
    ],
    'client' => [
        'company' => 'Client Corp',
        'address' => 'Clientstreet 456',
        'zip' => '4567 CD',
        'city' => 'Clientcity',
        'country' => 'Clientcountry',
        //"custom1" => "custom value 1",
        //"custom2" => "custom value 2",
        //"custom3" => "custom value 3"
    ],
    'invoiceNumber' => '2021.0001',
    'invoiceDate' => '1.1.2021',
    'products' => [
        [
            'quantity' => '2',
            'description' => 'Test1',
            'tax' => 6,
            'price' => 33.87,
        ],
        [
            'quantity' => '4',
            'description' => 'Test2',
            'tax' => 21,
            'price' => 10.45,
        ],
    ],
    'bottomNotice' => 'Kindly pay your invoice within 15 days.',
    //Used for translating the headers to your preferred language
    //Defaults to English. Below example is translated to Dutch
    // "translate" => [ 
    //     "invoiceNumber" => "Factuurnummer",
    //     "invoiceDate" => "Factuurdatum",
    //     "products" => "Producten", 
    //     "quantity" => "Aantal", 
    //     "price" => "Prijs",
    //     "subtotal" => "Subtotaal",
    //     "total" => "Totaal" 
    // ]
];

//Sample code to test the library
$invoice = EasyInvoice::create($invoiceData);

//The invoice object wil contain a base64 PDF string
echo $invoice;

Locales and Currency

Used for number formatting and the currency symbol:

//E.g. for Germany, prices would look like 123.456,78 €
$data = [ "locale" => "de-DE", "currency" => "EUR"];

//E.g. for US, prices would look like $123,456.78
$data = [ "locale" => "en-US", "currency" => 'USD'];

Formatting and symbols are applied through the ECMAScript Internationalization API

Click here for a list of locale codes
Click here for a list of currency codes

Disclaimer: Not all locales and currency codes found in the above lists might be supported by the ECMAScript Internationalization API.

Logo and Background

The logo and url inputs accept either a URL or a base64 encoded file.

Supported file types:

  • Logo: image
  • Background: image, pdf

URL

$invoiceData = [
    "logo" => "https://public.easyinvoice.cloud/img/logo_en_original.png",
    "background" => "https://public.easyinvoice.cloud/img/watermark_draft.jpg"
];

Base64

$invoiceData = [
    //Note: Sample base64 string
    //Please use the link below to convert your image to base64    
    "logo" => "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
    "background" => "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" 
];

Click here for an online tool to convert an image to base64

View PDF

You could view your base64 pdf through the following website: https://base64.guru/converter/decode/pdf

Paste the base64 string and click 'Decode Base64 to PDF'.