lsolesen / billy-php-sdk
PHP-SDK,用于与Billy(http://www.billy.dk)通信
2.1.0
2016-04-17 07:24 UTC
Requires
- php: >=5.3.2
- lib/curl: *
Requires (Dev)
- php: >=5.5.0
- phpunit/phpunit: 4.4.*
- satooshi/php-coveralls: dev-master
- squizlabs/php_codesniffer: 2.*
This package is auto-updated.
Last update: 2024-08-25 00:16:01 UTC
README
仅适用于来自丹麦会计软件Billy API版本2的PHP SDK,由Billy提供。
入门
在开始之前,您应该注册Billy并获取访问凭证。
安装
Composer
如果您使用Composer来管理项目的依赖项,只需将lsolesen/billy-php-sdk添加到项目中的composer.json
文件即可。以下是一个composer.json文件的示例,仅定义了对Billy PHP SDK 2.1的依赖项。
{
"require": {
"lsolesen/billy-php-sdk": "2.1.*"
}
}
运行composer install
后,您可以使用位于vendor/autoload.php
中的Composer自动加载器。
使用方法
创建新客户端
首先,您应该创建一个客户端实例,该实例通过api_key
授权或由Billy提供。
<?php use Billy\Client\Client as Billy_Client; use Billy\Client\Request as Billy_Request; try { $request = new Billy_Request($api_key); $client = new Billy_Client($request); } catch (Exception $e) { //... } ?>
创建和更新联系人
<?php use Billy\Contacts\ContactRepository; try { // @todo: This will probably end up becoming an object of its own. $persons = array( array( 'name' => $name, 'email' => $email, ) ); $contact = new Contact(); $contact ->setName($name) ->set('phone', $phone) ->setCountryID($address['country']) ->set('street', $address['thoroughfare']) ->set('cityText', $address['locality']) ->set('stateText', $address['administrative_area']) ->set('zipcodeText', $address['postal_code']) ->set('contactNo', $profile_id) ->set('contactPersons', $persons); $repository = new ContactRepository($request); $created_contact = $repository->create($contact); $contact = $repository->getSingle($created_contact->getID()); $contact ->setName($new_name); $repository->update($contact); } catch (Exception $e) { //... } ?>
创建和更新产品
<?php use Billy\Products\ProductsRepository; try { $prices = array(); $prices[] = array( 'currencyId' => 'DKK', 'unitPrice' => '20.25', ); $product = new Product(); $product ->setAccount($billy_state_account_id) ->setProductNo($product_id) ->setSalesTaxRuleset($billy_vat_model_id) ->set('prices', $prices); $repository = new ProductRepository($request); $created_product = $repository->create($product); $product = $repository->getSingle($created_product->getID()); $product ->setName($new_name); $repository->update($product); } catch (Exception $e) { //... } ?>
创建发票
<?php use Billy\Invoices\InvoicesRepository; try { $invoice_line_items = array(); $invoice_line = new InvoiceLine(); $invoice_line->setProductID($product->getID()) ->setQuantity(4) ->set('priority', $priority) ->setDescription('My description') ->setUnitPrice(20.25); $invoice_line_items[] = $invoice_line->toArray(); $new_invoice = new Billy_Invoice(); $new_invoice->setType('invoice') ->setOrderNumber($order_number) ->setContactID($contact->getID()) ->setContactMessage($contact_message) ->setEntryDate($entry_date) ->setPaymentTermsDays(8) ->setCurrencyID('DKK') ->set('lines', $invoice_line_items); $created_invoice = $repository->create($new_invoice); $billy_invoice_id = $created_invoice->getID(); } catch (Exception $e) { //... } ?>