code050/twinfield

此包已被废弃,不再维护。作者建议使用php-twinfield / twinfield包。

用于使用Twinfield Soap服务的库。

v2.9.0 2020-03-06 15:11 UTC

README

一个用于Twinfield集成的PHP库。使用Twinfield SOAP服务使您的PHP应用程序能够直接与您的Twinfield账户通信。

⚠️ 此库仍在建设中。版本1已从Composer提供,但我们建议您等待(或帮助!)版本2。我们希望在2018年初发布。

安装

使用Composer安装此Twinfield PHP库

composer require code050/twinfield

用法

认证

您需要设置一个带有凭证的\PhpTwinfield\Secure\AuthenticatedConnection类。当使用基本用户名和密码认证时,应使用\PhpTwinfield\Secure\WebservicesAuthentication类,如下所示

$connection = new Secure\WebservicesAuthentication("username", "password", "organization");

为了使用OAuth2对Twinfield进行认证,应使用\PhpTwinfield\Secure\Provider\OAuthProvider检索一个\League\OAuth2\Client\Token\AccessToken对象。除了OAuthProviderAccessToken之外,还需要设置一个默认的\PhpTwinfield\Office,该Office将在请求Twinfield时使用。**请注意**:当通过其中一个ApiConnectors发送请求并指定不同的办公室时,此Office将覆盖默认设置。

使用此信息,我们可以创建一个\PhpTwinfield\Secure\OpenIdConnectAuthentication类的实例,如下所示

$provider    = new OAuthProvider([
    'clientId'     => 'someClientId',
    'clientSecret' => 'someClientSecret',
    'redirectUri'  => 'https://example.org/'
]);
$accessToken = $provider->getAccessToken("authorization_code", ["code" => ...]);
$office      = \PhpTwinfield\Office::fromCode("someOfficeCode");

$connection  = new \PhpTwinfield\Secure\OpenIdConnectAuthentication($provider, $accessToken, $office);

有关检索初始AccessToken的更多信息,请参阅:https://github.com/thephpleague/oauth2-client#usage

从API获取数据

为了与Twinfield API通信,您需要为相应的资源创建一个ApiConnector实例并使用get()list()方法。

ApiConnector接受一个Secure\AuthenticatedConnection对象

示例

$connection = new Secure\AuthenticatedConnection("username", "password", "organization");
$customerApiConnector = new ApiConnectors\CustomerApiConnector($connection);

// Get one customer.
$office   = Office::fromCode('office code');
$customer = $customerApiConnector->get('1001', $office);

// Get a list of all customers.
$customer = $customerApiConnector->listAll($office);

创建或更新对象

如果您想创建或更新客户或任何其他对象,同样简单

$customer_factory = new ApiConnectors\CustomerApiConnector($connection);

// First, create the objects you want to send.
$customer = new Customer();
$customer
    ->setCode('1001')
    ->setName('John Doe')
    ->setOffice($office)
    ->setEBilling(false);

$customer_address = new CustomerAddress();
$customer_address
    ->setType('invoice')
    ->setDefault(false)
    ->setPostcode('1212 AB')
    ->setCity('TestCity')
    ->setCountry('NL')
    ->setTelephone('010-12345')
    ->setFax('010-1234')
    ->setEmail('johndoe@example.com');
$customer->addAddress($customer_address);

// And secondly, send it to Twinfield.
$customer_factory->send($customer);

您还可以在单个批次中发送多个对象,分块处理由系统自动完成。

支持的资源

并非Twinfield API的所有资源都已实现。当您需要支持其他资源时,请随意创建拉取请求。

组件 get() listAll() send() 映射器
文章
银行交易
客户
电子银行对账单
销售发票
匹配
办公室
供应商
交易
采购销售日记账
用户
增值税类型

链接

作者