PHP client to connect to the itsme API.
The package is available via composer:
$ composer require nascom/itsme-api-client
First, you'll need to provide a client that can make HTTP requests. For now, only Guzzle is supported.
<?php
use Nascom\ItsmeApiClient\Http\ApiClient\ApiClient;
use Nascom\ItsmeApiClient\Http\ApiClient\Service;
use Nascom\ItsmeApiClient\Http\ApiClient\ApiClientFactory;
$guzzleClient = new \GuzzleHttp\Client(['base_uri' => Service::PRODUCTION]);
$client = new ApiClient($guzzleClient);
// Alternatively, you can use the ApiClientFactory.
$client = ApiClientFactory::production();
Every API endpoint has a corresponding Request class. These classes have to
be passed to the client's handle()
method.
Creating a transaction:
<?php
use Nascom\ItsmeApiClient\Request\Transaction\CreateTransactionRequest;
$transactionRequest = new CreateTransactionRequest($token, $service, $redirectUrl);
$transaction = $client->handle($transactionRequest);
echo $transaction->getAuthenticationUrl();
Retrieve status after validation of itsme:
<?php
use Nascom\ItsmeApiClient\Request\Status\RetrieveStatusRequest;
$statusRequest = new RetrieveStatusRequest($_SESSION['token']);
$status = $client->handle($statusRequest);
echo $status->getEmailAddress();