Download the PHP package php-twinfield/twinfield without Composer
On this page you can find all versions of the php package php-twinfield/twinfield. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-twinfield/twinfield
More information about php-twinfield/twinfield
Files in php-twinfield/twinfield
Package twinfield
Short Description Library for using the Twinfield Soap Service.
License GPL-3.0-or-later
Homepage https://github.com/php-twinfield/twinfield
Informations about the package twinfield
Twinfield
A PHP library for Twinfield Integration. Use the Twinfield SOAP Services to have your PHP application communicate directly with your Twinfield account.
:warning: Note that this library is not created or maintained by Twinfield. You can only get support on the code in this library here. For any questions related to your Twinfield administration or how to do certain things with the Twinfield API, contact your Twinfield account manager.
Installation
Install this Twinfield PHP library with Composer:
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:
Username and password
Some endpoints allow you to filter on the Office, but for instance the BrowseData endpoint doesn't. For this you need to switch to the correct office before making the request, you can do this after authentication like so:
oAuth2
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, and extract the refresh token from this object. Furthermore, 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:
In the case you have an existing accessToken object you may pass that to the constructor or set it, to limit the amount of access token and validate requests, since the accessToken is valid for 1 hour.
or
Setting an access token will force a new validation request on every login.
It's also possible to provide callables, that will be called when a new access token is validated. This way you're able to store the new 'validated' access token object and your application can re-use the token within an hour. This way you can optimize the number of requests.
Be aware to store your access token in an appropriate and secure way. E.g. encrypting it.
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:
Creating or updating objects
If you want to create or update a customer or any other object, it's just as easy:
You can also send multiple objects in one batch, chunking is handled automatically.
Browse data
In order to get financial data out of Twinfield like general ledger transactions, sales invoices, and so on, you can use the the browse data functionality. More information about the browse data functionality in Twinfield can be found in the documentation.
Browse definition
You can retrieve the browse definition of a browse code as follows. You don't need to retrieve the browse definition for getting the browse data. It's only for viewing the browse definition of a browse code to know exactly which columns are available.
Browse fields
You can retrieve the browse fields as follows. You don't need to retrieve the browse fields for getting the browse data. It's only for viewing the definitions of all browse fields so you now what you can expect when retrieving browse data.
Browse data
You can retrieve browse data of a browse code as follows.
ApiConnector Configuration
The ApiConnector has a constructor second parameter that can be used to configure some aspects of its operation.
The ApiOptions has the following methods signature:
:exclamation: All the get methods will return a new instance with the configuration you changed.
Configuration Examples
Below are some examples on how to use the configuration object
The example below will look for the default messages plus the "Bad Gateway" message.
Configuration default values
Attribute | Default Value | Description |
---|---|---|
Max retries | 3 | The number of retries that should happen before throwing an error. |
Retriable exception messages | [ "SSL: Connection reset by peer", "Your logon credentials are not valid anymore. Try to log on again." ] |
The exception messages that should be match in order to retry 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() | delete() | Mapper | |
---|---|---|---|---|---|---|
Articles | :white_check_mark: | :white_check_mark: | :white_check_mark: | |||
BankTransaction | :white_check_mark: | :white_check_mark: | ||||
Customer | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | ||
Electronic Bank Statements | :white_check_mark: | |||||
Sales Invoices | :white_check_mark: | :white_check_mark: | :white_check_mark: | |||
Matching | :white_check_mark: | :white_check_mark: | ||||
Offices | :white_check_mark: | :white_check_mark: | ||||
Suppliers | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | ||
Transactions: Purchase, Sale, Journal, Cash |
:white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | ||
Users | :white_check_mark: | |||||
Vat types | :white_check_mark: | |||||
Browse Data | :white_check_mark: | :white_check_mark: |
Links
Authors
All versions of twinfield with dependencies
ext-dom Version *
ext-json Version *
ext-soap Version *
moneyphp/money Version ^3.0 || ^4.0
myclabs/php-enum Version ^1.5
psr/http-message Version ^1.0 || ^2.0
psr/log Version ^1.0 || ^2.0 || ^3.0
webmozart/assert Version ^1.2