Twinfield service provider for Laravel 8, adding the functionality of the php-twinfield/twinfield
API client.
This service provider is written for Laravel 8 and up and requires PHP 8.1 to run.
You can install this package with composer:
composer require "willemo/laravel-twinfield:^2.0"
The package will be automatically discovered by your Laravel installation, so you don't need to add the service provider and facade to your app config file.
In that case you can install the ^1.0
version of this package, which is compatible with Laravel 5.5+ and PHP 7.2+.
Between version 0.X.X and 1.X.X the file structure has been modified. Make sure all class references are correct after upgrading.
Firstly you'll have to publish the config file:
php artisan vendor:publish --provider="Willemo\LaravelTwinfield\TwinfieldServiceProvider"
Then you can configure the Twinfield API client in config/twinfield.php
. The best way to configure your Twinfield API is by using environment variables.
You can either choose to use your credentials to connect to the Twinfield API:
TWINFIELD_AUTH_TYPE=credentials
TWINFIELD_USERNAME=your_username
TWINFIELD_PASSWORD=your_password
TWINFIELD_ORGANISATION=your_organisation
TWINFIELD_OFFICE=your_office
Or you can use OAuth to connect to the Twinfield API:
TWINFIELD_CLIENT_ID=your_client_id
TWINFIELD_CLIENT_SECRET=your_client_secret
TWINFIELD_RETURN_URL=https://example.org/oauth/return/url
TWINFIELD_ORGANISATION=your_organisation
TWINFIELD_OFFICE=your_office
If you wish to use the autoRedirect
option of the PhpTwinfield API client, you can enable it in the config/twinfield.php
file by setting 'autoRedirect' => true,
.
You can use the Twinfield
facade to get an API connector:
$customerApiConnector = \Twinfield::get('Customer');
For usage of the API connectors and available connectors, check the PhpTwinfield docs.