code050 / twinfield
Library for using the Twinfield Soap Service.
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
A PHP library for Twinfield Integration. Use the Twinfield SOAP Service to have your PHP application communicate directly with your Twinfield account.
⚠️ This library is still under construction. Version 1 is available from Composer, but we recommend you to wait for (or help with!) version 2. We hope to release it early 2018.
Installation
Install this Twinfield PHP library with Composer:
composer require code050/twinfield
Usage
Authentication
You need to set up a \PhpTwinfield\Secure\AuthenticatedConnection
class with your credentials. When using basic
username and password authentication, the \PhpTwinfield\Secure\WebservicesAuthentication
class should be used, as follows:
$connection = new Secure\WebservicesAuthentication("username", "password", "organization");
In order to use OAuth2 to authenticate with Twinfield, one should use the \PhpTwinfield\Secure\Provider\OAuthProvider
to retrieve an \League\OAuth2\Client\Token\AccessToken
object. Next to the OAuthProvider
and AccessToken
, it is required to set up a default \PhpTwinfield\Office
, that will be used during requests to Twinfield. Please note: when a different office is specified when sending a request through one of the ApiConnectors
, this Office will override the default.
Using this information, we can create an instance of the \PhpTwinfield\Secure\OpenIdConnectAuthentication
class, as follows:
$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);
For more information about retrieving the initial AccessToken
, please refer to: https://github.com/thephpleague/oauth2-client#usage
Getting data from the API
In order to communicate with the Twinfield API, you need to create an ApiConnector
instance for the corresponding
resource and use the get()
or list()
method.
The ApiConnector
takes a Secure\AuthenticatedConnection
object:
An example:
$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);
Creating or updating objects
If you want to create or update a customer or any other object, it's just as easy:
$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);
You can also send multiple objects in one batch, chunking is handled automatically.
Supported resources
Not all resources from the Twinfield API are currently implemented. Feel free to create a pull request when you need support for another resource.
Component | get() | listAll() | send() | Mapper |
---|---|---|---|---|
Articles | ✅ | ✅ | ✅ | |
BankTransaction | ✅ | |||
Customer | ✅ | ✅ | ✅ | ✅ |
Electronic Bank Statements | ✅ | |||
Sales Invoices | ✅ | ✅ | ✅ | |
Matching | ✅ | |||
Offices | ✅ | |||
Suppliers | ✅ | ✅ | ✅ | ✅ |
Transactions: Purchase, Sale, Journal |
✅ | ✅ | ✅ | |
Users | ✅ | |||
Vat types | ✅ |