|
|
|
@ -4,6 +4,10 @@ declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Payeer;
|
|
|
|
|
|
|
|
|
|
use Http\Discovery\HttpClientDiscovery;
|
|
|
|
|
use Http\Discovery\Psr17FactoryDiscovery;
|
|
|
|
|
use GuzzleHttp\Psr7\Utils;
|
|
|
|
|
|
|
|
|
|
class Adapter
|
|
|
|
|
{
|
|
|
|
|
private array $arParams = array();
|
|
|
|
@ -19,37 +23,28 @@ class Adapter
|
|
|
|
|
|
|
|
|
|
protected function request(array $req = array())
|
|
|
|
|
{
|
|
|
|
|
$client = HttpClientDiscovery::find();
|
|
|
|
|
$messageFactory = Psr17FactoryDiscovery::findRequestFactory();
|
|
|
|
|
$msec = round(microtime(true) * 1000);
|
|
|
|
|
|
|
|
|
|
$req['post']['ts'] = $msec;
|
|
|
|
|
|
|
|
|
|
$post = json_encode($req['post']);
|
|
|
|
|
|
|
|
|
|
$sign = hash_hmac('sha256', $req['method'] . $post, $this->arParams['key']);
|
|
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, "https://payeer.com/api/trade/" . $req['method']);
|
|
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
|
|
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
|
$request = $messageFactory->createRequest('POST', 'https://payeer.com/api/trade/' . $req['method'])
|
|
|
|
|
->withHeader('Content-Type', 'application/json')
|
|
|
|
|
->withHeader('API-ID', $this->arParams['id'])
|
|
|
|
|
->withHeader('API-SIGN', $sign)
|
|
|
|
|
->withBody(Utils::streamFor($post));
|
|
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
|
|
|
|
|
|
|
|
|
curl_setopt(
|
|
|
|
|
$ch,
|
|
|
|
|
CURLOPT_HTTPHEADER,
|
|
|
|
|
array(
|
|
|
|
|
"Content-Type: application/json",
|
|
|
|
|
"API-ID: " . $this->arParams['id'],
|
|
|
|
|
"API-SIGN: " . $sign
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
$response = $client->sendRequest($request);
|
|
|
|
|
if ($response->getStatusCode() !== 200) {
|
|
|
|
|
throw new \Exception('Server returned ' . $response->getStatusCode() . ':' . $response->getReasonPhrase());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arResponse = json_decode($response, true);
|
|
|
|
|
$arResponse = json_decode((string) $response->getBody(), true);
|
|
|
|
|
|
|
|
|
|
if ($arResponse['success'] !== true) {
|
|
|
|
|
$this->arError = $arResponse['error'];
|
|
|
|
|