定制 bennetgallein/billomat-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bennetgallein/billomat-client

Composer 安装命令:

composer require bennetgallein/billomat-client

包简介

PHP library for interacting with the Billomat REST API

README 文档

README

Latest Stable Version License

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:

Dependencies

Installation via composer

composer require bennetgallein/billomat-client

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 are GuzzleHttp\Command\Exception\CommandException and contain a Phobetor\Billomat\Exception\ExceptionInterface as $e->getPrevious(), 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 (GuzzleHttp\Command\Exception\CommandException $e) {
    switch (get_class($e->getPrevious())) {
        case \Phobetor\Billomat\Exception\NotFoundException::class:
            // There seems to be no such client.
            break;
        case \Phobetor\Billomat\Exception\BadRequestException::class:
            // Some of the given data must have been bad. $e->getMessage() could help.
            breaK;
        case \Phobetor\Billomat\Exception\TooManyRequestsException::class:
            // 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.
            breaK;
        default:
            // Something else failed. Maybe there is no connection to the API servers.
            break;
    }
}

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 getClient(array $args = [])
  • array getClientMyself(array $args = [])
  • array createClient(array $args = [])
  • array updateClient(array $args = [])
  • void deleteClient(array $args = [])

CLIENT PROPERTY VALUE RELATED METHODS doc:

  • array getClientPropertyValues(array $args = [])
  • array getClientPropertyValue(array $args = [])
  • array setClientPropertyValue(array $args = [])

ARTICLE RELATED METHODS doc:

  • array getArticles(array $args = [])
  • array getArticle(array $args = [])
  • array createArticle(array $args = [])
  • array updateArticle(array $args = [])
  • void deleteArticle(array $args = [])

ARTICLE PROPERTY VALUE RELATED METHODS doc:

  • array getArticlePropertyValues(array $args = [])
  • array getArticlePropertyValue(array $args = [])
  • array setArticlePropertyValue(array $args = [])

INVOICE RELATED METHODS doc:

  • array getInvoices(array $args = [])
  • array getInvoice(array $args = [])
  • array createInvoice(array $args = [])
  • array updateInvoice(array $args = [])
  • array completeInvoice(array $args = [])
  • \Guzzle\Http\Message\Response getInvoicePdf(array $args = [])
  • array signInvoice(array $args = [])
  • array sendInvoiceEmail(array $args = [])
  • array cancelInvoice(array $args = [])
  • array undoCancelInvoice(array $args = [])
  • void deleteInvoice(array $args = [])

INVOICE ITEM RELATED METHODS doc:

  • array getInvoiceItems(array $args = [])
  • array getInvoiceItem(array $args = [])
  • array createInvoiceItem(array $args = [])
  • array updateInvoiceItem(array $args = [])
  • void deleteInvoiceItem(array $args = [])

INVOICE PAYMENT RELATED METHODS doc:

  • array getInvoicePayments(array $args = [])
  • array getInvoicePayment(array $args = [])
  • array createInvoicePayment(array $args = [])
  • array deleteInvoicePayment(array $args = [])

INVOICE TAG RELATED METHODS doc:

  • array getInvoiceTagCloud(array $args = [])
  • array getInvoiceTags(array $args = [])
  • array getInvoiceTag(array $args = [])
  • array createInvoiceTag(array $args = [])
  • array deleteInvoiceTag(array $args = [])

CREDIT NOTE RELATED METHODS doc:

  • array getCreditNotes(array $args = [])
  • array getCreditNote(array $args = [])
  • array createCreditNote(array $args = [])
  • array updateCreditNote(array $args = [])
  • array completeCreditNote(array $args = [])
  • \Guzzle\Http\Message\Response getCreditNotePdf(array $args = [])
  • array signCreditNote(array $args = [])
  • array sendCreditNoteEmail(array $args = [])
  • void deleteCreditNote(array $args = [])

CREDIT NOTE ITEM RELATED METHODS doc:

  • array getCreditNoteItems(array $args = [])
  • array getCreditNoteItem(array $args = [])
  • array createCreditNoteItem(array $args = [])
  • array updateCreditNoteItem(array $args = [])
  • void deleteCreditNoteItem(array $args = [])

CREDIT NOTE PAYMENT RELATED METHODS doc:

  • array getCreditNotePayments(array $args = [])
  • array getCreditNotePayment(array $args = [])
  • array createCreditNotePayment(array $args = [])
  • array deleteCreditNotePayment(array $args = [])

TEMPLATE RELATED METHODS doc:

  • array getTemplates(array $args = [])
  • array getTemplate(array $args = [])
  • \Guzzle\Http\Message\Response getTemplatePreview(array $args = [])
  • array createTemplate(array $args = [])
  • array updateTemplate(array $args = [])
  • void deleteTemplate(array $args = [])

ARTICLE PROPERTY RELATED METHODS doc:

  • array getArticleProperties(array $args = [])
  • array getArticleProperty(array $args = [])
  • array createArticleProperty(array $args = [])
  • array updateArticleProperty(array $args = [])
  • void deleteArticleProperty(array $args = [])

CLIENT PROPERTY RELATED METHODS doc:

  • array getClientProperties(array $args = [])
  • array getClientProperty(array $args = [])
  • array createClientProperty(array $args = [])
  • array updateClientProperty(array $args = [])
  • void deleteClientProperty(array $args = [])

USER PROPERTY RELATED METHODS doc:

  • array getUserProperties(array $args = [])
  • array getUserProperty(array $args = [])
  • array createUserProperty(array $args = [])
  • array updateUserProperty(array $args = [])
  • void deleteUserProperty(array $args = [])

TAX RELATED METHODS doc:

  • array getTaxes(array $args = [])
  • array getTax(array $args = [])
  • array createTax(array $args = [])
  • array updateTax(array $args = [])
  • void deleteTax(array $args = [])

COUNTRY TAX RELATED METHODS doc:

  • array getCountryTaxes(array $args = [])
  • array getCountryTax(array $args = [])
  • array createCountryTax(array $args = [])
  • array updateCountryTax(array $args = [])
  • void deleteCountryTax(array $args = [])

REMINDER TEXT RELATED METHODS doc:

  • array getReminderTexts(array $args = [])
  • array getReminderText(array $args = [])
  • array createReminderText(array $args = [])
  • array updateReminderText(array $args = [])
  • void deleteReminderText(array $args = [])

EMAIL TEMPLATE RELATED METHODS doc:

  • array getEmailTemplates(array $args = [])
  • array getEmailTemplate(array $args = [])
  • array createEmailTemplate(array $args = [])
  • array updateEmailTemplate(array $args = [])
  • void deleteEmailTemplate(array $args = [])

USER PROPERTY VALUE RELATED METHODS doc:

  • array getUserPropertyValues(array $args = [])
  • array getUserPropertyValue(array $args = [])
  • array setUserPropertyValue(array $args = [])

SUPPLIER RELATED METHODS doc:

  • array getSupplier(array $args = [])
  • array getSuppliers(array $args = [])

INCOMING INVOICES doc:

  • array getIncomings(array $args = [])
  • array getIncomingPdf(array $args = [])

INCOMING INVOICE TAGS doc:

  • array createIncomingTag(array $args = [])

INCOMING PAYMENTS doc:

  • array createIncomingPayment(array $args = [])

INCOMING DOCUMENTS doc:

  • array createIncomingInboxDocument(array $args = [])

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 …

bennetgallein/billomat-client 适用场景与选型建议

bennetgallein/billomat-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.25k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「invoice」 「billing」 「billomat」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bennetgallein/billomat-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bennetgallein/billomat-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 bennetgallein/billomat-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-06