apextechnology/tidybill 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

apextechnology/tidybill

Composer 安装命令:

composer require apextechnology/tidybill

包简介

PHP SDK for the TidyBill invoicing API — create invoices, manage line items, and fetch clients. Works with any PHP project; optional Laravel support via service provider.

README 文档

README

A framework-agnostic PHP SDK for the TidyBill invoicing API. Provides a typed client with DTOs for creating invoices, managing line items, and fetching clients. Works in any PHP project; Laravel users get an optional service provider via auto-discovery.

Requirements

  • PHP ^8.2
  • ext-json
  • guzzlehttp/guzzle ^7.0

Installation

composer require apextechnology/tidybill

Plain PHP usage

use ApexTechnology\TidyBill\TidyBillClient;

$client = new TidyBillClient(
    token: 'your-api-token',
    companyId: 'your-company-id',
    baseUrl: 'https://tidybill.app', // optional, this is the default
);

You can also pass a custom GuzzleHttp\ClientInterface as the fourth argument for testing or advanced configuration:

use GuzzleHttp\Client;

$client = new TidyBillClient(
    token: 'your-api-token',
    companyId: 'your-company-id',
    httpClient: new Client(['timeout' => 10]),
);

Laravel usage

Laravel's package auto-discovery registers the service provider automatically. Publish the config file:

php artisan vendor:publish --tag=tidybill-config

This creates config/tidybill.php. Set the following environment variables:

TIDYBILL_TOKEN=your-api-token
TIDYBILL_COMPANY_ID=your-company-id
TIDYBILL_BASE_URL=https://tidybill.app

Resolve the client from the container:

use ApexTechnology\TidyBill\TidyBillClient;

$client = app(TidyBillClient::class);

Or inject it via the constructor in any Laravel service or controller.

Usage

Creating an invoice

use ApexTechnology\TidyBill\DTOs\CreateInvoiceData;
use ApexTechnology\TidyBill\DTOs\LineItemData;

$invoice = $client->createInvoice(new CreateInvoiceData(
    clientId: '42',
    issueDate: '2026-05-01',
    currency: 'ZAR',
    notes: 'Net 30',
    lineItems: [
        new LineItemData(description: 'API usage', quantity: 100, unitPrice: 1.50),
        new LineItemData(description: 'Support hours', quantity: 2, unitPrice: 350.00),
    ],
));

echo $invoice->id;     // int
echo $invoice->status; // 'draft'
echo $invoice->total;  // float (in the currency's major unit)

Adding line items to an existing invoice

use ApexTechnology\TidyBill\DTOs\LineItemData;

// Single item
$lineItem = $client->addLineItem(invoiceId: $invoice->id, item: new LineItemData(
    description: 'Extra usage',
    quantity: 50,
    unitPrice: 0.80,
));

// Multiple items (sequential API calls)
$results = $client->addLineItems(invoiceId: $invoice->id, items: [
    new LineItemData(description: 'Item A', quantity: 1, unitPrice: 100.00),
    new LineItemData(description: 'Item B', quantity: 3, unitPrice: 25.00),
]);

Fetching invoices

// All invoices (with optional filters)
$invoices = $client->getInvoices(['status' => 'draft', 'client_id' => '42']);

// Single invoice
$invoice = $client->getInvoice(id: 123);

// Update an invoice
$updated = $client->updateInvoice(id: 123, data: ['notes' => 'Updated terms']);

Managing line items

// Update a line item
$client->updateLineItem(invoiceId: 123, lineItemId: 10, item: new LineItemData(
    description: 'Revised description',
    quantity: 5,
    unitPrice: 2.00,
));

// Delete a line item
$client->deleteLineItem(invoiceId: 123, lineItemId: 10);

Fetching clients

// All clients
$clients = $client->getClients();

// Single client
$clientData = $client->getClient(id: '42');

echo $clientData->name;  // string
echo $clientData->email; // ?string
echo $clientData->id;    // string

E-invoicing

