RetailCRM API Client

Orders extends AbstractApiResourceGroup

Class Orders

Tags
category

Orders

SuppressWarnings

(PHPMD.ExcessiveClassLength)

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Methods

cancelBonusOperations()  : OrdersGetResponse
Makes POST "/api/v5/orders/loyalty/cancel-bonus-operations" request.
combine()  : OrdersCombineResponse
Makes POST "/api/v5/orders/combine" request.
create()  : OrdersCreateResponse
Makes POST "/api/v5/orders/create" request.
deliveryCancel()  : SuccessResponse
Makes POST "/api/v5/orders/{externalId}/delivery/cancel" request.
edit()  : OrdersCreateResponse
Makes POST "/api/v5/orders/{externalId}/edit" request.
fixExternalIds()  : SuccessResponse
Makes POST "/api/v5/orders/fix-external-ids" request.
get()  : OrdersGetResponse
Makes GET "/api/v5/orders" request.
history()  : OrdersHistoryResponse
Makes GET "/api/v5/orders/history" request.
linksCreate()  : SuccessResponse
Makes POST "/api/v5/orders/links/create" request.
list()  : OrdersResponse
Makes GET "/api/v5/orders" request.
loyaltyApply()  : OrdersLoyaltyApplyResponse
Makes POST "/api/v5/orders/loyalty/apply" request.
paymentsCreate()  : IdResponse
Makes POST "/api/v5/orders/payments/create" request.
paymentsDelete()  : SuccessResponse
Makes POST "/api/v5/orders/payments/{id}/delete" request.
paymentsEdit()  : IdResponse
Makes POST "/api/v5/orders/payments/{id}/edit" request.
platesPrint()  : FilesDownloadResponse
Makes GET "/api/v5/orders/{externalId}/plates/{plateId}/print" request.
statuses()  : OrdersStatusesResponse
Makes GET "/api/v5/orders/statuses" request.
upload()  : OrdersUploadResponse
Makes POST "/api/v5/orders/upload" request.

Methods

cancelBonusOperations()

Makes POST "/api/v5/orders/loyalty/cancel-bonus-operations" request.

public cancelBonusOperations(OrderLoyaltyCancelBonusOperationsRequest $request) : OrdersGetResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder;
use RetailCrm\Api\Model\Request\Orders\OrderLoyaltyCancelBonusOperationsRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new OrderLoyaltyCancelBonusOperationsRequest(
    SerializedEntityOrder::withId(7751),
    'bitrix-test'
);

