ikurcubic / wolt-api
PHP Client for Wolt API
v1.0.2
2022-06-24 15:13 UTC
Requires
- php: ^7.4
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.8.0
- pestphp/pest: ^0.3.8
- phpstan/phpstan: ^0.12.48
- symfony/var-dumper: ^5.2.0
This package is auto-updated.
Last update: 2024-10-24 20:54:58 UTC
README
This package provides Wolt API PHP Client for Items and Inventory update
Installation
composer require ikurcubic/wolt-api
Usage
<?php use GuzzleHttp\Exception\ClientException; use IvanKurcubic\WoltAPI\Client; use IvanKurcubic\WoltAPI\Exceptions\HttpResponseException; $username = 'test'; $password = 'b77b7a63cd5176154ca2802f9927ee598dc'; $venueId = '62b041691ce47b414960c712' $api = new Client($username, $password, Client::ENV_STAGE); $data = [ "data" => [ ['sku'=>'1234', 'price'=>10000, 'enabled'=>true, 'vat_percentage'=>20.00], ['sku'=>'5678', 'price'=>20000, 'enabled'=>true, 'vat_percentage'=>20.00], ... ] ]; try { $api->updateItems($venueId, $data); } catch (HttpResponseException|ClientException $exception) { if ($exception->getResponse()->getStatusCode() == 429) { $retryAfter = $exception->getResponse()->getHeader('retry-after'); if (is_array($retryAfter)) { $retryAfter = $retryAfter[0] ?? 0; } echo "Too many requests, need to wait $retryAfter seconds."; sleep($retryAfter + 2); $api->updateItems($venueId, $data); } else { throw $exception; } }
Wolt API PHP Client was created by Ivan Kurcubic under the MIT license.