Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
Updated docs, improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Nov 3, 2020
1 parent 0ab73c0 commit ad2e60c
Show file tree
Hide file tree
Showing 23 changed files with 876 additions and 88 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,15 @@

Работа с большинством методов API возможна [только при наличии договора с Яндекс.Доставкой](https://yandex.ru/dev/delivery-3/doc/dg/concepts/access-docpage/).


## Установка

```bash
composer require sanmai/ydelivery-sdk
```
Для работы SDK нужен PHP 7.3 или выше. Работа протестирована под PHP 7.3, 7.4.
Для работы SDK нужен PHP 7.3 или выше. Работа протестирована под PHP 7.3, 7.4, 8.0, 8.1.

[Полная документация по всем методам.](https://ydelivery-sdk.readthedocs.io/)

## Важно

Что нужно иметь ввиду, прежде чем вы начнёте разработку:

- На момент написания этих строк у Яндекс.Доставки нет тестового окружения. Все заказы будут настоящие.
- Документация не описывает какие поля важны и какие необходимы при создании заказа. Может быть вам поможет обращение в поддержку.
- Успех создания заказа не гарантирует отсутствие ошибок при подтверждении. Можно не увидеть никаких ошибок при создании заказа и получить кучу при подтверждении.

## Лицензия

Данный SDK распространяется [под лицензией MIT](LICENSE).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"psr/log": "^1.0",
"sanmai/json-serializer": "^0.2.2",
"sanmai/pipeline": "^5",
"sanmai/sdk-common": "^0.4.3",
"sanmai/sdk-common": "^0.4.4",
"sanmai/version-info": "^0.2.0",
"symfony/http-foundation": "^4.4.7 || ^5.0.7"
},
Expand Down
447 changes: 430 additions & 17 deletions docs/index.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/010_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@

$token = 'token';
$timeout = 120;
$cacheDir = 'ydostavka';

$builder = new \YDeliverySDK\ClientBuilder();
$builder->setToken($token);
$builder->setTimeout($timeout);
$builder->setCacheDir($cacheDir);

$client = $builder->build();

Expand Down
4 changes: 2 additions & 2 deletions examples/035_PickupPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
declare(strict_types=1);

use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\PickupPointsRequest;
use YDeliverySDK\Requests;
use YDeliverySDK\Responses\Types\PickupPoint;

include_once 'vendor/autoload.php';
Expand All @@ -38,7 +38,7 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$request = new PickupPointsRequest();
$request = new Requests\PickupPointsRequest();
$request->type = $request::TYPE_TERMINAL;
$request->locationId = 65;
$request->latitude->from = 55.013;
Expand Down
2 changes: 1 addition & 1 deletion examples/040_PostalCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$response = $client->makePostalCodeRequest('Москва, ул. Льва Толстого, 16');
$response = $client->getPostalCodes('Москва, ул. Льва Толстого, 16');

\var_dump(\count($response));

Expand Down
5 changes: 1 addition & 4 deletions examples/050_Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
declare(strict_types=1);

use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\LocationRequest;

include_once 'vendor/autoload.php';

Expand All @@ -37,9 +36,7 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$request = new LocationRequest($argv[1]);

$response = $client->sendLocationRequest($request);
$response = $client->getLocations($argv[1]);

\var_dump(\count($response));

Expand Down
7 changes: 3 additions & 4 deletions examples/060_WithdrawIntervals.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
declare(strict_types=1);

use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\DeliveryServicesRequest;
use YDeliverySDK\Requests\WithdrawIntervalsRequest;
use YDeliverySDK\Requests;

include_once 'vendor/autoload.php';

Expand All @@ -38,7 +37,7 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$request = new DeliveryServicesRequest((int) $_SERVER['YANDEX_CABINET_ID']);
$request = new Requests\DeliveryServicesRequest((int) $_SERVER['YANDEX_CABINET_ID']);

// Получим ID первого попавшегося сервиса доставки.
foreach ($client->sendDeliveryServicesRequest($request) as $partner) {
Expand All @@ -47,7 +46,7 @@
/** @var \YDeliverySDK\Responses\Types\DeliveryService $partner */

// Для него получим расписание доставки.
$request = new WithdrawIntervalsRequest();
$request = new Requests\WithdrawIntervalsRequest();
$request->date = new DateTime('next Monday');
$request->partnerId = $partner->id;

Expand Down
7 changes: 3 additions & 4 deletions examples/070_ImportIntervals.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
declare(strict_types=1);

use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\DeliveryServicesRequest;
use YDeliverySDK\Requests\ImportIntervalsRequest;
use YDeliverySDK\Requests;

include_once 'vendor/autoload.php';

Expand All @@ -38,7 +37,7 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$request = new DeliveryServicesRequest((int) $_SERVER['YANDEX_CABINET_ID']);
$request = new Requests\DeliveryServicesRequest((int) $_SERVER['YANDEX_CABINET_ID']);

// Получим ID первого попавшегося сервиса доставки.
foreach ($client->sendDeliveryServicesRequest($request) as $partner) {
Expand All @@ -47,7 +46,7 @@
/** @var \YDeliverySDK\Responses\Types\DeliveryService $partner */

// Для него получим расписание доставки.
$request = new ImportIntervalsRequest();
$request = new Requests\ImportIntervalsRequest();
$request->date = new DateTime('next Monday');

// Используя первый попавшийся склад.
Expand Down
14 changes: 7 additions & 7 deletions examples/080_DeliveryOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
declare(strict_types=1);

use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\DeliveryOptionsRequest;
use YDeliverySDK\Requests;
use YDeliverySDK\Requests\Types\Shipment;

include_once 'vendor/autoload.php';
Expand All @@ -38,14 +38,14 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$request = new DeliveryOptionsRequest();
$request = new Requests\DeliveryOptionsRequest();
$request->senderId = $_SERVER['YANDEX_SHOP_ID'];

$request->from->location = 'Москва, Красная пл., 1';
$request->from->geoId = 890567;

$request->to->location = 'Новосибирск, Красный пр., 36';
//$request->to->geoId = 4444444;
//$request->to->geoId = 4444;
//$request->to->pickupPointIds = [11111, 222222];

$request->dimensions->length = 10;
Expand All @@ -56,17 +56,17 @@
$request->deliveryType = $request::DELIVERY_TYPE_POST;

$request->shipment->date = new DateTime('next Monday');
$request->shipment->type = Shipment::TYPE_IMPORT;
//$request->shipment->partnerId = 1111111111;
//$request->shipment->warehouseId = 2222222222;
$request->shipment->type = $request->shipment::TYPE_IMPORT;
//$request->shipment->partnerId = 1111;
//$request->shipment->warehouseId = 2222;
//$request->shipment->includeNonDefault = true;

$request->cost->assessedValue = 500;
$request->cost->itemsSum = 1000;
$request->cost->manualDeliveryForCustomer = 750;
$request->cost->fullyPrepaid = true;

// $request->tariffId = 333333333;
// $request->tariffId = 3333;

$response = $client->sendDeliveryOptionsRequest($request);

Expand Down
14 changes: 7 additions & 7 deletions examples/090_CreateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
declare(strict_types=1);

use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\CreateOrderRequest;
use YDeliverySDK\Requests;

include_once 'vendor/autoload.php';

Expand All @@ -37,7 +37,7 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$request = new CreateOrderRequest();
$request = new Requests\CreateOrderRequest();
$request->deliveryType = $request::DELIVERY_TYPE_COURIER;
$request->senderId = (int) $_SERVER['YANDEX_SHOP_ID'];

Expand Down Expand Up @@ -76,23 +76,23 @@
$item->count = 1;
$item->price = 1467;
$item->assessedValue = 1467;
$item->tax = 'NO_VAT';
$item->tax = $item::TAX_NO_VAT;

$item->dimensions->length = 10;
$item->dimensions->width = 20;
$item->dimensions->height = 30;
$item->dimensions->weight = 0.3;

$request->externalId = '426';
$request->deliveryType = 'PICKUP';
$request->deliveryType = $request::DELIVERY_TYPE_PICKUP;
$request->comment = 'Доставки не будет - тестовый заказ';

$request->deliveryOption->tariffId = 100040;

$request->deliveryOption->tariffId = 100040;
$request->deliveryOption->delivery = 198.00;
$request->deliveryOption->deliveryForCustomer = 369.802;
$request->deliveryOption->type = 'PICKUP';
$request->deliveryOption->type = $request::DELIVERY_TYPE_PICKUP;
$request->deliveryOption->partnerId = 107;
$request->deliveryOption->calculatedDeliveryDateMin = '2020-02-13';
$request->deliveryOption->calculatedDeliveryDateMax = '2020-02-13';
Expand Down Expand Up @@ -135,11 +135,11 @@
$request->cost->assessedValue = 1467;
$request->cost->fullyPrepaid = false;
$request->cost->manualDeliveryForCustomer = 500;
$request->cost->paymentMethod = 'CASH';
$request->cost->paymentMethod = $request->cost::PAYMENT_METHOD_CASH;

$contact = $request->addContact();

$contact->type = 'RECIPIENT';
$contact->type = $contact::TYPE_RECIPIENT;
$contact->phone = '+79266056128';
$contact->firstName = 'Василий';
$contact->lastName = 'Юрочкин';
Expand Down
14 changes: 7 additions & 7 deletions examples/100_SubmitOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
declare(strict_types=1);

use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\CreateOrderRequest;
use YDeliverySDK\Requests\SubmitOrderRequest;
use YDeliverySDK\Requests;

include_once 'vendor/autoload.php';

Expand All @@ -38,7 +37,7 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$request = new CreateOrderRequest();
$request = new Requests\CreateOrderRequest();
$request->deliveryType = $request::DELIVERY_TYPE_COURIER;
$request->senderId = (int) $_SERVER['YANDEX_SHOP_ID'];
$response = $client->sendCreateOrderRequest($request);
Expand All @@ -55,8 +54,9 @@
return;
}

$request = new SubmitOrderRequest();
$request->orderIds = [$response->id];
$request = new Requests\SubmitOrderRequest([
$response->id,
]);

$response = $client->sendSubmitOrderRequest($request);

Expand All @@ -72,6 +72,6 @@
return;
}

foreach ($response as $order) {
\var_dump($order->orderId);
foreach ($response as $submittedOrder) {
\var_dump($submittedOrder->orderId);
}
3 changes: 1 addition & 2 deletions examples/110_CreateAndSubmitOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\CreateOrderRequest;
use YDeliverySDK\Requests\DeliveryOptionsRequest;
use YDeliverySDK\Requests\OrderLabelRequest;
use YDeliverySDK\Requests\SubmitOrderRequest;

include_once 'vendor/autoload.php';
Expand Down Expand Up @@ -219,7 +218,7 @@
echo "Confirmed order: {$order->orderId}\n";
}

$response = $client->sendOrderLabelRequest(new OrderLabelRequest($order->orderId));
$response = $client->getLabel($order->orderId);

if ($response->hasErrors()) {
// Обрабатываем ошибки
Expand Down
11 changes: 6 additions & 5 deletions examples/120_OrdersSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

use CommonSDK\Types\HTTPErrorResponse;
use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\OrdersSearchRequest;
use YDeliverySDK\Requests;

include_once 'vendor/autoload.php';

Expand All @@ -40,11 +40,12 @@
/** @var \YDeliverySDK\Client $client */
$client = $builder->build();

$request = new OrdersSearchRequest([
$request = new Requests\OrdersSearchRequest([
(int) $_SERVER['YANDEX_SHOP_ID'],
]);
$request->term = '+79266056128';
$request->size = 10;

$request->term = 'Новосибирск';
$request->statuses[] = $request->statuses::CANCELLED;

$logger->addFile('orders-search-request.json');
$logger->addFile('orders-search-response.json');
Expand Down Expand Up @@ -78,7 +79,7 @@
continue;
}

$response = $client->makeDeleteOrderRequest($order->id);
$response = $client->deleteOrder($order->id);

if ($response->hasErrors()) {
if ($response instanceof HTTPErrorResponse) {
Expand Down
10 changes: 4 additions & 6 deletions examples/130_UpdateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
declare(strict_types=1);

use Tests\YDeliverySDK\Integration\DebuggingLogger;
use YDeliverySDK\Requests\CreateOrderRequest;
use YDeliverySDK\Requests\DeliveryOptionsRequest;
use YDeliverySDK\Requests\UpdateOrderRequest;
use YDeliverySDK\Requests;

include_once 'vendor/autoload.php';

Expand Down Expand Up @@ -73,7 +71,7 @@
/**
* Получим тарифы.
*/
$request = new DeliveryOptionsRequest();
$request = new Requests\DeliveryOptionsRequest();

$request->senderId = $_SERVER['YANDEX_SHOP_ID'];

Expand Down Expand Up @@ -115,7 +113,7 @@
/**
* Создадим заказ без данных.
*/
$request = new CreateOrderRequest();
$request = new Requests\CreateOrderRequest();
$request->deliveryType = $request::DELIVERY_TYPE_COURIER;
$request->comment = 'Пустой тестовый заказ.';
$request->senderId = (int) $_SERVER['YANDEX_SHOP_ID'];
Expand All @@ -142,7 +140,7 @@
/**
* Наполним заказ данными.
*/
$requestBuilder = UpdateOrderRequest::builder($order->id, $deliveryMethod, $location);
$requestBuilder = Requests\UpdateOrderRequest::builder($order->id, $deliveryMethod, $location);
$requestBuilder->setPostalCode($postalCode);
$request = $requestBuilder->build();

Expand Down
Loading

0 comments on commit ad2e60c

Please sign in to comment.