RetailCRM API Client

Delivery extends AbstractApiResourceGroup

Class Delivery

Tags
category

Delivery

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Methods

calculate()  : DeliveryCalculateResponse
Makes POST "/api/v5/delivery/calculate" request.
shipments()  : DeliveryShipmentsResponse
Makes GET "/api/v5/delivery/shipments" request.
shipmentsCreate()  : DeliveryShipmentsCreateResponse
Makes POST "/api/v5/delivery/shipments/create" request.
shipmentsEdit()  : DeliveryShipmentsCreateResponse
Makes POST "/api/v5/delivery/shipments/{id}/edit" request.
shipmentsGet()  : DeliveryShipmentsGetResponse
Makes GET "/api/v5/delivery/shipments/{id}" request.
tracking()  : SuccessResponse
Makes POST "/api/v5/delivery/generic/{subcode}/tracking" request.

Methods

calculate()

Makes POST "/api/v5/delivery/calculate" request.

public calculate(DeliveryCalculateRequest $request) : DeliveryCalculateResponse

Example:

use RetailCrm\Api\Enum\CountryCodeIso3166;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Delivery\SerializedOrder;
use RetailCrm\Api\Model\Entity\Delivery\SerializedOrderDelivery;
use RetailCrm\Api\Model\Entity\Delivery\SerializedOrderProduct;
use RetailCrm\Api\Model\Entity\Delivery\TimeInterval;
use RetailCrm\Api\Model\Entity\Orders\Delivery\OrderDeliveryAddress;
use RetailCrm\Api\Model\Request\Delivery\DeliveryCalculateRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$delivery                      = new SerializedOrderDelivery();
$delivery->address             = new OrderDeliveryAddress();
$delivery->date                = (new DateTime())->add(new DateInterval('P1D'));
$delivery->time                = TimeInterval::withCustomInterval('from 9:00 am to 18:00 pm');
$delivery->address->index      = '12010';
$delivery->address->building   = '9850';
$delivery->address->countryIso = CountryCodeIso3166::UNITED_STATES_OF_AMERICA;
$delivery->address->city       = 'New York';
$delivery->address->street     = 'Griffin Ave.';

$item                        = new SerializedOrderProduct();
$item->initialPrice          = 1000.0;
$item->discountManualPercent = 5.0;
$item->quantity              = 10;

$order           = new SerializedOrder();
$order->delivery = $delivery;
$order->items    = [$item];
$order->height   = 100;
$order->width    = 100;
$order->weight   = 100;
$order->length   = 100;

$request                    = new DeliveryCalculateRequest();
$request->order             = $order;
$request->deliveryTypeCodes = ['2', '3', '8', '9', '10', '11'];

try {
    $response = $client->delivery->calculate($request);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Calculate result: ' . print_r($response->calculations, true);
Parameters
$request : DeliveryCalculateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
DeliveryCalculateResponse

shipments()

Makes GET "/api/v5/delivery/shipments" request.

public shipments([DeliveryShipmentsRequest|null $request = null ]) : DeliveryShipmentsResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Delivery\ApiDeliveryShipmentFilterType;
use RetailCrm\Api\Model\Request\Delivery\DeliveryShipmentsRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$request                      = new DeliveryShipmentsRequest();
$request->filter              = new ApiDeliveryShipmentFilterType();
$request->filter->dateFrom    = '2020-01-15';
$request->filter->orderNumber = '6911C';

try {
    $response = $client->delivery->shipments($request);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Shipments: ' . print_r($response->deliveryShipments, true);
Parameters
$request : DeliveryShipmentsRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
DeliveryShipmentsResponse

shipmentsCreate()

Makes POST "/api/v5/delivery/shipments/create" request.

public shipmentsCreate(DeliveryShipmentsCreateRequest $request) : DeliveryShipmentsCreateResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Delivery\DeliveryShipment;
use RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder;
use RetailCrm\Api\Model\Entity\Delivery\TimeInterval;
use RetailCrm\Api\Model\Request\Delivery\DeliveryShipmentsCreateRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$shipment                  = new DeliveryShipment();
$shipment->integrationCode = 'boxberry-249';
$shipment->externalId      = 'test_30';
$shipment->managerId       = 19;
$shipment->store           = 'main1';
$shipment->date            = new DateTime();
$shipment->time            = TimeInterval::withTextInterval('18:00', '22:00');
$shipment->orders          = [
    SerializedEntityOrder::withNumber('8124705923428910')
];

$request                   = new DeliveryShipmentsCreateRequest();
$request->site             = 'aliexpress';
$request->deliveryType     = 'boxberry';
$request->deliveryShipment = $shipment;

try {
    $response = $client->delivery->shipmentsCreate($request);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

printf('Created shipment %d with status "%s"', $response->id, $response->status);
Parameters
$request : DeliveryShipmentsCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
DeliveryShipmentsCreateResponse

shipmentsEdit()

Makes POST "/api/v5/delivery/shipments/{id}/edit" request.

public shipmentsEdit(string $id, DeliveryShipmentsCreateRequest $request) : DeliveryShipmentsCreateResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Delivery\DeliveryShipment;
use RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder;
use RetailCrm\Api\Model\Entity\Delivery\TimeInterval;
use RetailCrm\Api\Model\Request\Delivery\DeliveryShipmentsCreateRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$shipment                  = new DeliveryShipment();
$shipment->integrationCode = 'boxberry-249';
$shipment->externalId      = 'test_30';
$shipment->managerId       = 19;
$shipment->store           = 'main1';
$shipment->date            = new DateTime();
$shipment->time            = TimeInterval::withTextInterval('18:00', '22:00');
$shipment->orders          = [
    SerializedEntityOrder::withNumber('8124705923428910')
];

$request                   = new DeliveryShipmentsCreateRequest();
$request->site             = 'aliexpress';
$request->deliveryType     = 'boxberry';
$request->deliveryShipment = $shipment;

try {
    $response = $client->delivery->shipmentsEdit('1', $request);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

printf('Edited shipment %d with status "%s"', $response->id, $response->status);
Parameters
$id : string
$request : DeliveryShipmentsCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
DeliveryShipmentsCreateResponse

shipmentsGet()

Makes GET "/api/v5/delivery/shipments/{id}" request.

public shipmentsGet(string $id) : DeliveryShipmentsGetResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

try {
    $response = $client->delivery->shipmentsGet('1');
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Shipment №1: ' . print_r($response->deliveryShipment, true);
Parameters
$id : string
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
DeliveryShipmentsGetResponse

tracking()

Makes POST "/api/v5/delivery/generic/{subcode}/tracking" request.

public tracking(string $subcode, TrackingRequest $request) : SuccessResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Delivery\RequestStatusUpdateItem;
use RetailCrm\Api\Model\Entity\Delivery\StatusInfo;
use RetailCrm\Api\Model\Request\Delivery\TrackingRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$status            = new StatusInfo();
$status->code      = 'code';
$status->comment   = 'comment';
$status->updatedAt = new DateTime();

$item              = new RequestStatusUpdateItem();
$item->deliveryId  = 'boxberry';
$item->trackNumber = 'track';
$item->cost        = 100;
$item->history     = [$status];

$request               = new TrackingRequest();
$request->statusUpdate = [$item];

try {
    $response = $client->delivery->tracking('boxberry-1-5f8064212c612', $request);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}
Parameters
$subcode : string
$request : TrackingRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

        
On this page

Search results