siegerhansma / acumulus-php
Acumulus API 的 PHP 包装器
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: 4.1.*
Requires (Dev)
- evert/phpdoc-md: 0.0.*
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.1.*
This package is not auto-updated.
Last update: 2024-09-24 02:43:29 UTC
README
官方 Acumulus 文档:https://apidoc.sielsystems.nl/
此软件包使用 Guzzle 来对 Acumulus 进行 cUrl 请求。由于其对 Guzzle 的依赖,此软件包需要 PHP >= 5.4 才能运行。
安装
通过 composer
将软件包添加到您的 composer.json 文件中
"require": {
"siegerhansma/acumulus": "~1.0"
},
配置
所有提供者类都接受一个配置数组作为参数。
$config['contractcode'] = 123456;
$config['username'] = "xxxxxxxxx";
$config['password'] = "xxxxxxxxx";
您可以将这些变量放入特定的配置文件中。
用法
每个类和函数都在在线文档中有完整的文档这里。
请求
可以通过官方 API 文档中相应类别的特定类调用 API 中的调用。首先,创建您所需的提供者类的新实例。
$client = new \Siegerhansma\AcumulusPhp\Providers\ContactsProvider($config);
之后,该类中的所有调用都可通过 $client 变量访问。
$client->getContactDetails(14036242)->sendRequest();
当调用方法时,可以将 sendRequest 方法链到该方法上。此方法实际上将请求发送到 Acumulus API。其他提供者类也遵循相同的原理。
响应
sendRequest 方法返回 Acumulus 给出的响应。对于多记录,响应被转换为数组;对于单记录,转换为模型实例。
以下是一个 ContactsProvider 中 getAvailableContacts 方法的示例响应。
示例响应
array(3) {
[0] =>
class Siegerhansma\AcumulusPhp\Models\Contact#68 (27) {
protected $contactid =>
string(7) "1234567"
protected $contactname1 =>
string(13) "Contactname 1"
protected $contactname2 =>
NULL
protected $contacttypeid =>
string(1) "3"
protected $contacttypename =>
string(7) "Relatie"
protected $contactperson =>
NULL
protected $contactsalutation =>
NULL
protected $contactaddress1 =>
string(9) "Address 1"
protected $contactaddress2 =>
NULL
protected $contactpostalcode =>
NULL
protected $contactcity =>
string(10) "Leeuwarden"
protected $contactcountryid =>
NULL
protected $contactcountrycode =>
NULL
protected $contactcountryname =>
NULL
protected $contacttelephone =>
NULL
protected $contactfax =>
NULL
protected $contactemail =>
NULL
protected $contactwebsite =>
NULL
protected $contactbankaccountnumber =>
NULL
protected $contactiban =>
NULL
protected $contactbic =>
NULL
protected $contactmark =>
NULL
protected $contactvatnumber =>
NULL
protected $contactvatstandard =>
NULL
protected $contacttemplateid =>
NULL
protected $contactnotes =>
NULL
protected $contactstatus =>
NULL
}
[1] =>
class Siegerhansma\AcumulusPhp\Models\Contact#91 (27) {
protected $contactid =>
string(7) "3216549"
protected $contactname1 =>
string(13) "Contactname 2"
protected $contactname2 =>
NULL
protected $contacttypeid =>
string(1) "3"
protected $contacttypename =>
string(7) "Relatie"
protected $contactperson =>
NULL
protected $contactsalutation =>
NULL
protected $contactaddress1 =>
string(9) "Address 2"
protected $contactaddress2 =>
NULL
protected $contactpostalcode =>
NULL
protected $contactcity =>
string(8) "Drachten"
protected $contactcountryid =>
NULL
protected $contactcountrycode =>
NULL
protected $contactcountryname =>
NULL
protected $contacttelephone =>
NULL
protected $contactfax =>
NULL
protected $contactemail =>
NULL
protected $contactwebsite =>
NULL
protected $contactbankaccountnumber =>
NULL
protected $contactiban =>
NULL
protected $contactbic =>
NULL
protected $contactmark =>
NULL
protected $contactvatnumber =>
NULL
protected $contactvatstandard =>
NULL
protected $contacttemplateid =>
NULL
protected $contactnotes =>
NULL
protected $contactstatus =>
NULL
}
[2] =>
class Siegerhansma\AcumulusPhp\Models\Contact#69 (27) {
protected $contactid =>
string(5) "00001"
protected $contactname1 =>
string(13) "Contactname 3"
protected $contactname2 =>
NULL
protected $contacttypeid =>
string(1) "3"
protected $contacttypename =>
string(7) "Relatie"
protected $contactperson =>
NULL
protected $contactsalutation =>
NULL
protected $contactaddress1 =>
string(9) "Address 3"
protected $contactaddress2 =>
NULL
protected $contactpostalcode =>
NULL
protected $contactcity =>
NULL
protected $contactcountryid =>
NULL
protected $contactcountrycode =>
string(2) "NL"
protected $contactcountryname =>
NULL
protected $contacttelephone =>
NULL
protected $contactfax =>
NULL
protected $contactemail =>
NULL
protected $contactwebsite =>
NULL
protected $contactbankaccountnumber =>
NULL
protected $contactiban =>
NULL
protected $contactbic =>
NULL
protected $contactmark =>
NULL
protected $contactvatnumber =>
NULL
protected $contactvatstandard =>
NULL
protected $contacttemplateid =>
NULL
protected $contactnotes =>
NULL
protected $contactstatus =>
NULL
}
}
模型
对于从 Acumulus 获得的响应,使用了多个模型。这些模型是响应的完整副本,并具有自己的 getter 和 setter。有关所有模型及其可用方法的列表,请参阅 API 文档这里。
添加发票
此软件包最困难的任务之一是将发票添加到 Acumulus。我已尽量使其尽可能简单,但所进行的调用相当复杂。需要注意的是,Acumulus 将客户电子邮件地址视为客户的唯一标识符。因此,如果客户还没有电子邮件,此软件包将自动为该客户创建一个唯一的电子邮件地址,以防止创建多个客户。然而,在您进行此调用之前,建议您确保客户已有电子邮件。为了(希望)使您的工作更轻松,我创建了一个 InvoiceBuilder 类。以下是如何使用它的示例。
// Instantiate a new InvoiceBuilder object
$invoiceBuilder = new InvoiceBuilder;
// Create a new contact by instantiating a new Contact model or get it from the API
$builder = new \Siegerhansma\AcumulusPhp\ContactsProvider($config);
$contact = $builder->getContactDetails(123456)->sendRequest();
// Set the customer by passing in the Contact model
$invoiceBuilder->setCustomer($contact);
// Instantiate a new Invoice model and set Invoice specific settings
$invoice = new Invoice;
$invoice
->setTemplate('Standaard');
// Pass in the Invoice model
$invoiceBuilder->setInvoiceData($invoice);
// Create a new InvoiceLine object and set the fields
// Use this in a loop for multiple lines
$invoiceLine = new InvoiceLine;
$invoiceLine
->setItemnumber(102)
->setProduct("Awesome product")
->setUnitprice(19.95)
->setQuantity(3);
$invoiceBuilder->addLine($invoiceLine);
// Pass the InvoiceBuilder into the addInvoice method on the InvoicesProvider and call the build method on it
$invoiceSender = new \Siegerhansma\AcumulusPhp\InvoicesProvider($config);
$response = $invoiceSender->addInvoice($invoiceBuilder->build())->sendRequest();
从 Acumulus 的响应中,您将获得一个包含以下字段的数组
- 发票号
- 令牌
- 条目 ID
LICENSE
版权所有 (c) 2014 Sieger Hansma
以下是对任何获得此软件及其相关文档副本(“软件”)的人的授权,免费使用软件,不受限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向软件提供方提供软件的人行使其权利,但受以下条件约束
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
本软件按“原样”提供,不提供任何形式的保证,无论是明示的还是暗示的,包括但不限于适销性、适用于特定目的和不受侵犯的保证。在任何情况下,作者或版权持有人不对任何索赔、损害或其他责任负责,无论这些责任是基于合同、侵权或其他法律行为,是否与软件有关、使用软件或与软件的其他使用有关。
待办事项
还有很多工作要做,以下是具体内容
- 编写更多测试
- 制作文档
- 支持选择列表
如果您有任何问题、反馈或遇到错误,请留下问题或拉取请求。