PHP client for RetailCRM API
30dfcc7c68
[fix] fileDownload and fileUpload method works properly now |
||
---|---|---|
lib/RetailCrm | ||
tests | ||
.gitignore | ||
.travis.yml | ||
composer.json | ||
LICENSE | ||
phpunit.xml.dist | ||
README.md |
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
-
Get composer
-
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']);
//}
}