PHP code example of lapaygroup / ozon-rocket-sdk

1. Go to this page and download the library: Download lapaygroup/ozon-rocket-sdk 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/ */

    

lapaygroup / ozon-rocket-sdk example snippets


try {
    // Инициализация API клиента с таймаутом ожидания ответа 60 секунд
    $Client = new LapayGroup\OzonRocketSdk\Client('ApiTest_11111111-1111-1111-1111-111111111111', 'SRYksX3PBPUYj73A6cNqbQYRSaYNpjSodIMeWoSCQ8U=', 60, \LapayGroup\OzonRocketSdk\Client::API_URI_TEST);
    $jwt = $Client->getJwt(); // $jwt = eyJhbGciOiJSUzI1NiIsImtpZCI6IjQyMmNhZDNiLTc2MjMtNGZhYy1hMWEwLTIwZTQxMGQxNDRjMCIsInR5cCI6ImF0K2p3dCJ9.eyJuYmYiOjE2NTUxMzAxNjQsImV4cCI6MTY1NTIxNjU2NCwiaXNzIjoiaHR0cHM6Ly9hcGktc3RnLm96b25ydS5tZS9wcmluY2lwYWwtYXV0aC1hcGkiLCJjbGllbnRfaWQiOiJBcGlUZXN0XzExMTExMTExLTExMTEtMTExMS0xMTExLTExMTExMTExMTExMSIsIkxvem9uVXNlck5hbWUiOiJBcGlVc2VyVGVzdDIiLCJMb3pvbkNvbnRyYWN0SWQiOiIyMjYwNDI1OTU3NjAwMCIsIkxvem9uUHJpbmNpcGFsSWQiOiIzNDUiLCJqdGkiOiJCOUFCNTUyMTVCMzlEQjBFMDM2OEI5NTk3QzE4QjFENiIsImlhdCI6MTY1NTEzMDE2NCwic2NvcGUiOlsiZGVsaXZlcnkucGFyYW1zLmFwaS5yZWFkIiwicHJpbmNpcGFsLmludGVncmF0aW9uLmFwaS5mdWxsIl19.IN6UV3rArlGSQD_fOFYT2c9FUPNx_LW_BMI7RqO7-rpT0_hbmh_PhxZedAdJs3ZRdc-kki5t2nR9p-GoQYWeVt30s5n-qeqpSigZvunf-TYmNMjl6Un0zSI0XY_9SMl-xTzUJ7DnwAGdWu9jWvusMoFI-vGUJB-wZIQzhCN1MeOq1gIgvc5Hd729fXe3hvlc683dsF-leoXgiIb3CV-kkSx6ASERZy7rw7ugs4LWhwphVCM2dvhMt8Ue1f35MkllgJaic9x6OU3JMIKlRdGFFdcPy9ZpWqmH34XpDoZCrHWnbndE-tFLc0fuXSIf0kNoJhaUrW5VJ7Gliu0_Rtv3sQ
    $result = \LapayGroup\OzonRocketSdk\Jwt::decode($jwt); // Получения информации из токена (payload)

    // Ранее полученный токен можно добавить в клиент специльным методом
    $Client->setJwt($jwt);

    // Токен можно сохранять в файл используя Helper
    $jwtHelper = new \LapayGroup\OzonRocketSdk\Helpers\JwtSaveFileHelper();
    // Можно задать путь до временного файла отличный от заданного по умолчанию
    $jwtHelper->setTmpFile('/tmp/saved_jwt.txt');

    $Client = new LapayGroup\OzonRocketSdk\Client('ApiTest_11111111-1111-1111-1111-111111111111', 'SRYksX3PBPUYj73A6cNqbQYRSaYNpjSodIMeWoSCQ8U=', 60, \LapayGroup\OzonRocketSdk\Client::API_URI_TEST, $jwtHelper);
    $jwt = $Client->getJwt(); // $jwt = eyJhbGciOiJSUzI1NiIsImtpZCI6IjQyMmNhZDNiLTc2MjMtNGZhYy1hMWEwLTIwZTQxMGQxNDRjMCIsInR5cCI6ImF0K2p3dCJ9.eyJuYmYiOjE2NTUxMzAxNjQsImV4cCI6MTY1NTIxNjU2NCwiaXNzIjoiaHR0cHM6Ly9hcGktc3RnLm96b25ydS5tZS9wcmluY2lwYWwtYXV0aC1hcGkiLCJjbGllbnRfaWQiOiJBcGlUZXN0XzExMTExMTExLTExMTEtMTExMS0xMTExLTExMTExMTExMTExMSIsIkxvem9uVXNlck5hbWUiOiJBcGlVc2VyVGVzdDIiLCJMb3pvbkNvbnRyYWN0SWQiOiIyMjYwNDI1OTU3NjAwMCIsIkxvem9uUHJpbmNpcGFsSWQiOiIzNDUiLCJqdGkiOiJCOUFCNTUyMTVCMzlEQjBFMDM2OEI5NTk3QzE4QjFENiIsImlhdCI6MTY1NTEzMDE2NCwic2NvcGUiOlsiZGVsaXZlcnkucGFyYW1zLmFwaS5yZWFkIiwicHJpbmNpcGFsLmludGVncmF0aW9uLmFwaS5mdWxsIl19.IN6UV3rArlGSQD_fOFYT2c9FUPNx_LW_BMI7RqO7-rpT0_hbmh_PhxZedAdJs3ZRdc-kki5t2nR9p-GoQYWeVt30s5n-qeqpSigZvunf-TYmNMjl6Un0zSI0XY_9SMl-xTzUJ7DnwAGdWu9jWvusMoFI-vGUJB-wZIQzhCN1MeOq1gIgvc5Hd729fXe3hvlc683dsF-leoXgiIb3CV-kkSx6ASERZy7rw7ugs4LWhwphVCM2dvhMt8Ue1f35MkllgJaic9x6OU3JMIKlRdGFFdcPy9ZpWqmH34XpDoZCrHWnbndE-tFLc0fuXSIf0kNoJhaUrW5VJ7Gliu0_Rtv3sQ
        
}

