nexttalent / acumulus
Acumulus API 的 PHP 封装
Requires
- php: >=5.6.0
- guzzlehttp/guzzle: ^6.3.0
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-18 08:12:44 UTC
README
官方 Acumulus 文档: https://apidoc.sielsystems.nl/
由 siegerhansma/acumulus-php 分支而来
此包使用 Guzzle 向 Acumulus 发送 cUrl 请求。由于对 Guzzle 的依赖,此包需要 PHP >= 5.6 才能运行。
安装
通过 composer
将包添加到您的 composer.json 文件中
"require": {
"thalent/acumulus": "~2.0"
},
配置
所有提供者类都接受一个配置数组作为参数。
$config['contractcode'] = 123456;
$config['username'] = "xxxxxxxxx";
$config['password'] = "xxxxxxxxx";
您可以将这些变量放入特定的配置文件中。
请求
您可以通过官方 API 文档中的类别对应的具体类来调用 API 中的调用。首先,创建您需要的提供者类的新实例。
$client = new \Thalent\AcumulusPhp\Providers\ContactsProvider($config);
之后,该类中的所有调用都可通过 $client 变量访问。
$client->getContactDetails(14036242)->sendRequest();
当调用方法时,您可以将 sendRequest 方法链到该方法上。此方法实际上会将请求发送到 Acumulus API。其他提供者类也遵循相同的原则。
响应
sendRequest 方法返回 Acumulus 给出的响应。响应被转换为数组以表示多个记录,或转换为单个记录的模型实例。
以下示例显示了 ContactsProvider 上的 getAvailableContacts 方法的响应。
示例响应
array(3) {
[0] =>
class Thalent\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 Thalent\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 Thalent\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 \Thalent\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 \Thalent\AcumulusPhp\InvoicesProvider($config);
$response = $invoiceSender->addInvoice($invoiceBuilder->build())->sendRequest();
从 Acumulus 的响应中,您将获得以下字段的数组
- invoicenumber
- token
- entryid
TODO
还有很多工作要做,以下是一些
- 编写更多测试
- 制作文档
- 支持 Picklists
如果您有任何问题、反馈或遇到错误,请留下问题或拉取请求。