diff --git a/composer.json b/composer.json index 4acb210..15f3584 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "minimum-stability": "dev", "require": { - "php": ">=7.4", - "guzzlehttp/guzzle": "^7.0", + "php": ">=5.6", + "guzzlehttp/guzzle": "^6.5.x-dev", "starkbank/ecdsa": "0.0.5" }, "autoload": { diff --git a/src/Client.php b/src/Client.php index 188f8ca..53a0521 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,10 +5,10 @@ class Client extends RequestBuilder { - private ?string $merchantId; - private ?string $merchantName; - public string $apiEndpoint = 'https://api.monobank.ua/'; - private \GuzzleHttp\Client $httpClient; + private $merchantId; + private $merchantName; + public $apiEndpoint = 'https://api.monobank.ua/'; + private $httpClient; /** * Створює клієнт з ключем для запитів до серверу Mono і отримує дані про мерчант @@ -16,7 +16,7 @@ class Client extends RequestBuilder * @throws \GuzzleHttp\Exception\GuzzleException * @link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1details/get Так отримуються деталі мерчанту */ - public function __construct(string $token) + public function __construct($token='') { $this->httpClient = new \GuzzleHttp\Client([ 'base_uri' => $this->apiEndpoint, @@ -37,21 +37,21 @@ public function __construct(string $token) throw new \Exception('Cannot decode json response from Mono', 500); } } else { - throw new \Exception($data['errorDescription'] ?? 'Unknown error response: ' . $json, $response->getStatusCode()); + throw new \Exception(isset($data['errorDescription']) ? $data['errorDescription'] : 'Unknown error response: ' . $json, $response->getStatusCode()); } } - public function getMerchantId(): string + public function getMerchantId() { return $this->merchantId; } - public function getMerchantName(): string + public function getMerchantName() { return $this->merchantName; } - public function getClient(): \GuzzleHttp\Client + public function getClient() { return $this->httpClient; } @@ -63,7 +63,7 @@ public function getClient(): \GuzzleHttp\Client * @throws \GuzzleHttp\Exception\GuzzleException * @throws \Exception */ - public function getPublicKey(): string + public function getPublicKey() { $response = $this->getClient()->request('GET','/api/merchant/pubkey'); $data = $this->getDataFromGuzzleResponse($response); @@ -80,7 +80,7 @@ public function getPublicKey(): string * @throws \GuzzleHttp\Exception\GuzzleException * @throws \Exception */ - public function getMerchant(): array + public function getMerchant() { $response = $this->getClient()->request('GET','/api/merchant/details'); return $this->getDataFromGuzzleResponse($response); diff --git a/src/Payment.php b/src/Payment.php index 8aabce4..2f383b6 100644 --- a/src/Payment.php +++ b/src/Payment.php @@ -6,7 +6,7 @@ class Payment extends RequestBuilder { - private \MonoPay\Client $client; + private $client; public function __construct(\MonoPay\Client $client) { @@ -20,9 +20,10 @@ public function __construct(\MonoPay\Client $client) * @param array $options Додаткові параметри (Див. посилання) * @return array * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \Exception * @link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1invoice~1create/post */ - public function create(int $amount, array $options=[]): array + public function create( $amount, $options=[]) { if($amount < 1){ throw new \Exception('Amount must be a natural number',500); @@ -43,7 +44,7 @@ public function create(int $amount, array $options=[]): array * @throws \GuzzleHttp\Exception\GuzzleException * @throws \Exception */ - public function info(string $invoiceId): array + public function info($invoiceId) { $response = $this->client->getClient()->request('GET','/api/merchant/invoice/status',[ \GuzzleHttp\RequestOptions::QUERY => [ @@ -63,7 +64,7 @@ public function info(string $invoiceId): array * @throws \GuzzleHttp\Exception\GuzzleException * @throws \Exception */ - public function refund(string $invoiceId, array $options=[]): array + public function refund( $invoiceId, array $options=[]) { $options['invoiceId'] = $invoiceId; @@ -78,10 +79,10 @@ public function refund(string $invoiceId, array $options=[]): array * Інвалідація рахунку * Інвалідація рахунку, якщо за ним ще не було здіснено оплати * @param string $invoiceId ID рахунку + * @throws \GuzzleHttp\Exception\GuzzleException*@throws \Exception * @link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1invoice~1remove/post - * @throws \GuzzleHttp\Exception\GuzzleException */ - public function cancel(string $invoiceId): array + public function cancel($invoiceId) { $response = $this->client->getClient()->request('POST','/api/merchant/invoice/remove',[ \GuzzleHttp\RequestOptions::JSON => [ @@ -99,7 +100,7 @@ public function cancel(string $invoiceId): array * @throws \Exception *@link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1invoice~1payment-info?invoiceId=%7BinvoiceId%7D/get */ - public function successDetails(string $invoiceId): array + public function successDetails($invoiceId) { $response = $this->client->getClient()->request('GET','/api/merchant/invoice/payment-info',[ \GuzzleHttp\RequestOptions::QUERY => [ @@ -120,7 +121,7 @@ public function successDetails(string $invoiceId): array * @throws \Exception * @link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1invoice~1finalize/post */ - public function captureHold(string $invoiceId, int $amount = null): array + public function captureHold( $invoiceId, $amount = null) { $body = [ 'invoiceId' => $invoiceId @@ -145,7 +146,7 @@ public function captureHold(string $invoiceId, int $amount = null): array * @throws \Exception * @link https://api.monobank.ua/docs/acquiring.html#/paths/~1api~1merchant~1statement/get */ - public function items(int $fromTimestamp, int $toTimestamp=null): array + public function items( $fromTimestamp, $toTimestamp=null) { $query = [ 'from' => $fromTimestamp @@ -158,7 +159,7 @@ public function items(int $fromTimestamp, int $toTimestamp=null): array ]); $data = $this->getDataFromGuzzleResponse($response); - return $data['list']??[]; + return isset($data['list']) ? $data['list'] : []; } } \ No newline at end of file diff --git a/src/RequestBuilder.php b/src/RequestBuilder.php index 89bcb93..57b9c86 100644 --- a/src/RequestBuilder.php +++ b/src/RequestBuilder.php @@ -6,7 +6,7 @@ class RequestBuilder { - protected function getDataFromGuzzleResponse(\Psr\Http\Message\ResponseInterface $response): array + protected function getDataFromGuzzleResponse(\Psr\Http\Message\ResponseInterface $response) { $json = $response->getBody()->getContents(); if(!$json){ diff --git a/src/Webhook.php b/src/Webhook.php index c564b75..99ff33a 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -6,8 +6,8 @@ class Webhook { - private string $publicKeyBase64; - private string $xSignBase64; + private $publicKeyBase64; + private $xSignBase64; /** * Класс для верифікації даних з вебхука @@ -17,7 +17,7 @@ class Webhook * @throws \GuzzleHttp\Exception\GuzzleException * @throws \Exception */ - public function __construct(\MonoPay\Client $client, string $publicKeyBase64=null, string $xSignBase64=null) + public function __construct(\MonoPay\Client $client, $publicKeyBase64=null, $xSignBase64=null) { if(!$publicKeyBase64){ $publicKeyBase64 = $client->getPublicKey(); @@ -40,7 +40,7 @@ public function __construct(\MonoPay\Client $client, string $publicKeyBase64=nul * @param string|null $requestBody Тіло запиту. Зазвичай це json body вхідного запиту який можна отримати через функцію file_get_contents('php://input') * @return bool Чи коректні вхідні дані */ - public function verify(string $requestBody=null): bool + public function verify( $requestBody=null) { if(empty($requestBody)){ $requestBody = file_get_contents('php://input');