Skip to content

Commit

Permalink
Updated to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dveldhoen committed Jan 9, 2022
1 parent e199643 commit ba65b1e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 37 deletions.
8 changes: 6 additions & 2 deletions src/EasyApis/EasyInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ public static function create($data)
{
try {
$client = new Client();
$response = $client->request('POST', 'https://api.easyinvoice.cloud/v1/invoices', [
$response = $client->request('POST', 'https://api.easyinvoice.cloud/v2/free/invoices', [
'json' => ["data" => $data]
]);

if ($response->getBody()) {
$result = json_decode($response->getBody(), true);
return $result['data']['pdf'];
return $result['data'];
}

} catch (\GuzzleHttp\Exception\GuzzleException $e) {
echo $e;
}
}

public static function save($pdfBase64, $filename = 'invoice'){
file_put_contents($filename . '.pdf', $pdfBase64);
}
}
108 changes: 73 additions & 35 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,87 @@
use EasyApis\EasyInvoice;

$invoiceData = [
'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',
],
'client' => [
'company' => 'Client Corp',
'address' => 'Clientstreet 456',
'zip' => '4567 CD',
'city' => 'Clientcity',
'country' => 'Clientcountry',
],
'invoiceNumber' => '2021.0001',
'invoiceDate' => '1.1.2021',
'products' => [
"bottom-notice" => "Kindly pay your invoice within 15 days.",
"products" => [
[
'quantity' => '2',
'description' => 'Test1',
'tax' => 6,
'price' => 33.87,
"quantity" => 2,
"description" => "Test1",
"tax-rate" => 6,
"price" => 33.87
],
[
'quantity' => '4',
'description' => 'Test2',
'tax' => 21,
'price' => 10.45,
"quantity" => 4.1,
"description" => "Test2",
"tax-rate" => 6,
"price" => 12.34
],
[
"quantity" => 4.5678,
"description" => "Test3",
"tax-rate" => 21,
"price" => 6324.453456
]
],
"translate" => [
"invoice" => "FACTUUR",
"number" => "Nummer",
"date" => "Datum",
"due-date" => "Verloopdatum",
"subtotal" => "Subtotaal",
"products" => "Producten",
"quantity" => "Aantal",
"price" => "Prijs",
"product-total" => "Totaal",
"total" => "Totaal"
],
"images" => [
"logo" => "https://public.easyinvoice.cloud/img/logo_en_original.png",
"background" => "https://public.easyinvoice.cloud/img/watermark-draft.jpg"
],
'bottomNotice' => 'Kindly pay your invoice within 15 days.',
"settings" => [
"currency" => "EUR",
"locale" => "nl-NL",
"tax-notation" => "gst",
"margin-top" => 25,
"margin-right" => 25,
"margin-left" => 25,
"margin-bottom" => 25,
"format" => "A4"
],
"information" => [
"number" => "2021.0001",
"date" => "12-12-2021",
"due-date" => "31-12-2021"
],
"sender" => [
"company" => "Sample Corp",
"address" => "Sample Street 123",
"zip" => "1234 AB",
"city" => "Sampletown",
"country" => "Samplecountry",
"custom1" => "sender-custom1",
"custom2" => "sender-custom2",
"custom3" => "sender-custom3"
],
"client" => [
"company" => "Client Corp",
"address" => "Clientstreet 456",
"zip" => "4567 CD",
"city" => "Clientcity",
"country" => "Clientcountry",
"custom1" => "client-custom1",
"custom2" => "client-custom2",
"custom3" => "client-custom3"
]
];

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

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

$fileName = 'invoice-test';
EasyInvoice::save(base64_decode($invoice['pdf']), $fileName);

echo 'Invoice saved as ' . $fileName . '.pdf';

0 comments on commit ba65b1e

Please sign in to comment.