1
0
mirror of synced 2024-11-21 21:06:07 +03:00
PHP client for RetailCRM API
Go to file
Uryvskiy Dima 805844cd32 Add phpdoc
2024-08-02 14:44:58 +03:00
.github/workflows PHP 8.3 support (#193) 2024-07-03 18:14:17 +03:00
lib/RetailCrm Add phpdoc 2024-08-02 14:44:58 +03:00
tests Add method to get of currencies list (#182) 2023-11-27 15:06:47 +03:00
.gitignore add ordersLoyaltyApply method (#169) 2023-06-21 12:57:37 +03:00
composer.json PHP 8.3 support (#193) 2024-07-03 18:14:17 +03:00
LICENSE Update product name, cleanup annotations (#96) 2020-12-15 13:32:52 +03:00
phpunit.xml.dist files methods 2019-08-30 14:10:52 +03:00
README.md Update product name, cleanup annotations (#96) 2020-12-15 13:32:52 +03:00

Build Status Covarage 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
  • PHP's JSON support
  • PHP's Fileinfo 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.pro',
    '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.pro',
    'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
    \RetailCrm\ApiClient::V5
);

try {
    $response = $client->request->ordersCreate(array(
        'externalId' => 'some-shop-order-id',
        'firstName' => 'John',
        'lastName' => 'Doe',
        'items' => array(
            //...
        ),
        'delivery' => array(
            'code' => 'fedex',
        )
    ));
} 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']);
    //}
}

Set custom headers and client timeout

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

$options = new \RetailCrm\Http\RequestOptions(
    ['X-Rlimit-Token' => 'example_token'], // array of custom headers
    10 // client timeout (in seconds)
);

$client->request->setOptions($options);