deviddev / billingo-api-v3-wrapper
这是一个Billingo (billingo.hu) API V3 SwaggerHUB PHP SDK的简单Laravel包装器。
Requires
- php: ^8.1
- deviddev/billingo-api-v3-php-sdk: ^0.2.6
- illuminate/support: ^8|^9|^10|^11
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-15 15:44:41 UTC
README
这是一个简单的Laravel (PHP) 包装器,用于Billingo (billingo.hu) API V3 SwaggerHUB PHP SDK。
兼容性:Laravel 8.x, 9.x 和 10.x 或 PHP 8.1 及以下
从1.0.0版本开始,您可以使用包装器轻松地在所有类型的PHP项目中使用(而不仅仅是Laravel),无需更改,除了downloadInvoice方法。
安装
您可以通过composer安装此包,或者直接下载它
composer require deviddev/billingo-api-v3-wrapper
用法
Laravel
发布配置文件
php artisan vendor:publish --tag="billingo-config"
首先,在./config/billingo-api-v3-wrapper.php配置文件中设置您的Billingo API V3密钥。
使用外观导入包装器
use BillingoApiV3Wrapper as BillingoApi;
PHP
导入包装器
use Deviddev\BillingoApiV3Wrapper\BillingoApiV3Wrapper as BillingoApi;
您必须将您的API密钥添加到BillingoApi对象的构造函数中
$billingoApi = new BillingoApi('YOUR_API_KEY_HERE');
可用方法
创建API实例(例如:BankAccount、Currency、Document、DocumentBlock、DocumentExport、Organization、Partner、Product、Util)
api(string $apiName);
向模型添加一些数据
make(array $data);
创建模型实例(例如:Address、BankAccount、Currency、Document等... - 查看./vendor/deviddev/billingo-api-v3-php-sdk/lib/model)
model(string $modelName, array $data = null);
(如果您不想使用make()方法,只需将必要的数据作为第二个参数添加即可)
带有HTTP信息(获取HTTP信息(头信息、响应代码等...))
withHttpInfo();
获取发票、合作伙伴、产品(使用模型实例调用API类方法)
get(int $id);
删除合作伙伴、产品(使用模型实例调用API类方法)
delete(int $id);
删除付款(使用模型实例调用API类方法)
deletePayment(int $id);
创建模型(使用模型实例调用API类方法)
create();
更新模型(使用模型实例和模型ID调用API类方法)
update(int $id);
取消发票
cancelInvoice(int $invoiceId);
从预付款发票创建发票
createInvoiceFromProforma(int $invoiceId);
检查税号
checkTaxNumber(string $taxNumber);
列出模型(使用模型实例调用API类方法)
list(array $conditions);
*** 所有条件都是可选的!
将发票下载到服务器
downloadInvoice(int $invoiceId, string $path = null, string $extension = null);
通过电子邮件发送发票
sendInvoice(int $invoiceId);
获取发票公开URL响应
getPublicUrl(int $id);
获取Billingo API响应
getResponse();
获取Billingo API响应ID(例如:合作伙伴ID、发票ID等)
getId();
方法链式调用
所有公共方法都是链式的,除了getResponse()和getId()方法。如果您没有向model(string $modelName, array $data = null)
方法添加一些数据作为第二个参数,您必须在调用model()
方法之前,使用make(array $data)
方法,请参阅示例。必须立即在api()
、make()
或model()
方法之后调用withHttpInfo()
方法。
示例
创建合作伙伴示例
合作伙伴数组
$partner = [ 'name' => 'Test Company', 'address' => [ 'country_code' => 'HU', 'post_code' => '1010', 'city' => 'Budapest', 'address' => 'Nagy Lajos 12.', ], 'emails' => ['test@company.hu'], 'taxcode' => '', ];
Laravel
创建合作伙伴并获取响应
BillingoApi::api('Partner')->model('PartnerUpsert', $partner)->create()->getResponse();
或者
使用make创建合作伙伴并获取响应
BillingoApi::api('Partner')->make($partner)->model('PartnerUpsert')->create()->getResponse();
或者
创建合作伙伴并获取合作伙伴ID
BillingoApi::api('Partner')->model('PartnerUpsert', $partner)->create()->getId();
或者
使用make创建合作伙伴并获取合作伙伴ID
BillingoApi::api('Partner')->make($partner)->model('PartnerUpsert')->create()->getId();
PHP
创建合作伙伴并获取响应
$billingoApi->api('Partner')->model('PartnerUpsert', $partner)->create()->getResponse();
或者
使用make创建合作伙伴并获取响应
$billingoApi->api('Partner')->make($partner)->model('PartnerUpsert')->create()->getResponse();
或者
创建合作伙伴并获取合作伙伴ID
$billingoApi->api('Partner')->model('PartnerUpsert', $partner)->create()->getId();
或者
使用make创建合作伙伴并获取合作伙伴ID
$billingoApi->api('Partner')->make($partner)->model('PartnerUpsert')->create()->getId();
更新合作伙伴示例
合作伙伴数组
$partner = [ 'name' => 'Test Company updated', 'address' => [ 'country_code' => 'HU', 'post_code' => '1010', 'city' => 'Budapest', 'address' => 'Nagy Lajos 12.', ], 'emails' => ['test@company.hu'], 'taxcode' => '', ];
Laravel
更新合作伙伴并获取响应
BillingoApi::api('Partner')->model('Partner', $partner)->update('BILLINGO_PARTNER_ID')->getResponse();
或者
使用make更新合作伙伴并获取响应
BillingoApi::api('Partner')->make($partner)->model('Partner')->update('BILLINGO_PARTNER_ID')->getResponse();
或者
更新合作伙伴并获取合作伙伴ID
BillingoApi::api('Partner')->model('Partner', $partner)->update('BILLINGO_PARTNER_ID')->getId();
或者
使用make更新合作伙伴并获取合作伙伴ID
BillingoApi::api('Partner')->make($partner)->model('Partner')->update('BILLINGO_PARTNER_ID')->getId();
PHP
更新合作伙伴并获取响应
$billingoApi->api('Partner')->model('Partner', $partner)->update('BILLINGO_PARTNER_ID')->getResponse();
或者
使用make更新合作伙伴并获取响应
$billingoApi->api('Partner')->make($partner)->model('Partner')->update('BILLINGO_PARTNER_ID')->getResponse();
或者
更新合作伙伴并获取合作伙伴ID
$billingoApi->api('Partner')->model('Partner', $partner)->update('BILLINGO_PARTNER_ID')->getId();
或者
使用make更新合作伙伴并获取合作伙伴ID
$billingoApi->api('Partner')->make($partner)->model('Partner')->update('BILLINGO_PARTNER_ID')->getId();
创建发票示例
发票数组
$invoice = [ 'partner_id' => BILLINGO_PARTNER_ID, // REQUIRED int 'block_id' => YOUR_BILLINGO_BLOCK_ID, // REQUIRED int 'bank_account_id' => YOUR_BILLINGO_BANK_ACCOUNT_ID, // int 'type' => 'invoice', // REQUIRED 'fulfillment_date' => Carbon::now('Europe/Budapest')->format('Y-m-d'), // REQUIRED, set up other time zone if it's necessaray 'due_date' => Carbon::now('Europe/Budapest')->format('Y-m-d'), // REQUIRED, set up other time zone if it's necessaray 'payment_method' => 'online_bankcard', // REQUIRED, see other types in billingo documentation 'language' => 'hu', // REQUIRED, see others in billingo documentation 'currency' => 'HUF', // REQUIRED, see others in billingo documentation 'conversion_rate' => 1, // see others in billingo documentation 'electronic' => false, // see others in billingo documentation 'paid' => false, // see others in billingo documentation 'items' => [ [ 'name' => 'Laptop', // REQUIRED 'unit_price' => '100000', // REQUIRED 'unit_price_type' => 'gross', // REQUIRED 'quantity' => 2, // REQUIRED int 'unit' => 'db', // REQUIRED 'vat' => '27%', // REQUIRED 'comment' => 'some comment here...', ], ], 'comment' => 'some comment here...', 'settings' => [ 'mediated_servicíe' => false, 'without_financial_fulfillment' => false, 'online_payment' => '', 'round' => 'five', 'place_id' => 0, ], ];
Laravel
创建发票并获取响应
BillingoApi::api('Document')->model('DocumentInsert', $invoice)->create()->getResponse();
或者
使用make创建发票并获取响应
BillingoApi::api('Document')->make($invoice)->model('DocumentInsert')->create()->getResponse();
或者
创建发票并获取发票ID
BillingoApi::api('Document')->model('DocumentInsert', $invoice)->create()->getId();
或者
使用make创建发票并获取发票ID
BillingoApi::api('Document')->make($invoice)->model('DocumentInsert')->create()->getId();
PHP
创建发票并获取响应
$billingo->api('Document')->model('DocumentInsert', $invoice)->create()->getResponse();
或者
使用make创建发票并获取响应
$billingo->api('Document')->make($invoice)->model('DocumentInsert')->create()->getResponse();
或者
创建发票并获取发票ID
$billingo->api('Document')->model('DocumentInsert', $invoice)->create()->getId();
或者
使用make创建发票并获取发票ID
$billingo->api('Document')->make($invoice)->model('DocumentInsert')->create()->getId();
列出发票、合作伙伴、块等示例
Laravel
列出发票
BillingoApi::api('Document')->list([ 'page' => 1, 'per_page' => 25, 'block_id' => 42432, 'partner_id' => 13123123, 'payment_method' => 'cash', 'payment_status' => 'paid', 'start_date' => '2020-05-10', 'end_date' => '2020-05-15', 'start_number' => '1', 'end_number' => '10', 'start_year' => 2020, 'end_year' => 2020 ])->getResponse();
列出合作伙伴
BillingoApi::api('Partner')->list([ 'page' => 1, 'per_page' => 5 ])->getResponse();
使用查询字符串列出合作伙伴
BillingoApi::api('Partner')->list([ 'page' => 1, 'per_page' => 5, 'query' => 'Teszt partner' ])->getResponse();
列出块
BillingoApi::api('DocumentBlock')->list([ 'page' => 1, 'per_page' => 5 ])->getResponse();
列出银行账户
BillingoApi::api('BankAccount')->list([ 'page' => 1, 'per_page' => 5 ])->getResponse();
列出产品
BillingoApi::api('Products')->list([ 'page' => 1, 'per_page' => 5 ])->getResponse();
PHP
列出发票
$billingoApi->api('Document')->list([ 'page' => 1, 'per_page' => 25, 'block_id' => 42432, 'partner_id' => 13123123, 'payment_method' => 'cash', 'payment_status' => 'paid', 'start_date' => '2020-05-10', 'end_date' => '2020-05-15', 'start_number' => '1', 'end_number' => '10', 'start_year' => 2020, 'end_year' => 2020 ])->getResponse();
列出合作伙伴
$billingoApi->api('Partner')->list([ 'page' => 1, 'per_page' => 5 ])->getResponse();
使用查询字符串列出合作伙伴
$billingoApi->api('Partner')->list([ 'page' => 1, 'per_page' => 5, 'query' => 'Teszt partner' ])->getResponse();
列出块
$billingoApi->api('DocumentBlock')->list([ 'page' => 1, 'per_page' => 5 ])->getResponse();
列出银行账户
$billingoApi->api('BankAccount')->list([ 'page' => 1, 'per_page' => 5 ])->getResponse();
列出产品
$billingoApi->api('Products')->list([ 'page' => 1, 'per_page' => 5 ])->getResponse();
下载发票示例
Laravel
默认路径是: ./storage/app/invoices
默认扩展名是: .pdf
文件名为发票ID。
在响应中返回路径,例如。
path: "invoices/11246867.pdf"
下载发票
BillingoApi::api('Document')->downloadInvoice(INVOICE_ID)->getResponse();
或者
下载到指定的路径和扩展名
BillingoApi::api('Document')->downloadInvoice(INVOICE_ID, 'PATH', 'EXTENSION')->getResponse();
PHP
在版本1.1中引入。
电子邮件发送发票示例
返回要发送发票的电子邮件数组,例如。
emails: [
"kiss@kft.hu"
]
Laravel
发送发票
BillingoApi::api('Document')->sendInvoice(INVOICE_ID)->getResponse();
PHP
发送发票
$billingoApi->api('Document')->sendInvoice(INVOICE_ID)->getResponse();
获取发票公开URL示例
返回公开URL数组,例如。
[
public_url: "https://api.billingo.hu/document-access/K3drE0Gvb2eRwQNYlypfasdOlJADB4Y"
]
Laravel
获取发票公开URL
BillingoApi::api('Document')->getPublicUrl(INVOICE_ID)->getResponse();
PHP
获取发票公开URL
$billingoApi->api('Document')->getPublicUrl(INVOICE_ID)->getResponse();
取消发票示例
Laravel
取消发票
BillingoApi::api('Document')->cancelInvoice(INVOICE_ID)->getResponse();
PHP
取消发票
$billingoApi->api('Document')->cancelInvoice(INVOICE_ID)->getResponse();
从形式发票创建发票示例
Laravel
从预付款发票创建发票
BillingoApi::api('Document')->createInvoiceFromProforma(INVOICE_ID)->getResponse();
PHP
从预付款发票创建发票
$billingoApi->api('Document')->createInvoiceFromProforma(INVOICE_ID)->getResponse();
检查税号示例
首先在billingo账户中设置你的NAV连接,因为它总是返回"无效的税号!"
Laravel
检查税号
BillingoApi::api('Util')->checkTaxNumber('tax_number')->getResponse();
PHP
检查税号
$billingoApi->api('Util')->checkTaxNumber('tax_number')->getResponse();
获取发票、产品、合作伙伴示例
Laravel
获取发票
BillingoApi::api('Document')->get(INVOICE_ID)->getResponse();
获取合作伙伴
BillingoApi::api('Partner')->get(PARTNER_ID)->getResponse();
获取产品
BillingoApi::api('Product')->get(PRODUCT_ID)->getResponse();
PHP
获取发票
$billingoApi->api('Document')->get(INVOICE_ID)->getResponse();
获取合作伙伴
$billingoApi->api('Partner')->get(PARTNER_ID)->getResponse();
获取产品
$billingoApi->api('Product')->get(PRODUCT_ID)->getResponse();
删除产品、合作伙伴示例
Laravel
删除合作伙伴
BillingoApi::api('Partner')->delete(PARTNER_ID)->getResponse();
删除产品
BillingoApi::api('Product')->get(PRODUCT_ID)->getResponse();
PHP
删除合作伙伴
$billingoApi->api('Partner')->delete(PARTNER_ID)->getResponse();
删除产品
$billingoApi->api('Product')->get(PRODUCT_ID)->getResponse();
删除支付示例
Laravel
获取合作伙伴
BillingoApi::api('Partner')->deletePayment(PAYMENT_ID)->getResponse();
PHP
获取合作伙伴
$billingoApi->api('Partner')->deletePayment(PAYMENT_ID)->getResponse();
带有http信息示例
Laravel
带有http信息
BillingoApi::api('Product')->withHttpInfo()->list(['page' => 1, 'per_page' => 5])->getResponse();
PHP
带有http信息
$billingoApi->api('Product')->withHttpInfo()->list(['page' => 1, 'per_page' => 5])->getResponse();
测试
首先在config/config.php
文件中设置你的Billingo API V3密钥。
Linux, MAC OS
$ ./vendor/bin/phpunit
或者
$ composer test
Windows
$ vendor\bin\phpunit
或者
$ composer test-win
贡献
有关详细信息,请参阅CONTRIBUTING。
安全
如果您发现任何与安全相关的问题,请通过电子邮件发送至david.molnar.mega@gmail.com,而不是使用问题跟踪器。
致谢
许可
MIT许可证(MIT)。有关更多信息,请参阅许可文件。
Laravel Package Boilerplate
此包是使用Laravel Package Boilerplate生成的。