PHP code example of fostenslave / nalogka-deals-sdk

1. Go to this page and download the library: Download fostenslave/nalogka-deals-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/ */

    

fostenslave / nalogka-deals-sdk example snippets


use Fostenslave\NalogkaDealsSDK\ApiClient;
use Fostenslave\NalogkaDealsSDK\Serialization\SerializationComponent;

$serializationComponent = new SerializationComponent();

$apiClient = new ApiClient("https://sandbox.deals.api.nalogka.ru/", [
    'headers' => [
        'X-Nalogka-Auth-Token' => '9qASPlstioSjksdqpLkSF2js8Iks1CIv'
    ],
], $serializationComponent);

use Fostenslave\NalogkaDealsSDK\Request\DealsListRequest;
use Fostenslave\NalogkaDealsSDK\Exception\ApiErrorException;
use Fostenslave\NalogkaDealsSDK\Exception\NalogkaSdkException;
use Fostenslave\NalogkaDealsSDK\Exception\ServerErrorException;

$dealsListRequest = (new DealsListRequest($apiClient))
    ->page(1)
    ->items(3);

try {
    $deals = $dealsListRequest->request();
} catch (ApiErrorException $e) {
    // Ошибка от API
} catch (ServerErrorException $e) {
    // Неизвестный ответ от сервера
} catch (NalogkaSdkException $e) {
    // Ошибка в SDK, например проблема с десериализация
}

use Fostenslave\NalogkaDealsSDK\Request\DealGetRequest;

$dealGetRequest = (new DealGetRequest($apiClient))
    ->id(60);

$deal = $dealGetRequest->request();

use Fostenslave\NalogkaDealsSDK\Request\DealCreateRequest;

$dealCreateRequest = (new DealCreateRequest($apiClient))
    ->orderId('4127')
    ->conditions('Хрупкий, крупногабаритный груз')
    ->commissionPayer('seller')
    ->buyerHaveToPayOffline(0)
    ->subjectItem('Смартфон Apple iPhone 5s 16Gb Серебристый', 23500, 1, "test", "test")
    ->additionalService('Доставка СДЭК', 'Тариф Посылка Склад-Склад', 450, 400, 'seller', 'seller')
    ->partialBuyoutNotAllowed();

$deal = $dealCreateRequest->request();

use Fostenslave\NalogkaDealsSDK\Request\DealPerformingTrackSetRequest;

$dealPerformingTrackSetRequest = (new DealPerformingTrackSetRequest($apiClient))
    ->id(60)
    ->trackerShortName('cdek')
    ->code('8172990122');

$track = $dealPerformingTrackSetRequest->request();

use Fostenslave\NalogkaDealsSDK\Request\DealPerformingTrackDeleteRequest;

(new DealPerformingTrackDeleteRequest($apiClient))
    ->id(373)
    ->request();