1
0
mirror of synced 2024-11-23 13:56:06 +03:00
api-client-php/README.md

103 lines
2.3 KiB
Markdown
Raw Permalink Normal View History

2016-03-12 01:54:33 +03:00
# retailCRM API PHP client
2013-07-02 12:37:54 +04:00
2016-07-11 14:22:06 +03:00
PHP-client for [retailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion4).
2013-07-03 18:13:25 +04:00
2016-03-12 01:54:33 +03:00
Use [API documentation](http://retailcrm.github.io/api-client-php)
2014-11-13 13:04:11 +03:00
2016-03-12 01:54:33 +03:00
## Requirements
2013-07-03 18:13:25 +04:00
2016-03-12 01:54:33 +03:00
* PHP 5.3 and above
* PHP's cURL support
2013-07-04 12:44:41 +04:00
2016-03-12 01:54:33 +03:00
## Install
2013-07-04 12:44:41 +04:00
2016-03-12 01:54:33 +03:00
1) Get [composer](https://getcomposer.org/download/)
2013-07-04 12:44:41 +04:00
2016-03-12 01:54:33 +03:00
2) Run into your project directory:
```bash
2017-04-27 14:30:14 +03:00
composer require retailcrm/api-client-php 4.* --no-dev
2013-10-08 11:19:38 +04:00
```
2014-11-06 02:55:09 +03:00
2016-03-12 01:54:33 +03:00
If you have not used `composer` before, include autoloader into your project.
2014-11-07 13:05:40 +03:00
```php
require 'path/to/vendor/autoload.php';
```
2016-03-12 01:54:33 +03:00
## Usage
2014-11-06 02:55:09 +03:00
2016-03-12 01:54:33 +03:00
### Get order
2014-11-07 11:31:33 +03:00
```php
2014-11-06 02:55:09 +03:00
$client = new \RetailCrm\ApiClient(
2016-04-10 13:57:22 +03:00
'https://demo.retailcrm.pro',
2014-11-06 02:55:09 +03:00
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH'
);
2014-11-07 11:31:33 +03:00
2014-11-06 02:55:09 +03:00
try {
$response = $client->ordersGet('M-2342');
} catch (\RetailCrm\Exception\CurlException $e) {
2016-03-12 01:54:33 +03:00
echo "Connection error: " . $e->getMessage();
2014-11-06 02:55:09 +03:00
}
if ($response->isSuccessful()) {
echo $response->order['totalSumm'];
2016-03-12 01:54:33 +03:00
// or $response['order']['totalSumm'];
// or
2014-11-06 02:55:09 +03:00
// $order = $response->getOrder();
// $order['totalSumm'];
2014-11-06 11:31:47 +03:00
} else {
echo sprintf(
2016-03-12 01:54:33 +03:00
"Error: [HTTP-code %s] %s",
2014-11-06 11:31:47 +03:00
$response->getStatusCode(),
$response->getErrorMsg()
);
2016-03-09 02:34:13 +03:00
2016-03-12 01:54:33 +03:00
// error details
2014-11-07 11:34:54 +03:00
//if (isset($response['errors'])) {
// print_r($response['errors']);
//}
2014-11-06 02:55:09 +03:00
}
2014-11-06 03:18:39 +03:00
```
2016-03-12 01:54:33 +03:00
### Create order
2014-11-06 03:18:39 +03:00
```php
$client = new \RetailCrm\ApiClient(
2016-04-10 13:57:22 +03:00
'https://demo.retailcrm.pro',
2014-11-06 03:18:39 +03:00
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH'
);
try {
$response = $client->ordersCreate(array(
'externalId' => 'some-shop-order-id',
'firstName' => 'Vasily',
'lastName' => 'Pupkin',
'items' => array(
//...
),
2014-11-06 03:20:32 +03:00
'delivery' => array(
2014-11-06 03:18:39 +03:00
'code' => 'russian-post',
)
));
} catch (\RetailCrm\Exception\CurlException $e) {
2016-03-12 01:54:33 +03:00
echo "Connection error: " . $e->getMessage();
2014-11-06 03:18:39 +03:00
}
2014-11-06 19:15:51 +03:00
if ($response->isSuccessful() && 201 === $response->getStatusCode()) {
2016-03-12 01:54:33 +03:00
echo 'Order successfully created. Order ID into retailCRM = ' . $response->id;
// or $response['id'];
// or $response->getId();
2014-11-06 11:31:47 +03:00
} else {
echo sprintf(
2016-03-12 01:54:33 +03:00
"Error: [HTTP-code %s] %s",
2014-11-06 11:31:47 +03:00
$response->getStatusCode(),
$response->getErrorMsg()
);
2014-11-07 11:34:54 +03:00
2016-03-12 01:54:33 +03:00
// error details
2014-11-07 11:34:54 +03:00
//if (isset($response['errors'])) {
// print_r($response['errors']);
//}
2014-11-06 03:18:39 +03:00
}
2014-11-06 17:24:44 +03:00
```