|
|
|
|
|
|
|
|
namespace common\components\Tiller; |
|
|
namespace common\components\Tiller; |
|
|
|
|
|
|
|
|
use common\components\Tiller\TillerClientInterface; |
|
|
use common\components\Tiller\TillerClientInterface; |
|
|
|
|
|
use GuzzleHttp\Exception\RequestException; |
|
|
use linslin\yii2\curl; |
|
|
use linslin\yii2\curl; |
|
|
|
|
|
|
|
|
class TillerClientV3 implements TillerClientInterface |
|
|
class TillerClientV3 implements TillerClientInterface |
|
|
{ |
|
|
{ |
|
|
var $curl; |
|
|
|
|
|
|
|
|
var $client; |
|
|
var $storeId; |
|
|
var $storeId; |
|
|
var $headers = []; |
|
|
var $headers = []; |
|
|
var $urlApi = 'https://api.tiller.systems/orders/v3/'; |
|
|
|
|
|
|
|
|
var $urlApi = 'https://api.tiller.systems/'; |
|
|
|
|
|
|
|
|
public function __construct(string $storeId = null, string $accessToken = null) |
|
|
public function __construct(string $storeId = null, string $accessToken = null) |
|
|
{ |
|
|
{ |
|
|
$this->storeId = $storeId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->client = new \GuzzleHttp\Client(); |
|
|
|
|
|
$this->storeId = (int) $storeId; |
|
|
$this->headers = [ |
|
|
$this->headers = [ |
|
|
'authorization' => 'Bearer '.$accessToken, |
|
|
'authorization' => 'Bearer '.$accessToken, |
|
|
'accept' => 'application/json', |
|
|
'accept' => 'application/json', |
|
|
'content-type' => 'application/json', |
|
|
'content-type' => 'application/json', |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
$this->curl = new curl\Curl(); |
|
|
|
|
|
$this->curl->setHeader('Authorization', 'Bearer '.$accessToken); |
|
|
|
|
|
$this->curl->setHeader('accept', 'application/json'); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUrlAuthorizeCode(string $clientId, string $redirectUri): string |
|
|
public function getUrlAuthorizeCode(string $clientId, string $redirectUri): string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function isAuthenticated(): bool |
|
|
public function isAuthenticated(): bool |
|
|
{ |
|
|
{ |
|
|
/*$resultOrders = $this->getOrders('2024-02-01'); |
|
|
|
|
|
print_r($resultOrders); |
|
|
|
|
|
die();*/ |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
return $this->getOrders(date('Y-m-d')) !== false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getOrders($date) |
|
|
public function getOrders($date) |
|
|
{ |
|
|
{ |
|
|
$client = new \GuzzleHttp\Client(); |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
$response = $this->client->request('POST', $this->urlApi.'orders/v3/orders/search', [ |
|
|
|
|
|
'body' => json_encode([ |
|
|
|
|
|
'storeIds' => [$this->storeId], |
|
|
|
|
|
'openDate' => [ |
|
|
|
|
|
'from' => date('Y-m-d H:i:s', strtotime($date)), |
|
|
|
|
|
'to' => date('Y-m-d H:i:s', strtotime($date) + 24 * 60 * 60 - 1) |
|
|
|
|
|
] |
|
|
|
|
|
]), |
|
|
|
|
|
'headers' => $this->headers |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
return $response->getBody()->getContents(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (RequestException $exception) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$response = $client->request('POST', 'https://api.tiller.systems/orders/v3/orders/search', [ |
|
|
|
|
|
'body' => json_encode([ |
|
|
|
|
|
'storeIds' => [$this->storeId], |
|
|
|
|
|
'openDate' => [ |
|
|
|
|
|
'from' => date('Y-m-d H-i-s', strtotime($date)), |
|
|
|
|
|
'to' => date('Y-m-d H-i-s', strtotime($date) + 24 * 60 * 60 - 1) |
|
|
|
|
|
] |
|
|
|
|
|
]), |
|
|
|
|
|
|
|
|
public function postOrder($params) |
|
|
|
|
|
{ |
|
|
|
|
|
$response = $this->client->request('POST', $this->urlApi.'purchase-requests/v1/requests', [ |
|
|
|
|
|
'query' => [ |
|
|
|
|
|
'storeId' => $this->storeId |
|
|
|
|
|
], |
|
|
|
|
|
'body' => json_encode($params), |
|
|
'headers' => $this->headers |
|
|
'headers' => $this->headers |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
return $response->getBody()->getContents(); |
|
|
return $response->getBody()->getContents(); |
|
|
|
|
|
|
|
|
/*$orders = $this->curl |
|
|
|
|
|
->setRequestBody(json_encode([ |
|
|
|
|
|
'storeIds' => [$this->storeId], |
|
|
|
|
|
'openDate' => [ |
|
|
|
|
|
'from' => date('Y-m-d H-i-s', strtotime($date)), |
|
|
|
|
|
'to' => date('Y-m-d H-i-s', strtotime($date) + 24 * 60 * 60 - 1), |
|
|
|
|
|
] |
|
|
|
|
|
])) |
|
|
|
|
|
->setPostParams([ |
|
|
|
|
|
// 'statuses' => ['IN_PROGRESS'], |
|
|
|
|
|
])->post($this->urlApi . 'orders/search?count=20'); |
|
|
|
|
|
|
|
|
|
|
|
return json_decode($orders);*/ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function postOrder($params) |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->curl |
|
|
|
|
|
->setPostParams($params) |
|
|
|
|
|
->post($this->urlApi . 'orders'); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |