PHP code example of phpsoftbox / yandex-market

1. Go to this page and download the library: Download phpsoftbox/yandex-market 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/ */

    

phpsoftbox / yandex-market example snippets


use PhpSoftBox\Http\Message\RequestFactory;
use PhpSoftBox\Http\Message\StreamFactory;
use PhpSoftBox\YandexMarket\YandexMarketApiClient;

$client = new YandexMarketApiClient(
    token: $_ENV['YANDEX_MARKET_API_KEY'],
    httpClient: $psr18Client,
    requestFactory: new RequestFactory(),
    streamFactory: new StreamFactory(),
);

$orders = $client->v2('campaigns/123')->get('/orders', [
    'limit' => 50,
]);

use PhpSoftBox\YandexMarket\YandexMarketApiClient;
use PhpSoftBox\YandexMarket\Retry\RateLimitRetryOptions;
use PhpSoftBox\YandexMarket\Retry\YandexMarketRetryEvent;

$client = new YandexMarketApiClient(
    token: $token,
    httpClient: $psr18Client,
    requestFactory: $requestFactory,
    streamFactory: $streamFactory,
    rateLimitRetry: new RateLimitRetryOptions(
        maxAttempts: 4,
        maxDelaySeconds: 30.0,
        maxTotalDelaySeconds: 60.0,
        onRetry: static function (YandexMarketRetryEvent $event): void {
            // Доступны attempt, delaySeconds, method, endpoint и statusCode.
        },
    ),
);

use PhpSoftBox\YandexMarket\Retry\CallbackRetryableRequestPolicy;
use Psr\Http\Message\RequestInterface;

$retry = new RateLimitRetryOptions(
    requestPolicy: new CallbackRetryableRequestPolicy(
        static fn (RequestInterface $request): bool => $request->getUri()->getPath() !== '/custom/non-retryable',
    ),
);

$orders = $client->v2('campaigns/123')->get('/orders')->makeDto();