PHP code example of vgrish / yclients-sdk-php

1. Go to this page and download the library: Download vgrish/yclients-sdk-php 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/ */

    

vgrish / yclients-sdk-php example snippets


use Vgrish\Yclients\Yclients;

$yc = Yclients::getInstance()
    ->setPartnerToken('Partner_token')
    ->setUserToken('User_token');

//Конструктор запросов
$auth = $yc->query()
    ->user()
    ->auth()
    ->param([
        'login'    => 'телефон пользователя',
        'password' => 'пароль пользователя',
    ])
    ->create();

//Получаем токен пользователя
$userToken = $auth->object()->getUserToken();

//Устанавливаем токен пользователя
$yc->setUserToken($userToken);

//Получаем клиентов компании
$clients = $yc->query()
    ->clients()
    ->path('company_id', '111111')
    ->param([
        'fields' => [
            'id',
            'name',
            'phone',
            'email',
        ],
    ])
    ->pageSize(5)
    ->page(1)
    ->get();

foreach ($clients->objects() as $client) {
    var_dump($client->getId().':'$client->getName());
}

use Vgrish\Yclients\Yclients;

$yc = Yclients::getInstance()
    ->setPartnerToken('Partner_token')
    ->setUserToken('User_token');
$yc->query()->...;

$yc->query()
    ->client()
    ->path('company_id', '11111')
    ->path('id', '22222222')
    //или
    ->path(['company_id' => '11111', 'id' => '22222222'])
    //или
    ->path([
       ['company_id', '11111'],
       ['id', '22222222'],
    ])
    ->get();

$yc->query()
    ->loyalty()
    ->transactions()
    ->path('chain_id', '33333')
    ->param([
         'created_after'  => '2024-07-10',
         'created_before' => '2024-07-31',
         'company_ids'  => '204265',
         ['types', [5, 6]],
    ])
    ->get([]);

$yc->query()
    ->user()
    ->auth()
    ->create([
        'login'    => 'login',
        'password' => 'password',
    ]);

$yc->query()
    ->client()
    ->get()

$yc->query()
    ->client()
    ->get()
    ->update(['name' => 'новое имя клиента'])

$yc->query()
    ->client()
    ->get()
    ->remove()

$clients = $yc->query()
    ->clients()
    ->path('company_id', '111111')
    ->param([
        'fields' => [
            'id',
            'name',
            'phone',
            'email',
        ],
    ])
    ->pageSize(200)
    ->page(1)
    ->get();
foreach ($clients->objects() as $client) {
    var_dump($client);
}

$generator = $yc->query()
    ->clients()
    ->path('company_id', '111111')
    ->pageSize(200)
    ->generator(function ($builder) {
         $params = $builder->params();
         //Можно прекратить перебор коллекции
         if ($params['page'] > 20) {
             return;
         }
         return $builder->get();
    });
foreach ($generator as $client) {
    $clients[] = $client;
}
bash
composer vgrish/yclients-sdk-php