catch (\LapayGroup\FivePostSdk\Exceptions\FivePostException $e) {
    // Обработка ошибки вызова API 5post
    // $e->getMessage(); текст ошибки 
    // $e->getCode(); http код ответа сервиса 5post
    // $e->getRawResponse(); // ответ сервера 5post как есть (http request body)
}

catch (\Exception $e) {
    // Обработка исключения
}


    use Monolog\Logger;
    use Monolog\Handler\StreamHandler;
    
    $log = new Logger('name');
    $log->pushHandler(new StreamHandler('log.txt', Logger::INFO));

    $Client = new LapayGroup\OzonRocketSdk\Client('ApiTest_11111111-1111-1111-1111-111111111111', 'SRYksX3PBPUYj73A6cNqbQYRSaYNpjSodIMeWoSCQ8U=', 60, \LapayGroup\OzonRocketSdk\Client::API_URI_TEST);
    $Client->setLogger($log);
    $jwt = $Client->getJwt(); // $jwt = eyJhbGciOiJSUzI1NiIsImtpZCI6IjQyMmNhZDNiLTc2MjMtNGZhYy1hMWEwLTIwZTQxMGQxNDRjMCIsInR5cCI6ImF0K2p3dCJ9.eyJuYmYiOjE2NTUxMzAxNjQsImV4cCI6MTY1NTIxNjU2NCwiaXNzIjoiaHR0cHM6Ly9hcGktc3RnLm96b25ydS5tZS9wcmluY2lwYWwtYXV0aC1hcGkiLCJjbGllbnRfaWQiOiJBcGlUZXN0XzExMTExMTExLTExMTEtMTExMS0xMTExLTExMTExMTExMTExMSIsIkxvem9uVXNlck5hbWUiOiJBcGlVc2VyVGVzdDIiLCJMb3pvbkNvbnRyYWN0SWQiOiIyMjYwNDI1OTU3NjAwMCIsIkxvem9uUHJpbmNpcGFsSWQiOiIzNDUiLCJqdGkiOiJCOUFCNTUyMTVCMzlEQjBFMDM2OEI5NTk3QzE4QjFENiIsImlhdCI6MTY1NTEzMDE2NCwic2NvcGUiOlsiZGVsaXZlcnkucGFyYW1zLmFwaS5yZWFkIiwicHJpbmNpcGFsLmludGVncmF0aW9uLmFwaS5mdWxsIl19.IN6UV3rArlGSQD_fOFYT2c9FUPNx_LW_BMI7RqO7-rpT0_hbmh_PhxZedAdJs3ZRdc-kki5t2nR9p-GoQYWeVt30s5n-qeqpSigZvunf-TYmNMjl6Un0zSI0XY_9SMl-xTzUJ7DnwAGdWu9jWvusMoFI-vGUJB-wZIQzhCN1MeOq1gIgvc5Hd729fXe3hvlc683dsF-leoXgiIb3CV-kkSx6ASERZy7rw7ugs4LWhwphVCM2dvhMt8Ue1f35MkllgJaic9x6OU3JMIKlRdGFFdcPy9ZpWqmH34XpDoZCrHWnbndE-tFLc0fuXSIf0kNoJhaUrW5VJ7Gliu0_Rtv3sQ
    $result = \LapayGroup\OzonRocketSdk\Jwt::decode($jwt);


    $Client = new LapayGroup\OzonRocketSdk\Client('ApiTest_11111111-1111-1111-1111-111111111111', 'SRYksX3PBPUYj73A6cNqbQYRSaYNpjSodIMeWoSCQ8U=', 60, \LapayGroup\OzonRocketSdk\Client::API_URI_TEST);
    $price = $Client->calculationTariff(1011000000001578, 18842715502000, 500, 1000); // 146.4


    $Client = new LapayGroup\OzonRocketSdk\Client('ApiTest_11111111-1111-1111-1111-111111111111', 'SRYksX3PBPUYj73A6cNqbQYRSaYNpjSodIMeWoSCQ8U=', 60, \LapayGroup\OzonRocketSdk\Client::API_URI_TEST);
    $price = $Client->calculationTariff(1011000000001578, 18842715502000, 500, 1000); // 146.4


    $Client = new LapayGroup\OzonRocketSdk\Client('ApiTest_11111111-1111-1111-1111-111111111111', 'SRYksX3PBPUYj73A6cNqbQYRSaYNpjSodIMeWoSCQ8U=', 60, \LapayGroup\OzonRocketSdk\Client::API_URI_TEST);
    $days = $Client->getDeliveryPeriod(1011000000001578, 18842715502000); // 9