1
0
mirror of synced 2024-11-24 22:36:06 +03:00
PHP client for RetailCRM API
Go to file
2014-11-06 16:39:55 +03:00
lib/RetailCrm Added reference and statistic methods 2014-11-06 16:39:55 +03:00
tests Added reference and statistic methods 2014-11-06 16:39:55 +03:00
.gitignore New version of PHP client for API v3. Not all methods implements 2014-11-06 02:44:52 +03:00
composer.json Removed docs 2014-11-06 14:10:48 +03:00
phpunit.xml.dist New version of PHP client for API v3. Not all methods implements 2014-11-06 02:44:52 +03:00
README.md Fix examples 2014-11-06 11:31:47 +03:00

PHP client for retailCRM API

PHP client for retailCRM API.

Requirements

  • PHP version 5.3 and above
  • PHP-extension CURL

Installation

  1. Install composer

  2. Run:

composer require retailcrm/api-client-php 3.0

Usage

Example of the receipt of order:


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

try {
    $response = $client->ordersGet('M-2342');
} catch (\RetailCrm\Exception\CurlException $e) {
    echo "CRM 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 of the order receipt: [Code %s] %s", 
        $response->getStatusCode(),
        $response->getErrorMsg()
    );
}

Example of the order creating:


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

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

if ($response->isSuccessful()) {
    if (201 === $response->getStatusCode()) {
        echo 'Order created successfully! Order ID in CRM = ' . $response->id;
            // or $response['id'];
            // or $response->getId();
    } else {
        echo 'Order updated successfully!';
    }
} else {
    echo sprintf(
        "Error of the order creating: [Code %s] %s", 
        $response->getStatusCode(),
        $response->getErrorMsg()
    );
}