talent / 积雪
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-15 02:43:10 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
还有很多工作要做,以下是一些内容
- 编写更多测试
- 制作文档
- 支持选择列表
如果您有任何问题、反馈或遇到错误,请提交问题或拉取请求。