scratchy2/billomat
Composer 安装命令:
composer require scratchy2/billomat
包简介
PHP library for interacting with the Billomat REST API
README 文档
README
Introduction
This is a Billomat PHP client for interacting with the REST Billomat API.
Extend of this client
All methods on the following assets are supported:
- Clients
- Articles
- Invoices
- Credit Notes
- Templates
Settings
Dependencies
- Guzzle library: >= 3.5
Integration with frameworks
If you want to use this client with Symfony 2, there is a ready-to-use bundle:
- billomat-bundle: a Symfony 2 bundle
Installation via composer
php composer.phar require phobetor/billomat:~1.5
How to use this
Instantiate the client:
use Phobetor\Billomat\Client\BillomatClient; $billomat = new BillomatClient('my-id', 'my-api-key');
If you have a registered app for billomat’s API (which is highly recommended due to higher rate limits) instantiate the client like this:
use Phobetor\Billomat\Client\BillomatClient; $billomat = new BillomatClient('my-id', 'my-api-key', 'my-api-app-id', 'my-api-app-secret');
The client will find the correct endpoint automatically based on your id.
All methods are accessible from that client object:
// Get the client with id 133713371337 $client = $billomat->getClient(array( 'id' => 133713371337 )); // Create a new client $client = $billomat->createClient(array( 'client' => array( 'number' => 424242424242, 'name' => 'client-name' ) ));
Calling methods
All method names are based on the Billomat API URLs and follow the CRUD naming schema whenever possible.
All parameter names are exactly mapped. Therefore, you can refer to the official API documentation. Deep links to specific documentation sections are given in the extend of this client list above and the complete method reference list below.
Here is the user update method as an example for the client asset:
// Update a client $client = $billomat->updateClient(array( 'id' => 133713371337, 'client' => array( 'number' => 424242424242, 'name' => 'client-name' ) ));
Return values
All delete* methods return nothing.
The methods get*Pdf (when called with 'format' => 'pdf') and getTemplatePreview return a guzzle response. You can easily extract the file content:
// Fetch an invoice pdf file $response = $billomat->getInvoicePdf(array( 'id' => 133713371337, 'format' => 'pdf' )); $content = (string)$response->getBody();
All the other methods return array values.
Exception handling
This client creates exceptions from Billomat errors based on the HTTP status code and filled with the error message provided by the Billomat API.
All exceptions implement the Phobetor\Billomat\Exception\ExceptionInterface interface, so you can catch this to handle everything.
You can find all exceptions in the Phobetor\Billomat\Exception folder.
Usage example:
try { $client = $billomat->updateClient(array( 'id' => 133713371337, 'client' => array( 'number' => 424242424242, 'name' => 'client-name' ) )); } catch (\Phobetor\Billomat\Exception\NotFoundException $e) { // There seems to be no such client. } catch (\Phobetor\Billomat\Exception\BadRequestException $e) { // Some of the given data must have been bad. $e->getMessage() could help. } catch (\Phobetor\Billomat\Exception\TooManyRequestsException $e) { // The rate limit was reached. $e->getRateLimitReset() returns the UTC timestamp of the next rate limit reset. // @see http://www.billomat.com/en/api/basics/rate-limiting for details about the rate limit. } catch (\Phobetor\Billomat\ExceptionInterface $e) { // Something else failed. Maybe there is no connection to the API servers. }
Automatic rate limit handling
If this client is used in asynchronous processes or CLI commands you can activate automatic waiting for rate limit reset.
In that mode all method calls that would otherwise throw a \Phobetor\Billomat\Exception\TooManyRequestsException will wait for the rate limit reset and retry automatically.
You should not use this in synchronous request (e. g. a website request) because all method calls in that mode can last very long and most likely longer than your server’s request timeout.
There are two ways to do this.
At construction:
use Phobetor\Billomat\Client\BillomatClient; // setting the fifth parameter to true enables waiting for rate limit $billomat = new BillomatClient('my-id', 'my-api-key', 'my-api-app-id', 'my-api-app-secret', true);
After construction:
$billomat->setDoWaitForRateLimitReset(true);
Complete method reference
CLIENT RELATED METHODS doc:
- array getClients(array $args = array())
- array getClient(array $args = array())
- array getClientMyself(array $args = array())
- array createClient(array $args = array())
- array updateClient(array $args = array())
- void deleteClient(array $args = array())
CLIENT PROPERTY VALUE RELATED METHODS doc:
- array getClientPropertyValues(array $args = array())
- array getClientPropertyValue(array $args = array())
- array setClientPropertyValue(array $args = array())
ARTICLE RELATED METHODS doc:
- array getArticles(array $args = array())
- array getArticle(array $args = array())
- array createArticle(array $args = array())
- array updateArticle(array $args = array())
- void deleteArticle(array $args = array())
ARTICLE PROPERTY VALUE RELATED METHODS doc:
- array getArticlePropertyValues(array $args = array())
- array getArticlePropertyValue(array $args = array())
- array setArticlePropertyValue(array $args = array())
INVOICE RELATED METHODS doc:
- array getInvoices(array $args = array())
- array getInvoice(array $args = array())
- array createInvoice(array $args = array())
- array updateInvoice(array $args = array())
- array completeInvoice(array $args = array())
- \Guzzle\Http\Message\Response getInvoicePdf(array $args = array())
- array signInvoice(array $args = array())
- array sendInvoiceEmail(array $args = array())
- array cancelInvoice(array $args = array())
- array undoCancelInvoice(array $args = array())
- void deleteInvoice(array $args = array())
INVOICE ITEM RELATED METHODS doc:
- array getInvoiceItems(array $args = array())
- array getInvoiceItem(array $args = array())
- array createInvoiceItem(array $args = array())
- array updateInvoiceItem(array $args = array())
- void deleteInvoiceItem(array $args = array())
INVOICE PAYMENT RELATED METHODS doc:
- array getInvoicePayments(array $args = array())
- array getInvoicePayment(array $args = array())
- array createInvoicePayment(array $args = array())
- array deleteInvoicePayment(array $args = array())
INVOICE TAG RELATED METHODS doc:
- array getInvoiceTagCloud(array $args = array())
- array getInvoiceTags(array $args = array())
- array getInvoiceTag(array $args = array())
- array createInvoiceTag(array $args = array())
- array deleteInvoiceTag(array $args = array())
CREDIT NOTE RELATED METHODS doc:
- array getCreditNotes(array $args = array())
- array getCreditNote(array $args = array())
- array createCreditNote(array $args = array())
- array updateCreditNote(array $args = array())
- array completeCreditNote(array $args = array())
- \Guzzle\Http\Message\Response getCreditNotePdf(array $args = array())
- array signCreditNote(array $args = array())
- array sendCreditNoteEmail(array $args = array())
- void deleteCreditNote(array $args = array())
CREDIT NOTE ITEM RELATED METHODS doc:
- array getCreditNoteItems(array $args = array())
- array getCreditNoteItem(array $args = array())
- array createCreditNoteItem(array $args = array())
- array updateCreditNoteItem(array $args = array())
- void deleteCreditNoteItem(array $args = array())
CREDIT NOTE PAYMENT RELATED METHODS doc:
- array getCreditNotePayments(array $args = array())
- array getCreditNotePayment(array $args = array())
- array createCreditNotePayment(array $args = array())
- array deleteCreditNotePayment(array $args = array())
TEMPLATE RELATED METHODS doc:
- array getTemplates(array $args = array())
- array getTemplate(array $args = array())
- \Guzzle\Http\Message\Response getTemplatePreview(array $args = array())
- array createTemplate(array $args = array())
- array updateTemplate(array $args = array())
- void deleteTemplate(array $args = array())
ARTICLE PROPERTY RELATED METHODS doc:
- array getArticleProperties(array $args = array())
- array getArticleProperty(array $args = array())
- array createArticleProperty(array $args = array())
- array updateArticleProperty(array $args = array())
- void deleteArticleProperty(array $args = array())
CLIENT PROPERTY RELATED METHODS doc:
- array getClientProperties(array $args = array())
- array getClientProperty(array $args = array())
- array createClientProperty(array $args = array())
- array updateClientProperty(array $args = array())
- void deleteClientProperty(array $args = array())
USER PROPERTY RELATED METHODS doc:
- array getUserProperties(array $args = array())
- array getUserProperty(array $args = array())
- array createUserProperty(array $args = array())
- array updateUserProperty(array $args = array())
- void deleteUserProperty(array $args = array())
TAX RELATED METHODS doc:
- array getTaxes(array $args = array())
- array getTax(array $args = array())
- array createTax(array $args = array())
- array updateTax(array $args = array())
- void deleteTax(array $args = array())
COUNTRY TAX RELATED METHODS doc:
- array getCountryTaxes(array $args = array())
- array getCountryTax(array $args = array())
- array createCountryTax(array $args = array())
- array updateCountryTax(array $args = array())
- void deleteCountryTax(array $args = array())
REMINDER TEXT RELATED METHODS doc:
- array getReminderTexts(array $args = array())
- array getReminderText(array $args = array())
- array createReminderText(array $args = array())
- array updateReminderText(array $args = array())
- void deleteReminderText(array $args = array())
EMAIL TEMPLATE RELATED METHODS doc:
- array getEmailTemplates(array $args = array())
- array getEmailTemplate(array $args = array())
- array createEmailTemplate(array $args = array())
- array updateEmailTemplate(array $args = array())
- void deleteEmailTemplate(array $args = array())
USER PROPERTY VALUE RELATED METHODS doc:
- array getUserPropertyValues(array $args = array())
- array getUserPropertyValue(array $args = array())
- array setUserPropertyValue(array $args = array())
API glitches handled by this client internally
The Billomat API provides two data formats, xml and json. The json format is used here. Due to an xml to json conversion in the Billomat API lists have a data inconsistency in the json responses.
If there is ony one element in a list the API returns something like this:
array( 'clients' => array( 'client' => array( 'id' => 133713371337, /* […] */ ), ), )
If there are more elements in a list the API returns something like this:
array( 'clients' => array( 'client' => array( array( 'id' => 133713371337, /* […] */ ), array( 'id' => 133713371338, /* […] */ ), /* […] */ ), ), )
The type of $result['clients']['client'] changes from an associative array to a numeric array of associative arrays.
This issue is addressed by this client internally. You can be sure that lists are numeric arrays (like in the lower example) no matter how many elements are returned.
Advanced usage
This client is built on top of Guzzle, so you can take advantage of all its features. Please refer to the Guzzle documentation to learn more …
scratchy2/billomat 适用场景与选型建议
scratchy2/billomat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.3k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「invoice」 「billing」 「billomat」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 scratchy2/billomat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 scratchy2/billomat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 scratchy2/billomat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library for interacting with the Billomat REST API
Easy invoice generation using Laravel Eloquent
Laravel Cashier provides an expressive, fluent interface to Braintree's subscription billing services.
Metamel Addresses is a polymorphic Laravel package, for address book management. You can add addresses to any eloquent model with ease.
Laravel MPdf : Easily generate PDF files with arabic support
统计信息
- 总下载量: 17.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-21