andreilungeanu/smartbill
Composer 安装命令:
composer require andreilungeanu/smartbill
包简介
A Laravel package for the Smartbill API.
README 文档
README
A Laravel package for the Smartbill API, offering full compatibility with Laravel versions 11, 12, and 13.
Installation
You can install the package via composer:
composer require andreilungeanu/smartbill
Configuration
You can publish the configuration file with:
php artisan vendor:publish --provider="AndreiLungeanu\Smartbill\SmartbillServiceProvider"
This will create a config/smartbill.php file in your application's config directory. You should add your Smartbill API credentials to your .env file:
SMARTBILL_API_USERNAME=your-username
SMARTBILL_API_TOKEN=your-api-token
# Optional — HTTP request timeout in seconds (default: 30)
SMARTBILL_TIMEOUT=30
Usage Examples
You can interact with the API in two primary ways:
1. Using the Facade (recommended for Laravel)
This is the most convenient method for use within a Laravel application.
use AndreiLungeanu\Smartbill\Facades\Smartbill; $response = Smartbill::invoices()->create($invoiceData);
2. Using the Service Container
This is useful for dependency injection within your own classes.
use AndreiLungeanu\Smartbill\Smartbill; $smartbill = app(Smartbill::class); $response = $smartbill->invoices()->create($invoiceData);
Both of these methods work seamlessly because Laravel's service container automatically handles the creation of the required HTTP client and injects it into the package.
3. Manual Instantiation (Advanced)
Direct instantiation with new Smartbill() is no longer possible due to the new dependency injection requirement. If you need to use this package outside of a Laravel application or wish to manually construct the object, you must now provide a configured Illuminate\Http\Client\PendingRequest instance to its constructor.
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()->create($invoiceData);
Example 1: Creating an Invoice
This example shows how to create a new invoice and retrieve its number.
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" => "contact@upbit.ro", "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 }
Example API Response
A successful create call will return an array decoded from the following JSON structure:
{
"errorText": "",
"message": "",
"number": "0044",
"series": "SBINV",
"url": ""
}
Example 2: Downloading an Invoice PDF
This example shows how to download the PDF content of an existing invoice.
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 }
And many more...
This is just a small sample of the available methods. For a complete list of all available endpoints and their parameters, please see the full documentation.
Known Issues
When working with the Smartbill API, there are a few known issues to be aware of:
-
Internal Server Errors on Invalid Request Data: The API may return a
500 Internal Server Errorwhen the request payload contains invalid data, such as a typo in a required field name.For example, sending
numeinstead ofnamein the client object will trigger a500error:$invoiceData = [ "companyVatCode" => "YOUR_COMPANY_VAT_CODE", "client" => [ "nume" => "Test Client SRL", // Incorrect: should be "name" "vatCode" => "12345678", // ... ], // ... ];
Ideally, the API should respond with a
400 Bad Requeststatus and a helpful error message detailing which field is incorrect. Instead, it returns a generic500error, which makes debugging difficult as it incorrectly suggests a server-side failure rather than a client-side mistake.
While this package attempts to mitigate these issues where possible, the fundamental problems lie with the API's implementation. We are awaiting fixes from the Smartbill provider to ensure more reliable and standards-compliant behavior.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
andreilungeanu/smartbill 适用场景与选型建议
andreilungeanu/smartbill 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「smartbill」 「AndreiLungeanu」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 andreilungeanu/smartbill 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 andreilungeanu/smartbill 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 andreilungeanu/smartbill 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SmartBill API wrapper compatible for Laravel
SmartBill API wrapper compatible for laravel9
Alfabank REST API integration
SmartBill.ro API wrapper compatible for Laravel
SmartBill API wrapper compatible for Laravel
Laravel package for Accurate Online API integration.
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-14