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()->createV2($invoiceData);
use AndreiLungeanu\Smartbill\Smartbill;
$smartbill = app(Smartbill::class);
$response = $smartbill->invoices()->createV2($invoiceData);
use AndreiLungeanu\Smartbill\Smartbill;
use Illuminate\Http\Client\Factory;
// Manually create and configure the HTTP client
$http = new Factory();
$client = $http->withBasicAuth('your-username', 'your-api-token')
->baseUrl('https://ws.smartbill.ro/SBORO/api')
->acceptJson();
// Pass the configured client to the constructor
$smartbill = new Smartbill($client);
$response = $smartbill->invoices()->createV2($invoiceData);
use AndreiLungeanu\Smartbill\Facades\Smartbill;
use Illuminate\Support\Facades\Log;
$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,
"taxName" => "Normala",
"taxPercentage" => 21,
"saveToDb" => false,
"isService" => false
]
]
];
// createV2 returns an array with the API response
try {
$response = Smartbill::invoices()->createV2($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\Log;
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,
// and throws SmartbillApiException if the request fails.
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
}
use AndreiLungeanu\Smartbill\Exceptions\SmartbillRequestException;
try {
Smartbill::invoices()->createV2($invoiceData);
} catch (SmartbillRequestException $e) {
$e->getParam(); // "client.nume", or "products[0].quantity" inside a list
$e->getErrorCode(); // "json_mapping_error"
}