1
0
Fork 0

use psr-7

This commit is contained in:
Alexander Yakovlev 2022-06-13 20:24:22 +07:00
parent 58777b4973
commit e7b8fe2985
3 changed files with 20 additions and 24 deletions

View File

@ -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
View File

@ -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",

View File

@ -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']);
$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_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = $client->sendRequest($request);
if ($response->getStatusCode() !== 200) {
throw new \Exception('Server returned ' . $response->getStatusCode() . ':' . $response->getReasonPhrase());
}
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);
$arResponse = json_decode($response, true);
$arResponse = json_decode((string) $response->getBody(), true);
if ($arResponse['success'] !== true) {
$this->arError = $arResponse['error'];