TidyBill generates and validates structured e-invoice documents from your invoices: ZUGFeRD / Factur-X (EN 16931) and UBL Peppol BIS Billing 3.0. These methods drive that generation and validation via the TidyBill API. They do not transmit invoices on the Peppol network; TidyBill produces the compliant document and you retrieve it.

use ApexTechnology\TidyBill\Enums\EInvoiceFormat;

// Status of e-invoice generation for an invoice
$status = $client->getEInvoiceStatus(invoiceId: 123);
echo $status->enabled ? 'on' : 'off';        // bool
echo $status->format?->value;                // ?EInvoiceFormat ('zugferd_en16931' | 'ubl_peppol_bis3')
echo $status->generatedAt ?? 'not generated'; // ?string
$status->warnings;                            // array
$status->hasXml;                              // bool

// Download the generated XML (raw application/xml body).
// Throws TidyBillNotFoundException if no XML has been generated.
$xml = $client->downloadEInvoiceXml(invoiceId: 123); // string

// Validate an invoice against the target format without generating
$preview = $client->previewEInvoice(invoiceId: 123);
$preview->valid;  // bool
$preview->issues; // array of issue objects

// Company-level settings (uses the client's configured company ID)
$company = $client->getCompanyEInvoiceSettings();
echo $company->format->value; // EInvoiceFormat

$client->updateCompanyEInvoiceSettings([
    'enabled' => true,
    'format'  => EInvoiceFormat::ZugferdEn16931->value,
    'vat_id'  => 'GB123456789',
    'electronic_address_scheme' => '0088',
    'electronic_address'        => '7300010000001',
    'tax_registration_number'   => 'TRN-1',
]);

// Client-level settings (enabled = null inherits the company setting)
$clientSettings = $client->getClientEInvoiceSettings(clientId: '42');

$client->updateClientEInvoiceSettings('42', [
    'enabled'                 => true,
    'vat_id'                  => 'GB999',
    'buyer_reference_default' => 'PO-1234',
    'electronic_address_scheme' => '0088',
    'electronic_address'        => '5790000435975',
    'tax_registration_number'   => 'TRN-9',
]);

EInvoiceFormat cases: EInvoiceFormat::ZugferdEn16931 ('zugferd_en16931') and EInvoiceFormat::UblPeppolBis3 ('ubl_peppol_bis3').

Error handling

use ApexTechnology\TidyBill\Exceptions\TidyBillAuthException;
use ApexTechnology\TidyBill\Exceptions\TidyBillNotFoundException;
use ApexTechnology\TidyBill\Exceptions\TidyBillException;

try {
    $invoice = $client->getInvoice(999);
} catch (TidyBillNotFoundException $e) {
    // 404: invoice does not exist
    echo $e->getMessage();
    echo $e->statusCode;
} catch (TidyBillAuthException $e) {
    // 401 / 403: invalid token or insufficient permissions
} catch (TidyBillException $e) {
    // Any other API error (5xx, etc.)
    // $e->responseBody contains the raw response array
}

DTO reference

CreateInvoiceData

Property Type Default Description
clientId string required TidyBill client ID
issueDate string required ISO 8601 date (e.g. 2026-05-01)
currency string 'ZAR' ISO 4217 currency code
notes ?string null Optional invoice notes
lineItems LineItemData[] [] Line items to include on creation

LineItemData

Property Type Description
description string Line item description
quantity int Number of units
unitPrice float Price per unit in the invoice currency (e.g. 1.50 for R1.50)

Unit prices are converted to integer cents before being sent to the API.

InvoiceResult

Property Type Description
id int Invoice ID
clientId string Client ID
status string Invoice status
issueDate string Issue date
currency string Currency code
total float Invoice total
lineItems array Raw line items from the API
raw array Full raw response

LineItemResult

Property Type Description
id int Line item ID
description string Description
quantity int Quantity
unitPrice float Unit price in currency's major unit
total float Line item total

ClientData

Property Type Description
id string Client ID
name string Client name
email ?string Client email
raw array Full raw response

License

MIT

apextechnology/tidybill 适用场景与选型建议

apextechnology/tidybill 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 154 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 apextechnology/tidybill 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-18