1. Go to this page and download the library: Download andreilungeanu/smartbill 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/ */
andreilungeanu / smartbill example snippets
use AndreiLungeanu\Smartbill\Facades\Smartbill;
$response = Smartbill::invoices()->create($invoiceData);
use AndreiLungeanu\Smartbill\Smartbill;
$smartbill = app(Smartbill::class);
$response = $smartbill->invoices()->create($invoiceData);
use AndreiLungeanu\Smartbill\Smartbill;
$smartbill = new Smartbill();
$response = $smartbill->invoices()->create($invoiceData);
use AndreiLungeanu\Smartbill\Facades\Smartbill;
$invoiceData = [
"companyVatCode" => "YOUR_COMPANY_VAT_CODE",
"client" => [
"name" => "UPBIT WEB DESIGN SRL",
"vatCode" => "39521446",
"isTaxPayer" => true,
"address" => "str. Suhurlui, nr. 8",
"city" => "Pechea",
"county" => "Galati",
"country" => "Romania",
"email" => "[email protected]",
"saveToDb" => false
],
"issueDate" => now()->format('Y-m-d'),
"seriesName" => "YOUR_INVOICE_SERIES",
"isDraft" => false,
"dueDate" => now()->addDays(14)->format('Y-m-d'),
"deliveryDate" => now()->format('Y-m-d'),
"products" => [
[
"name" => "Produs 1",
"isDiscount" => false,
"measuringUnitName" => "buc",
"currency" => "RON",
"quantity" => 1,
"price" => 10,
"saveToDb" => false,
"isService" => false
]
]
];
// The create method returns an array with the API response
try {
$response = Smartbill::invoices()->create($invoiceData);
// You can now access the invoice number
$invoiceNumber = $response['number']; // "0044"
} catch (\AndreiLungeanu\Smartbill\Exceptions\SmartbillApiException $e) {
// Handle Smartbill API errors
Log::error('Smartbill API error: ' . $e->getMessage());
// Optionally, show a user-friendly message or handle as needed
}
use AndreiLungeanu\Smartbill\Facades\Smartbill;
use Illuminate\Support\Facades\Storage;
$cif = 'YOUR_COMPANY_VAT_CODE';
$series = 'SBINV';
$number = '0044';
// The getPdf method returns the raw PDF content as a string on success,
// or an array with error details if not found or failed.
try {
$pdfContent = Smartbill::invoices()->getPdf($cif, $series, $number);
Storage::disk('local')->put("invoices/{$series}-{$number}.pdf", $pdfContent);
} catch (\AndreiLungeanu\Smartbill\Exceptions\SmartbillApiException $e) {
Log::error('Smartbill PDF error: ' . $e->getMessage());
// Optionally, show a user-friendly message or handle as needed
}