friendsofapi / billogram
Billogram v2 API 连接库
2.0.0-alpha2
2017-08-27 17:28 UTC
Requires
- php: ^7.0
- php-http/client-common: ^1.5
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/httplug: ^1.0
- php-http/message-factory: ^1.0
- php-http/multipart-stream-builder: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.3
- nyholm/nsa: ^1.0
- php-http/curl-client: ^1.6
- php-http/message: ^1.0
- php-http/message-factory: ^1.0
- php-http/mock-client: ^1.0
- phpunit/phpunit: ^6.2
This package is auto-updated.
Last update: 2024-08-29 03:23:56 UTC
README
这个 Billogram 分支创建是为了我们想要一个遵循 PHP 标准的现代 API 客户端。我们尝试改进原始库,但这些努力很快就被停止了。这个分支将永远存在。
安装
composer require friendsofapi/billogram php-http/guzzle6-adapter php-http/message
为什么使用 php-http/guzzle6-adapter php-http/message
?我们在 HTTPlug 的帮助下与任何 HTTP 消息客户端解耦。在 HTTPlug 文档 中了解有关客户端的更多信息。
用法
首先,您需要注册一个账户。建议您在 Billogram 沙箱环境中注册 沙箱 Billogram 或在 Billogram 上注册,然后生成一个 API 用户。
身份验证
在您生成 API 用户后,您需要创建一个 BillogramClient,并将您的用户名和密码传递给工厂函数。
$billogram = BillogramClient::create($username, $apikey);
创建客户
use Billogram\Model\Customer\CustomerContact; use Billogram\Model\Customer\CustomerBillingAddress; use Billogram\Model\Customer\CustomerDeliveryAddress; use Billogram\Model\Customer\Customer; $contact = CustomerContact::createFromArray(['name' => 'ib92g', 'email' => 'ib922@gmail.com', 'phone' => '0712223344']); $addressCustomer = CustomerBillingAddress::createFromArray(['careof' => 'ibrahim', 'use_careof_as_attention' => false, 'street_address' => 'Flygarvägen 189B', 'zipcode' => '175 69', 'city' => 'Järfälla', 'country' => 'SE']); $addressDelivery = CustomerDeliveryAddress::createFromArray(['name' => 'ibrahim', 'street_address' => 'Flygarvägen 189B', 'careof' => 'ibrahim', 'zipcode' => '175 69', 'city' => 'Järfälla', 'country' => 'SE']); $customer = new Customer(); $customer = $customer->withCustomerNo(1); $customer = $customer->withName('Ibrahim AA'); $customer = $customer->withNotes('aa'); $customer = $customer->withOrgNo('556801-7155'); $customer = $customer->withVatNo('SE556677889901'); $customer = $customer->withContact($contact); $customer = $customer->withAddress($addressCustomer); $customer = $customer->withDeliveryAddress($addressDelivery); $customer = $customer->withCompanyType('individual'); $customer = $billogram->customers()->create($customer->toArray());
获取客户
$customer = $billogram->customers()->fetch($customerNo);
创建项目
use Billogram\Model\Item\Bookkeeping; use Billogram\Model\Item\Item; $bookkeeping = Bookkeeping::createFromArray(['income_account' => '302', 'vat_account' => '303']); $item = new Item(); $item = $item->withTitle('cc'); $item = $item->withDescription('cc'); $item = $item->withPrice(12); $item = $item->withVat(12); $item = $item->withUnit('hour'); $item = $item->withBookkeeping($bookkeeping); $item = $billogram->items()->create($item->toArray());
获取项目
$items = $billogram->items()->search(['page' => 1]);
删除项目
$billogram->items()->delete($itemNo);
创建发票
我们认为您已经创建了一个客户和一个项目(请参阅上面的文档),然后您将使用它们来创建一个新的发票
use Billogram\Model\Invoice\Item; use Billogram\Model\Invoice\Invoice; // ... $itemOfinvoice = new Item(); $itemOfinvoice = $itemOfinvoice->withItemNo($itemFetched->getItemNo()); $itemOfinvoice = $itemOfinvoice->withCount(2) $itemOfinvoice = $itemOfinvoice->withDiscount(1) $invoice = new Invoice(); $invoice = $invoice->withCustomer($customer); $invoice = $invoice->withItems([$itemOfinvoice]); $invoice = $invoice->withInvoiceDate('2013-11-14'); $invoice = $billogram->invoices()->create($invoice->toArray());
API 文档
如果您想了解 API 的更多信息,请从 Billogram API 文档 开始。
贡献
您想做出改变吗?欢迎提交拉取请求。