eelzee/intacct_integration

Intacct(https://us.intacct.com/)集成库。专为Drupal使用构建

此包的规范存储库似乎已丢失,因此包已冻结。

1.2.0 2017-03-16 01:34 UTC

This package is auto-updated.

Last update: 2019-01-31 03:53:21 UTC


README

概述

此包提供对IntAcct xml web api的PHP接口。它提供一系列命名空间类,在调用时,将允许模块实现者轻松地对其远程Intacct数据库进行操作。

该模块构建为异步,但目前同步操作直到可以更全面地测试。此模块处于预alpha发布阶段。

如前所述,这是一个部分实现。我们希望在这个开源工作的过程中,我们可以更全面地覆盖Intacct方法,同时为开源社区的其他人提供便利。不用说,但使用此模块,您必须已经有一个付费的Intacct账户。

要求

此模块需要本地安装composer和git。由于某些包依赖项,它还需要php 5.6或更高版本。

安装

  1. Intacct获取必要的账户和凭证。没有他们的账户,此模块毫无用处。
  2. 在您的项目中执行composer require eelzee/intacct_integration
  3. 一旦composer安装完成
    1. 如果独立运行:将安装的composer包中的文件intacct_configuration.example.yml复制到同一位置的intacct_configuration.yml,并在其中配置设置以适应您的安装。
    2. 如果使用Drupal:将安装的composer包根目录中的文件intacct_configuration.example.yml复制到private:///intacct_configuration.yml(其中'private://'是您的Drupal私有文件目录),并在其中配置设置以适应您的安装。

使用方法

在进入任何示例之前,值得谈谈API中看到的通用模式。

Intacct集成API的通用模式

所有处理方法都是静态的

每个创建方法都是静态的,因此要发出调用,您只需找到合适的静态方法,并用一组或两组数据调用它。第一个数据数组将始终是您打算填充请求的结构化数据。第二个不常用,但它影响数据的处理方式。

所有处理方法返回一个响应对象

每个创建方法都返回一个响应对象,其中包含详细响应数据的、响应成功的方法,以及一个名为'then'的方法,允许将响应链接到另一个调用。

所有处理方法都是可连接的

then方法接受一个参数,即实现响应接口的对象。我们使用isSuccessful方法(主要评估通信成功)测试响应成功,然后我们可以根据需要采取其他措施来处理响应。在这种情况下,我们只想断言响应成功。如果不成功,PHPUnit套件中的fail方法将生成一个错误消息,其中包含生成的请求和响应xml,它构成了请求。

API文档

此模块依赖于phpDocumentor来提供API文档。这尚未包含在存储库中 - 如果您需要此

  1. 请确保您的系统已安装phpdoc。
  2. 导航到composer包的根目录(vendor/eelzee/intacct_integration)。
  3. 在'src'文件夹上运行工具,指定文档的输出目录,例如:phpdoc -d src -t api_documentation
  4. 在浏览器中打开文档。示例文档的索引页面位于(从composer根目录开始)vendor/eelzee/intacct_integration/api_documentation/index.html

示例

示例1:创建一个类

vendor/eelzee/intacct_integration/tests文件夹中存在一些PHPUnit测试,它们也很好地充当示例。让我们从一个简单的测试开始,它来自tests/IntacctObject/IntacctClassTest.php

  /**
   * Standardizes the data used for the tests.
   */
  public static function getMockData() {
    $data = [
      // NOTE: should ultimately correspond to Drupal node id.
      'CLASSID' => 'TEST' . uniqid(),
      // NOTE: should ultimately correspond to Vehicle VIN.
      'NAME' => 'TEST' . uniqid(),
      // (Vehicle Year Make Model)
      'DESCRIPTION' => date('Y') . ' Dummy Class',
    ];
    return $data;
  }

  /**
   * Tests the createClass operation.
   *
   * @group active
   *
   * @return array
   *   An array consisting of two elements:
   *   0: The array defining the data used to construct the class object.
   *   1: The response object from the create operation, or NULL if the
   *   response failed.
   */
  public function testCreate() {
    static $test_name = "Testing create class";
    $vehicle_info = self::getMockData();
    $response = IntacctClass::create($vehicle_info)
      ->then(function (IntacctResponseInterface $response) {
        if (!$response->isSuccessful()) {
          $this->fail(sprintf("Cannot continue.  Errors: %s\n\nrequest xml: %s\n\nresponse xml: %s", print_r($response->getErrors(), TRUE), $response->getRequestXml(), $response->getResponseXml()));
          return NULL;
        }
        return $response;
      });
    Utilities::handleResponse($this, $response, $test_name);

    return $response;
  }

第一个方法是getMockData,它简单地返回一个数组,其中键对应于您将传递给Intacct API中类对象的Create_class方法的字段。这样做是为了在测试之间获得一致的创建测试数据。

第二个方法是phpunit测试,它调用Intacct API以创建新的类对象。您可以看到我们已经传递了我们的模拟数据,并调用了返回结果的then方法

    $response = IntacctClass::create($vehicle_info)
      ->then(function (IntacctResponseInterface $response) {
        if (!$response->isSuccessful()) {
          $this->fail(sprintf("Cannot continue.  Errors: %s\n\nrequest xml: %s\n\nresponse xml: %s", print_r($response->getErrors(), TRUE), $response->getRequestXml(), $response->getResponseXml()));
          return NULL;
        }

在回调处理程序中,我们只是做出一个断言,请求是成功的。成功的含义是标准化的

  • 请求已经解决。这个库旨在允许异步操作(最终),因此如果您在通信解决或超时之前调用此方法,将触发异常。如果您需要暂停操作直到它解决,只需在回调中使用'wait'方法即可
      $response = IntacctClass::create($vehicle_info)
        ->then(function (IntacctResponseInterface $response) {
          if (!$response->isSuccessful()) {
            $response->wait();
            $this->fail(sprintf("Cannot continue.  Errors: %s\n\nrequest xml: %s\n\nresponse xml: %s", print_r($response->getErrors(), TRUE), $response->getRequestXml(), $response->getResponseXml()));
            return NULL;
          }
    
-  The authorization for the intacct 'control' and 'authentication' blocks are successful (see [here](https://developer.intacct.com/wiki/constructing-web-services-request#Logon,%20Verification%20and%20Requests%20using%20the%20Intacct%20XML%20DTD)). 
- The *operation* was successful.  This means it was successfully executed remotely without error - you could be running a query for items, and it is possible and even likely for it to pass this test, and return an empty result set at the same time.

...more documentation coming soon...