code050 / twinfield
用于使用Twinfield Soap服务的库。
Requires
- php: >=7.1
- ext-dom: *
- ext-json: *
- ext-soap: *
- moneyphp/money: ^3.0
- myclabs/php-enum: ^1.5
- psr/http-message: ^1.0
- psr/log: ^1.0
- webmozart/assert: ^1.2
Requires (Dev)
- eloquent/liberator: ^2.0
- league/oauth2-client: ^2.2
- mediact/dependency-guard: ^1.0
- phpstan/phpstan: ^0.10.1
- phpunit/phpunit: ^7.3
Suggests
- league/oauth2-client: If you want to use OAuth to login
Conflicts
Replaces
- v2.9.0
- v2.8.3
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.0
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.1
- v2.5.0
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.3
- v2.3.2
- v2.3.1
- 2.3.0
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.44
- v2.0.43
- v2.0.42
- v2.0.41
- V2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.0
- v1.0.0
- 0.0.1
- dev-fix-performancetype-mapping
- dev-fix-performancetype-mapper
- dev-issue-124-fix-type-error
- dev-oauth2-provider
- dev-release-1.0
This package is not auto-updated.
Last update: 2023-03-07 08:12:51 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
对象。除了OAuthProvider
和AccessToken
之外,还需要设置一个默认的\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() | 映射器 |
---|---|---|---|---|
文章 | ✅ | ✅ | ✅ | |
银行交易 | ✅ | |||
客户 | ✅ | ✅ | ✅ | ✅ |
电子银行对账单 | ✅ | |||
销售发票 | ✅ | ✅ | ✅ | |
匹配 | ✅ | |||
办公室 | ✅ | |||
供应商 | ✅ | ✅ | ✅ | ✅ |
交易 采购、销售、日记账 |
✅ | ✅ | ✅ | |
用户 | ✅ | |||
增值税类型 | ✅ |