try {
    $response = $client->orders->cancelBonusOperations($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 'Current loyalty account balance: ' . $response->order->loyaltyAccount->amount . ' bonuses.';
Parameters
$request : OrderLoyaltyCancelBonusOperationsRequest
Tags
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
throws
ApiExceptionInterface
throws
ClientExceptionInterface
Return values
OrdersGetResponse

combine()

Makes POST "/api/v5/orders/combine" request.

public combine(OrdersCombineRequest $request) : OrdersCombineResponse

Example:

use RetailCrm\Api\Enum\CombineTechnique;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Orders\SerializedOrderReference;
use RetailCrm\Api\Model\Request\Orders\OrdersCombineRequest;

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

$request              = new OrdersCombineRequest();
$request->order       = new SerializedOrderReference(7143);
$request->resultOrder = new SerializedOrderReference(7140);
$request->technique   = CombineTechnique::SUMM;

try {
    $response = $client->orders->combine($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 'Combine errors: ' . print_r($response->errors, true);
Parameters
$request : OrdersCombineRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersCombineResponse

create()

Makes POST "/api/v5/orders/create" request.

public create(OrdersCreateRequest $request) : OrdersCreateResponse

Example:

use RetailCrm\Api\Enum\CountryCodeIso3166;
use RetailCrm\Api\Enum\Customers\CustomerType;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Orders\Delivery\OrderDeliveryAddress;
use RetailCrm\Api\Model\Entity\Orders\Delivery\SerializedOrderDelivery;
use RetailCrm\Api\Model\Entity\Orders\Items\Offer;
use RetailCrm\Api\Model\Entity\Orders\Items\OrderProduct;
use RetailCrm\Api\Model\Entity\Orders\Items\PriceType;
use RetailCrm\Api\Model\Entity\Orders\Items\Unit;
use RetailCrm\Api\Model\Entity\Orders\Order;
use RetailCrm\Api\Model\Entity\Orders\Payment;
use RetailCrm\Api\Model\Entity\Orders\SerializedRelationCustomer;
use RetailCrm\Api\Model\Request\Orders\OrdersCreateRequest;

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

$request         = new OrdersCreateRequest();
$order           = new Order();
$payment         = new Payment();
$delivery        = new SerializedOrderDelivery();
$deliveryAddress = new OrderDeliveryAddress();
$offer           = new Offer();
$item            = new OrderProduct();

$payment->type   = 'bank-card';
$payment->status = 'paid';
$payment->amount = 1000;
$payment->paidAt = new DateTime();

$deliveryAddress->index      = '344001';
$deliveryAddress->countryIso = CountryCodeIso3166::RUSSIAN_FEDERATION;
$deliveryAddress->region     = 'Ростовская область';
$deliveryAddress->city       = 'г. Ростов-на-Дону';
$deliveryAddress->street     = 'ул. Пушкинская';
$deliveryAddress->building   = '10';

$delivery->address = $deliveryAddress;
$delivery->cost    = 0;
$delivery->netCost = 0;

$offer->name        = 'Сборка №1445123';
$offer->displayName = 'Сборка №1445123';
$offer->xmlId       = 'tGunLo27jlPGmbA8BrHxY2';
$offer->article     = '14451445-14451445';
$offer->unit        = new Unit('796', 'Штука', 'шт');

$item->offer         = $offer;
$item->priceType     = new PriceType('base');
$item->quantity      = 1;
$item->purchasePrice = 60;

$order->delivery      = $delivery;
$order->items         = [$item];
$order->payments      = [$payment];
$order->orderType     = 'test';
$order->orderMethod   = 'phone';
$order->countryIso    = CountryCodeIso3166::RUSSIAN_FEDERATION;
$order->firstName     = 'Test';
$order->lastName      = 'User';
$order->patronymic    = 'Patronymic';
$order->phone         = '89003005069';
$order->email         = 'testuser12345678901@example.com';
$order->managerId     = 28;
$order->customer      = SerializedRelationCustomer::withIdAndType(
    4924,
    CustomerType::CUSTOMER
);
$order->status        = 'assembling';
$order->statusComment = 'Assembling order';
$order->weight        = 1000;
$order->shipmentStore = 'main12';
$order->shipmentDate  = (new DateTime())->add(new DateInterval('P7D'));
$order->shipped       = false;
$order->customFields  = [
    "galka" => false,
    "test_number" => 0,
    "otpravit_dozakaz" => false,
];

$request->order = $order;
$request->site  = 'moysklad';

try {
    $response = $client->orders->create($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 order id = %d with following data: %s',
    $response->id,
    print_r($response->order, true)
);
Parameters
$request : OrdersCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersCreateResponse

deliveryCancel()

Makes POST "/api/v5/orders/{externalId}/delivery/cancel" request.

public deliveryCancel(int|string $identifier, OrderDeliveryCancelRequest $request) : SuccessResponse

Example:

use RetailCrm\Api\Enum\ByIdentifier;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\Orders\OrderDeliveryCancelRequest;

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

$request        = new OrderDeliveryCancelRequest();
$request->by    = ByIdentifier::EXTERNAL_ID;
$request->force = true;

try {
    $response = $client->orders->deliveryCancel('8123522898559160', $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 'Order delivery cancel result: ' . print_r($response->success, true);
Parameters
$identifier : int|string
$request : OrderDeliveryCancelRequest
Tags
throws
ApiException
throws
ClientException
throws
HandlerException
throws
ApiExceptionInterface
Return values
SuccessResponse

edit()

Makes POST "/api/v5/orders/{externalId}/edit" request.

public edit(int|string $identifier, OrdersEditRequest $request) : OrdersCreateResponse

Example:

use RetailCrm\Api\Enum\ByIdentifier;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Orders\Order;
use RetailCrm\Api\Model\Request\Orders\OrdersEditRequest;

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

$order                 = new Order();
$order->managerComment = 'Manager comment';

$request        = new OrdersEditRequest();
$request->by    = ByIdentifier::EXTERNAL_ID;
$request->site  = 'aliexpress';
$request->order = $order;

try {
    $response = $client->orders->edit('8123522898559160', $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 'Edited order: ' . print_r($response->order, true);
Parameters
$identifier : int|string
$request : OrdersEditRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersCreateResponse

fixExternalIds()

Makes POST "/api/v5/orders/fix-external-ids" request.

public fixExternalIds(OrdersFixExternalIdsRequest $request) : SuccessResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\FixExternalRow;
use RetailCrm\Api\Model\Request\Orders\OrdersFixExternalIdsRequest;

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

$request = new OrdersFixExternalIdsRequest();
$request->orders = [
    new FixExternalRow(1, 'external_1'),
    new FixExternalRow(2, 'external_2'),
];

try {
    $response = $client->orders->fixExternalIds($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
$request : OrdersFixExternalIdsRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

get()

Makes GET "/api/v5/orders" request.

public get(int|string $identifier, BySiteRequest|null $request) : OrdersGetResponse

Example:

use RetailCrm\Api\Enum\ByIdentifier;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\BySiteRequest;

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

try {
    $response = $client->orders->get(
        '8123522898559160',
        new BySiteRequest(ByIdentifier::EXTERNAL_ID, 'aliexpress')
    );
} 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 'Orders: ' . print_r($response->order, true);
Parameters
$identifier : int|string
$request : BySiteRequest|null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersGetResponse

history()

Makes GET "/api/v5/orders/history" request.

public history([OrdersHistoryRequest|null $request = null ]) : OrdersHistoryResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Orders\OrderHistoryFilterV4Type;
use RetailCrm\Api\Model\Request\Orders\OrdersHistoryRequest;

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

$request                  = new OrdersHistoryRequest();
$request->limit           = 100;
$request->page            = 1;
$request->filter          = new OrderHistoryFilterV4Type();
$request->filter->sinceId = 2691;

try {
    $response = $client->orders->history($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 'Orders history: ' . print_r($response->history, true);
Parameters
$request : OrdersHistoryRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersHistoryResponse

linksCreate()

Makes POST "/api/v5/orders/links/create" request.

public linksCreate(OrdersLinksCreateRequest $request) : SuccessResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder;
use RetailCrm\Api\Model\Entity\Orders\SerializedOrderLink;
use RetailCrm\Api\Model\Request\Orders\OrdersLinksCreateRequest;

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

$request                = new OrdersLinksCreateRequest();
$request->link          = new SerializedOrderLink();
$request->site          = 'aliexpress';
$request->link->orders  = [
    SerializedEntityOrder::withNumber('8123522898559160'),
    SerializedEntityOrder::withNumber('8123898472679160')
];
$request->link->comment = 'same client';

try {
    $response = $client->orders->linksCreate($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
$request : OrdersLinksCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

list()

Makes GET "/api/v5/orders" request.

public list([OrdersRequest|null $request = null ]) : OrdersResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Orders\OrderFilter;
use RetailCrm\Api\Model\Request\Orders\OrdersRequest;

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

$request = new OrdersRequest();
$request->filter = new OrderFilter();
$request->filter->ids = [7141];

try {
    $response = $client->orders->list($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 'Got orders: ' . print_r($response->orders, true);
Parameters
$request : OrdersRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersResponse

loyaltyApply()

Makes POST "/api/v5/orders/loyalty/apply" request.

public loyaltyApply(OrdersLoyaltyApplyRequest $request) : OrdersLoyaltyApplyResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder;
use RetailCrm\Api\Model\Request\Orders\OrdersLoyaltyApplyRequest;

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

$request          = new OrdersLoyaltyApplyRequest();
$request->site    = 'bitrix-test';
$request->order   = SerializedEntityOrder::withNumber('7');
$request->bonuses = 10;

try {
    $response = $client->orders->loyaltyApply($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 'Applied loyalty to order: ' . print_r($response->order, true);
Parameters
$request : OrdersLoyaltyApplyRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersLoyaltyApplyResponse

paymentsCreate()

Makes POST "/api/v5/orders/payments/create" request.

public paymentsCreate(OrdersPaymentsCreateRequest $request) : IdResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder;
use RetailCrm\Api\Model\Entity\Orders\SerializedPayment;
use RetailCrm\Api\Model\Request\Orders\OrdersPaymentsCreateRequest;

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

$request                   = new OrdersPaymentsCreateRequest();
$request->payment          = new SerializedPayment();
$request->payment->type    = 'bank-card';
$request->payment->amount  = 10000;
$request->payment->comment = 'Comment';
$request->payment->order   = SerializedEntityOrder::withNumber('8123522898559160');
$request->site             = 'aliexpress';

try {
    $response = $client->orders->paymentsCreate($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 'Created payment ID: ' . $response->id;
Parameters
$request : OrdersPaymentsCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
IdResponse

paymentsDelete()

Makes POST "/api/v5/orders/payments/{id}/delete" request.

public paymentsDelete(int $id) : SuccessResponse

Example:

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

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

try {
    $response = $client->orders->paymentsDelete(4562);
} 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);
    }
}
Parameters
$id : int
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

paymentsEdit()

Makes POST "/api/v5/orders/payments/{id}/edit" request.

public paymentsEdit(int|string $identifier, OrdersPaymentsCreateRequest $request) : IdResponse

Example:

use RetailCrm\Api\Enum\ByIdentifier;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Orders\SerializedPayment;
use RetailCrm\Api\Model\Request\Orders\OrdersPaymentsEditRequest;

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

$request                   = new OrdersPaymentsEditRequest();
$request->by               = ByIdentifier::ID;
$request->payment          = new SerializedPayment();
$request->payment->comment = 'Comment';
$request->site             = 'aliexpress';

try {
    $response = $client->orders->paymentsEdit(4562, $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 'Edited payment ID: ' . $response->id;
Parameters
$identifier : int|string
$request : OrdersPaymentsCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
IdResponse

platesPrint()

Makes GET "/api/v5/orders/{externalId}/plates/{plateId}/print" request.

public platesPrint(string|int $identifier, int $plateId, BySiteRequest $request) : FilesDownloadResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\BySiteRequest;

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

try {
    $request = new BySiteRequest();
    $request = new BySiteRequest('id', 'gray_sale_ym');

    $response = $client->orders->platesPrint(100, 18, $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('Saving downloaded file to "%s."', $response->fileName);
file_put_contents($response->fileName, $response->data->getContents());
Parameters
$identifier : string|int
$plateId : int
$request : BySiteRequest
Tags
throws
ApiException
throws
ClientException
throws
HandlerException
throws
ApiExceptionInterface
Return values
FilesDownloadResponse

statuses()

Makes GET "/api/v5/orders/statuses" request.

public statuses(OrdersStatusesRequest $request) : OrdersStatusesResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\Orders\OrdersStatusesRequest;

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

$request              = new OrdersStatusesRequest();
$request->externalIds = ['8123522898559160'];

try {
    $response = $client->orders->statuses($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 'Statuses: ' . print_r($response->orders, true);
Parameters
$request : OrdersStatusesRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersStatusesResponse

upload()

Makes POST "/api/v5/orders/upload" request.

public upload(OrdersUploadRequest $request) : OrdersUploadResponse

Example:

use RetailCrm\Api\Enum\CountryCodeIso3166;
use RetailCrm\Api\Enum\Customers\CustomerType;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Orders\Delivery\OrderDeliveryAddress;
use RetailCrm\Api\Model\Entity\Orders\Delivery\SerializedOrderDelivery;
use RetailCrm\Api\Model\Entity\Orders\Items\Offer;
use RetailCrm\Api\Model\Entity\Orders\Items\OrderProduct;
use RetailCrm\Api\Model\Entity\Orders\Items\PriceType;
use RetailCrm\Api\Model\Entity\Orders\Items\Unit;
use RetailCrm\Api\Model\Entity\Orders\Order;
use RetailCrm\Api\Model\Entity\Orders\Payment;
use RetailCrm\Api\Model\Entity\Orders\SerializedRelationCustomer;
use RetailCrm\Api\Model\Request\Orders\OrdersUploadRequest;

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

$request         = new OrdersUploadRequest();
$order           = new Order();
$payment         = new Payment();
$delivery        = new SerializedOrderDelivery();
$deliveryAddress = new OrderDeliveryAddress();
$offer           = new Offer();
$item            = new OrderProduct();

$payment->type   = 'bank-card';
$payment->status = 'paid';
$payment->amount = 1000;
$payment->paidAt = new DateTime();

$deliveryAddress->index      = '344001';
$deliveryAddress->countryIso = CountryCodeIso3166::RUSSIAN_FEDERATION;
$deliveryAddress->region     = 'Ростовская область';
$deliveryAddress->city       = 'г. Ростов-на-Дону';
$deliveryAddress->street     = 'ул. Пушкинская';
$deliveryAddress->building   = '10';

$delivery->address = $deliveryAddress;
$delivery->cost    = 0;
$delivery->netCost = 0;

$offer->name        = 'Сборка №1445123';
$offer->displayName = 'Сборка №1445123';
$offer->xmlId       = 'tGunLo27jlPGmbA8BrHxY2';
$offer->article     = '14451445-14451445';
$offer->unit        = new Unit('796', 'Штука', 'шт');

$item->offer         = $offer;
$item->priceType     = new PriceType('base');
$item->quantity      = 1;
$item->purchasePrice = 60;

$order->delivery      = $delivery;
$order->items         = [$item];
$order->payments      = [$payment];
$order->orderType     = 'test';
$order->orderMethod   = 'phone';
$order->countryIso    = CountryCodeIso3166::RUSSIAN_FEDERATION;
$order->firstName     = 'Test';
$order->lastName      = 'User';
$order->patronymic    = 'Patronymic';
$order->phone         = '89003005069';
$order->email         = 'testuser12345678901@example.com';
$order->managerId     = 28;
$order->customer      = SerializedRelationCustomer::withIdAndType(
    4924,
    CustomerType::CUSTOMER
);
$order->status        = 'assembling';
$order->statusComment = 'Assembling order';
$order->weight        = 1000;
$order->shipmentStore = 'main12';
$order->shipmentDate  = (new DateTime())->add(new DateInterval('P7D'));
$order->shipped       = false;
$order->customFields  = [
    "galka" => false,
    "test_number" => 0,
    "otpravit_dozakaz" => false,
];

$request->site  = 'moysklad';
$request->orders = [$order];

try {
    $response = $client->orders->upload($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 'Uploaded: ' . print_r($response->uploadedOrders, true);
Parameters
$request : OrdersUploadRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
OrdersUploadResponse

        
On this page

Search results