floor12/dalli-api

Dalli service api client

1.0.2 2022-12-07 12:10 UTC

This package is auto-updated.

Last update: 2024-10-25 11:09:26 UTC


README

Scrutinizer Code Quality Code Coverage Build Status

Установка

Устанавливаем модуль через composer. Выполняем команду

$ composer require floor12/dalli-api

или добавляем в секцию "required" файла composer.json

"floor12/dalli-api":"dev-master"

Инициализация

use floor12\DalliApi\DalliClient;
use floor12\DalliApi\Enum\DalliApiEndpoint;
$token = 'your_token';
$dalliClient = new DalliClient(DalliApiEndpoint::SPB, $token);

Примеры вызовов

Отправка заказа в корзину

use floor12\DalliApi\Enum\DalliService;
use floor12\DalliApi\Models\Item;
use floor12\DalliApi\Models\Order;
use floor12\DalliApi\Models\Receiver;
use floor12\DalliApi\Enum\DalliApiMethod;
use floor12\DalliApi\Models\DalliApiBody;
use floor12\DalliApi\DalliClient;
use floor12\DalliApi\Enum\DalliApiEndpoint;


$token = 'your_token';
$dalliClient = new DalliClient(DalliApiEndpoint::SPB, $token);

$apiBody = new DalliApiBody(DalliApiMethod::BASKET_CREATE);

$receiver = (new Receiver())
    ->setPerson('Иванов Иван Иванович')
    ->setAddress('Большая Серпуховская 12-32')
    ->setTown('Москва')
    ->setPvzCode('PVZ_001')
    ->setDate('2020-10-10')
    ->setTimeMin('15:00')
    ->setTimeMax('21:00')
    ->setPhone('79269392399');

$order = (new Order())
    ->setNumber('AXC-12')
    ->setQuantity(1)
    ->setInshprice(1000)
    ->setPrice(1000)
    ->setService(DalliService::EXPRESS_MOSCOW)
    ->setReceiver($receiver);


$item1 = (new Item())
    ->setTitle('Юбка')
    ->setArticle('F2D0001')
    ->setQuantity(1)
    ->setWeight(0.3)
    ->setBarcode('460063453454')
    ->setRetprice(500);

$item2 = (new Item())
    ->setTitle('Кофта')
    ->setArticle('F2D0001')
    ->setQuantity(1)
    ->setWeight(0.3)
    ->setBarcode('460063453454')
    ->setRetprice(500);

$order->addItem($item1);
$order->addItem($item2);

$apiBody->add($order);

$success = !$dalliClient->sendApiRequest($apiBody);
if (!$success)
    foreach ($dalliClient->getErrors() as $error)
        echo $error;

echo $dalliClient->getResponseBody();

Очистка корзины

use floor12\DalliApi\DalliClient;
use floor12\DalliApi\Enum\DalliApiEndpoint;
use floor12\DalliApi\Enum\DalliApiMethod;
use floor12\DalliApi\Models\DalliApiBody;

$token = 'your_token';
$dalliClient = new DalliClient(DalliApiEndpoint::SPB, $token);

$apiBody = new DalliApiBody(DalliApiMethod::BASKET_CLEAR);

$success = $dalliClient->sendApiRequest($apiBody);

if (!$success)
    foreach ($dalliClient->getErrors() as $error)
        echo $error;

echo $dalliClient->getResponseBody();