Skip to content

Commit

Permalink
GetPrice for v5 and add method for print sticker (#35)
Browse files Browse the repository at this point in the history
* iml: get price for v5
* iml: add method printTicket
  • Loading branch information
DmitryZagorulko authored and gwinn committed Dec 18, 2017
1 parent a4ca7b6 commit 6c6f878
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
20 changes: 19 additions & 1 deletion src/SaaS/Service/Iml/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,27 @@ public function calcOrderPrice(array $parameters = array())
);
}

return $this->client->makeRequest('GetPrice', 'GET', $parameters);
return $this->client->makeRequest('GetPrice', 'GET', $parameters, 'v5');
}

/**
* Print ticket
*
* @param array $parameters set of parameters request
*
* @return Responce
*/
public function printTicket(array $parameters = array())
{
if (empty($parameters) ){
throw new \InvalidArgumentException(
"parameters request must be not empty"
);
}

return $this->client->makeRequest('PrintBar', 'POST', $parameters);
}

/**
* Get reference delivery status
*
Expand Down
20 changes: 11 additions & 9 deletions src/SaaS/Service/Iml/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($login, $password) {
*
* @return Response
*/
public function makeRequest($path, $method, array $parameters = array()){
public function makeRequest($path, $method, array $parameters = array(), $version = false){

$headers = array('Content-Type: application/json');

Expand Down Expand Up @@ -87,16 +87,18 @@ public function makeRequest($path, $method, array $parameters = array()){
$timeouts = 600;
}

if (self::METHOD_GET === $method && in_array($path, $apiListMethods)){
$url = 'https://api.iml.ru/list/';
} elseif(self::METHOD_GET === $method && !in_array($path, $apiListMethods)){
$url = 'https://list.iml.ru/';
} else {
$url = 'https://api.iml.ru/json/';
}
$url = 'https://api.iml.ru/json/';

if (self::METHOD_GET === $method){
$path .= '?' . http_build_query($parameters, '', '&');
if ($version) {
$url = "https://api.iml.ru/{$version}/";
} elseif (in_array($path, $apiListMethods)) {
$url = 'https://api.iml.ru/list/';
} elseif(!in_array($path, $apiListMethods)) {
$url = 'https://list.iml.ru/';
}

$path .= '?' . http_build_query($parameters, '', '&');
}

$url = $url . $path;
Expand Down

0 comments on commit 6c6f878

Please sign in to comment.