klapuch/fakturoid-api

Fakturoid PHP 库

dev-master 2016-08-17 09:19 UTC

This package is auto-updated.

Last update: 2024-09-21 20:18:32 UTC


README

用于 Fakturoid.cz 的 PHP 库。请参阅 API 了解更多文档。强烈建议仅用于测试 API 和使用独立用户(通过 "设置 > 用户和权限" 创建)来使用新账户。

用法

require_once '/path/to/lib/Fakturoid.php';
$f = new Fakturoid('..subdomain..', '..user@email.cz..', '..api_key..', 'PHPlib <your@email.cz>');

// create subject
$subject = $f->create_subject(array('name' => 'Firma s.r.o.', 'email' => 'aloha@pokus.cz'));

// create invoice with lines
$lines   = array(array('name' => 'Big sale', 'quantity' => 1, 'unit_price' => 1000));
$invoice = $f->create_invoice(array('subject_id' => $subject->id, 'lines' => $lines));

// send created invoice
$f->fire_invoice($invoice->id, 'deliver');

// to mark invoice as paid
$f->fire_invoice($invoice->id, 'pay'); // or 'pay_proforma' for paying proforma and 'pay_partial_proforma' for partial proforma

错误处理

如果服务器返回 4xx5xx 状态码,库将抛出 FakturoidException。您可以通过调用 getCode()getMessage() 来获取响应码和响应体。

try {
  $subject = $f->create_subject(array('name' => '', 'email' => 'aloha@pokus.cz'));
} catch (FakturoidException $e) {
  $e->getCode(); // 422
  $e->getMessage(); // '{"errors":{"name":["je povinná položka","je příliš krátký/á/é (min. 2 znaků)"]}}'
}

常见问题

  • 确保 curl 已安装证书 - 要么在 php.ini 中全局设置,要么调用 curl_setopt($ch, CURLOPT_CAINFO, "/path/to/cacert.pem")
  • 如果遇到问题,请通过 podpora@fakturoid.cz 联系我们的发票机器人