PHP code example of picqer / bol-retailer-php-client
1. Go to this page and download the library: Download picqer/bol-retailer-php-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
picqer / bol-retailer-php-client example snippets
$client = new \Picqer\BolRetailerV10\Client();
$client->authenticateByClientCredentials('your-client-id', 'your-client-secret');
$reducedOrders = $client->getOrders();
foreach ($reducedOrders as $reducedOrder) {
echo 'hello, I am order ' . $reducedOrder->orderId . PHP_EOL;
}
$accessToken = ... // your implementation of getting the access token from the storage
$client = new \Picqer\BolRetailerV10\Client();
$client->setAccessToken($accessToken);
$client->setAccessTokenExpiredCallback(function(\Picqer\BolRetailerV10\Client $client) {
// Called at the beginning of a request to the Retailer API when the access token was expired (or
// non-existent) and after a request that resulted in an error about an expired access token.
// Authenticate and fetch the new access token
$client->authenticateByClientCredentials('{your-client-id}', '{your-client-secret}');
$accessToken = $client->getAccessToken();
... // store $accessToken for future use
});
$client = new \Picqer\BolRetailerV10\Client();
$refreshToken = $client->authenticateByAuthorizationCode(
'{your-client-id}',
'{your-client-secret}',
'{received-shortcode}',
'{callback-uri}'
);
$accessToken = $client->getAccessToken();
... // store $accessToken and $refreshToken for future use
$orders = $client->getOrders();
$client = new \Picqer\BolRetailerV10\Client();
$accessToken = ... // your implementation of getting the access token from the storage
$client->setAccessToken($accessToken);
$orders = $client->getOrders();
$client = new \Picqer\BolRetailerV10\Client();
$accessToken = ... // your implementation of getting the access token from the storage
$client->setAccessToken($accessToken);
$client->setAccessTokenExpiredCallback(function(\Picqer\BolRetailerV10\Client $client) {
// Called at the beginning of a request to the Retailer API when the access token was expired or
// non-existent and after a request that resulted in an error about an expired access token.
// This callback can attempt to refresh the access token. If after this callback the Client has
// a valid access token, the request will continue or retried once. Otherwise, it will be
// aborted with an Exception.
$refreshToken = ... // your implementation of getting the refresh token from the storage
$client->authenticateByRefreshToken('{your-client-id}', '{your-client-secret}', $refreshToken);
$accessToken = $client->getAccessToken();
... // store $accessToken for future use
});
$orders = $client->getOrders();
$client = new \Picqer\BolRetailerV10\Client();
$accessToken = ... // your implementation of getting the access token from the storage
$client->setAccessToken($accessToken);
$client->setAccessTokenExpiredCallback(function(\Picqer\BolRetailerV10\Client $client) use ($mutex) {
// Called at the beginning of a request to the Retailer API when the access token was expired or
// non-existent and after a request that resulted in an error about an expired access token.
// Ensure only 1 process can be in the critical section, others are blocked and one is let in
// when that process leaves the critical section
$mutex->withLock(function () use ($client) {
// your implementation of getting the latest access token from the storage (it might be
// refreshed by another process)
$accessToken = ...
if (! $accessToken->isExpired()) {
// No need to refresh the token, as it was already refreshed by another proces. Make sure the
// client uses it.
$client->setAccessToken($accessToken);
return;
}
$refreshToken = ... // your implementation of getting the refresh token from the storage
$newRefreshToken = $client->authenticateByRefreshToken(
'{your-client-id}',
'{your-client-secret}',
$refreshToken
);
$accessToken = $client->getAccessToken();
... // store $accessToken and $newRefreshToken for future use
}
});
$orders = $client->getOrders();
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.