abb/fakturownia

Fakturownia API 的 PHP 客户端

1.6.0 2021-07-24 17:41 UTC

This package is auto-updated.

Last update: 2024-09-24 13:35:11 UTC


README

Fakturownia (InvoiceOcean) API 的 PHP 客户端 (fakturownia.pl, invoiceocean.com).

要求

  • PHP 7.1 或更高版本,并启用 curl 和 json 扩展。

安装

建议通过 Composer 进行安装。

$ composer require abb/fakturownia

支持的 API 令牌

Fakturownia.pl 提供两种类型的令牌 - 带前缀(即带有您的子域)和不带前缀。仅支持 带前缀的令牌。您可以在 fakturownia.pl 服务中生成它(设置 -> 账户设置 -> 集成 -> 显示 ApiTokens -> 添加新令牌 -> 类型:带前缀的令牌)。

可用方法

  • login(string $login, string $password)
  • getInvoices(array $params = [])
  • getInvoice(int $id)
  • getInvoicePdf(int $id, string $printOption = null)
  • createInvoice(array $invoice)
  • updateInvoice(int $id, array $invoice)
  • deleteInvoice(int $id)
  • sendInvoice(int $id)
  • changeInvoiceStatus(int $id, $status)
  • getRecurringInvoices(array $params = [])
  • createRecurringInvoice(array $recurringInvoice)
  • updateRecurringInvoice(int $id, array $recurringInvoice)
  • getClients(array $params = [])
  • getClient(int $id)
  • getClientByExternalId(int $id)
  • createClient(array $client)
  • updateClient(int $id, array $client)
  • getProducts(array $params = [])
  • getProduct(int $id, int $warehouseId = null)
  • createProduct(array $product)
  • updateProduct(int $id, array $product)
  • getWarehouseDocuments(array $params = [])
  • getWarehouseDocument(int $id)
  • createWarehouseDocument(array $warehouseDocument)
  • updateWarehouseDocument(int $id, array $warehouseDocument)
  • deleteWarehouseDocument(int $id)
  • getWarehouses(array $params = [])
  • getWarehouse(int $id)
  • createWarehouse(array $warehouse)
  • updateWarehouse(int $id, array $warehouse)
  • deleteWarehouse(int $id)
  • getCategories(array $params = [])
  • getCategory(int $id)
  • createCategory(array $category)
  • updateCategory(int $id, array $category)
  • deleteCategory(int $id)
  • getAccount()
  • createAccountForClient(array $account, array $user = [], array $company = [])
  • getPayments(array $params = [])
  • getPayment(int $id, array $params = [])
  • createPayment(array $payment)
  • updatePayment(int $id, array $payment)
  • deletePayment(int $id)
  • getDepartments(array $params = [])
  • getDepartment(int $id)
  • createDepartment(array $department)
  • updateDepartment(int $id, array $department)
  • deleteDepartment(int $id)
  • getPriceLists(array $params = [])
  • createPriceList(array $priceList)
  • updatePriceList(int $id, array $priceList)
  • deletePriceList(int $id)

用法示例

示例 1 - 获取发票

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$response = $fakturownia->getInvoices();
if ($response->isSuccess()) { // check response status before you retrieve data
    $invoices = $response->getData();
} else {
    $errors = $response->getData();
}

示例 2 - 根据参数获取发票

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$params = [
    'period' => 'this_month',
    'page' => '1',
];
$invoices = $fakturownia->getInvoices($params)->getData();

示例 3 - 通过 ID 获取发票

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceId = 123456;
$invoice = $fakturownia->getInvoice($invoiceId)->getData();

示例 3.1 - 通过 ID 获取发票作为 PDF

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceId = 123456;
$printOption = 'duplicate';
$pdfContent = $fakturownia->getInvoicePdf($invoiceId, $printOption)->getData()['content'];
file_put_contents('/path/to/invoice.pdf', $pdfContent);

示例 4 - 创建发票

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceData = [
    'kind' => 'vat',
    'number' => null,
    'sell_date' => '2013-01-16',
    'issue_date' => '2013-01-16',
    'payment_to' => '2013-01-23',
    'seller_name' => 'Wystawca Sp. z o.o.',
    'seller_tax_no' => '5252445767',
    'buyer_name' => 'Klient1 Sp. z o.o.',
    'buyer_email' => 'buyer@testemail.pl',
    'buyer_tax_no' => '5252445767',
    'positions' => [
        [
            'name' => 'Produkt A1',
            'tax' => 23,
            'total_price_gross' => 10.23,
            'quantity' => 1,
        ],
        [
            'name' => 'Produkt A2',
            'tax' => 0,
            'total_price_gross' => 50,
            'quantity' => 3,
        ],
    ],
];
$createdInvoice = $fakturownia->createInvoice($invoiceData)->getData();

示例 5 - 创建发票并通过电子邮件发送给客户

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceData = [
    'buyer_email' => 'buyer@testemail.pl',
    // ...
];
$response = $fakturownia->createInvoice($invoiceData);
if ($response->isSuccess()) {
    $createdInvoice = $response->getData();
    $fakturownia->sendInvoice($createdInvoice['id']); // Invoice will be sent to buyer_email
}

示例 6 - 更新发票

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceId = 123456;
$invoiceData = [
    'buyer_name' => 'Nowa nazwa klienta Sp. z o.o.',
    'positions' =>  [
        [
            'id' => 32649087,
            'name' => 'Nowa nazwa pozycji na fakturze',
        ],
    ],
];
$updatedInvoice = $fakturownia->updateInvoice($invoiceId, $invoiceData)->getData();

示例 7 - 删除发票

$fakturownia = new \Abb\Fakturownia\Fakturownia('fakturownia_api_token');
$invoiceId = 123456;
$result = $fakturownia->deleteInvoice($invoiceId)->getData();

有关每个方法所需参数的更多信息: PL | EN.

更新日志

更改日志可在此处找到。