1
0
Fork 0
master
Alexander Yakovlev 2 months ago
parent 58777b4973
commit e7b8fe2985
  1. 3
      composer.json
  2. 2
      composer.lock
  3. 39
      lib/Adapter.php

@ -17,7 +17,8 @@
"php-http/client-implementation": "^1",
"php-http/message": "^1.5",
"php-http/discovery": "^1.14",
"symfony/http-foundation": "^6"
"symfony/http-foundation": "^6",
"guzzlehttp/psr7": "^2.3"
},
"require-dev": {
"php-http/mock-client": "^1",

2
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "841c259ae4952442e7eaa53f1410765c",
"content-hash": "c176a4d7f47087c07fb8b86b76044123",
"packages": [
{
"name": "clue/stream-filter",

@ -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'];

Loading…
Cancel
Save