dicr/yii2-pochta

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Pochta API для Yii2

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

2.0.0 2021-08-12 23:51 UTC

This package is auto-updated.

Last update: 2021-10-12 19:21:07 UTC


README

Настройка

$config = [
    'components' => [
        'pochta' => [
            'class' => dicr\pochta\PochtaAPI::class,
            'token' => '<токен API>',
            'login' => '<логин личного кабинета>',
            'pass' => '<пароль от личного кабинета>'
        ]
    ]       
];

Использование

Расчёт стоимости доставки

/** @var dicr\pochta\PochtaAPI $api */
$api = Yii::$app->get('pochta');

/** @var dicr\pochta\request\TariffRequest $request создаем запрос */
$request = $api->tariffRequest([
    'declaredValue' => 200000, // 2 тыс руб 
    'indexFrom' => 614107, // Пермь
    'indexTo' => 105037, // Москва
    'mass' => 800, // 800 грамм
    'dimension' => ['height' => 25, 'length' => 15, 'width' => 10], // в сантиметрах
    'mailCategory' => dicr\pochta\Pochta::MAIL_CATEG_WITH_DECLARED_VALUE_AND_CASH_ON_DELIVERY,
    'mailType' => dicr\pochta\Pochta::MAIL_TYPE_ONLINE_PARCEL,
    'paymentMethod' => dicr\pochta\Pochta::PAYMENT_METHOD_CASHLESS
]);

/** @var dicr\pochta\request\TariffResponse $response отправляем запрос */
$response = $request->send();

printf("Срок: %d дней\n", $response->deliveryTime->maxDays);
printf("Стоимость %.2f руб.\n", $response->totalRate / 100);