1
0
mirror of synced 2024-11-24 06:16:27 +03:00
PHP client for RetailCRM API
Go to file
2019-04-23 14:19:41 +03:00
lib/RetailCrm update phpdoc 2019-04-23 14:19:41 +03:00
tests Add LimitException (#61) 2018-02-27 12:00:09 +03:00
.gitignore PSR-2, refactoring, tests 2016-03-12 01:54:33 +03:00
.travis.yml Fix CostsDelete method (#62) 2018-03-06 14:01:00 +03:00
apigen.neon update api docs requirements 2018-02-21 11:07:39 +03:00
composer.json add getters for response & raw response 2019-02-28 18:27:27 +03:00
LICENSE Create LICENSE 2015-02-02 16:21:11 +03:00
phpunit.xml.dist minor improvements, move test data to env 2018-02-20 17:51:01 +03:00
phpunit.xsd packs tests 2016-01-09 15:24:12 +03:00
README.md Update README (#63) 2018-03-20 21:28:14 +03:00

Build Status Latest stable PHP from Packagist

retailCRM API PHP client

This is php retailCRM API client. This library allows to use all available API versions. API documentation

Requirements

  • PHP 5.4 and above
  • PHP's cURL support

Install

  1. Get composer

  2. Run into your project directory:

composer require retailcrm/api-client-php ~5.0

If you have not used composer before, include autoloader into your project.

require 'path/to/vendor/autoload.php';

Usage

Get order

$client = new \RetailCrm\ApiClient(
    'https://demo.retailcrm.ru',
    'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
    \RetailCrm\ApiClient::V5
);

try {
    $response = $client->request->ordersGet('M-2342');
} catch (\RetailCrm\Exception\CurlException $e) {
    echo "Connection error: " . $e->getMessage();
}

if ($response->isSuccessful()) {
    echo $response->order['totalSumm'];
    // or $response['order']['totalSumm'];
    // or
    //    $order = $response->getOrder();
    //    $order['totalSumm'];
} else {
    echo sprintf(
        "Error: [HTTP-code %s] %s",
        $response->getStatusCode(),
        $response->getErrorMsg()
    );

    // error details
    //if (isset($response['errors'])) {
    //    print_r($response['errors']);
    //}
}

Create order


$client = new \RetailCrm\ApiClient(
    'https://demo.retailcrm.ru',
    'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
    \RetailCrm\ApiClient::V4
);

try {
    $response = $client->request->ordersCreate(array(
        'externalId' => 'some-shop-order-id',
        'firstName' => 'Vasily',
        'lastName' => 'Pupkin',
        'items' => array(
            //...
        ),
        'delivery' => array(
            'code' => 'russian-post',
        )
    ));
} catch (\RetailCrm\Exception\CurlException $e) {
    echo "Connection error: " . $e->getMessage();
}

if ($response->isSuccessful() && 201 === $response->getStatusCode()) {
    echo 'Order successfully created. Order ID into retailCRM = ' . $response->id;
        // or $response['id'];
        // or $response->getId();
} else {
    echo sprintf(
        "Error: [HTTP-code %s] %s",
        $response->getStatusCode(),
        $response->getErrorMsg()
    );

    // error details
    //if (isset($response['errors'])) {
    //    print_r($response['errors']);
    //}
}

Documentation