1
0
mirror of synced 2024-11-23 13:56:06 +03:00
PHP client for RetailCRM API
Go to file
Alex Lushpai 5be40d1d09 Merge pull request #27 from gwinn/master
prices methods: get, edit, upload
2016-09-21 00:12:23 +03:00
lib/RetailCrm prices methods: get, edit, upload 2016-09-21 00:09:24 +03:00
tests prices methods: get, edit, upload 2016-09-21 00:09:24 +03:00
.gitignore PSR-2, refactoring, tests 2016-03-12 01:54:33 +03:00
.travis.yml remove phpunit from vendor 2016-07-22 01:08:09 +03:00
apigen.neon fix apigen config 2016-08-10 00:35:46 +03:00
composer.json remove phpunit from vendor 2016-07-22 01:04:38 +03:00
LICENSE Create LICENSE 2015-02-02 16:21:11 +03:00
phpunit.xml.dist update tests 2016-07-22 01:01:47 +03:00
phpunit.xsd packs tests 2016-01-09 15:24:12 +03:00
README.md first alpha 2016-07-11 14:22:06 +03:00
README.ru.md first alpha 2016-07-11 14:22:06 +03:00

retailCRM API PHP client

PHP-client for retailCRM API.

Use API documentation

Requirements

  • PHP 5.3 and above
  • PHP's cURL support

Install

  1. Get composer

  2. Run into your project directory:

composer require retailcrm/api-client-php ~4.0.0 --no-dev

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.pro',
    'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH'
);


try {
    $response = $client->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.pro',
    '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 "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']);
    //}
}