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

Commit

Permalink
Merge branch 'main' into dependabot/composer/vimeo/psalm-tw-3.18.2or-…
Browse files Browse the repository at this point in the history
…tw-4.0.0
  • Loading branch information
sanmai committed Nov 4, 2020
2 parents 36a6585 + c271abb commit 2e77e72
Show file tree
Hide file tree
Showing 40 changed files with 1,100 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -21,6 +21,7 @@ jobs:
include:
- { php-version: '7.3', dependencies: '--prefer-lowest' }
- { php-version: '8.0', dependencies: '--ignore-platform-req=php' }
- { php-version: '8.1', dependencies: '--ignore-platform-req=php' }
- { php-version: '7.3', make-args: 'PHPUNIT_GROUP=integration' }

continue-on-error: ${{ matrix.php-version == '8.0' }}
Expand All @@ -31,7 +32,7 @@ jobs:
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -38,13 +38,12 @@

Работа с большинством методов 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/)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
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
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
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
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
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('Новосибирская область, Новосибирск');

$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
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
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
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
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
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);
}
5 changes: 2 additions & 3 deletions examples/110_CreateAndSubmitOrder.php
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 @@ -216,10 +215,10 @@
}

foreach ($response as $order) {
\var_dump($order->orderId);
echo "Confirmed order: {$order->orderId}\n";
}

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

if ($response->hasErrors()) {
// Обрабатываем ошибки
Expand Down
20 changes: 15 additions & 5 deletions examples/120_OrdersSearch.php
Expand Up @@ -26,8 +26,9 @@

declare(strict_types=1);

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

include_once 'vendor/autoload.php';

Expand All @@ -39,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 All @@ -65,6 +67,10 @@
foreach ($orders as $order) {
echo "Page {$orders->pageNumber}\t{$order->id}\t{$order->status}\t{$order->comment}\n";

if (!\is_string($order->comment)) {
continue;
}

if (\strpos($order->comment, 'тестовый заказ') === false) {
continue;
}
Expand All @@ -73,9 +79,13 @@
continue;
}

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

if ($response->hasErrors()) {
if ($response instanceof HTTPErrorResponse) {
echo $response->getBody();
}

// Обрабатываем ошибки
foreach ($response->getMessages() as $message) {
if ($message->getErrorCode() !== '') {
Expand Down

0 comments on commit 2e77e72

Please sign in to comment.