From cd5cd8b5c6c78766b2ccb3438a2117d9f8d81589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ariano=20Fonseca=20=C3=82ngelo?= Date: Mon, 22 Apr 2024 16:06:45 +0100 Subject: [PATCH] v2.1.1 * Minor bugfixes --- BlockBee/BlockBee.php | 26 ++++++++++++++------------ BlockBee/Requests.php | 4 ++-- README.md | 3 +++ composer.json | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/BlockBee/BlockBee.php b/BlockBee/BlockBee.php index 378b508..1d658f1 100644 --- a/BlockBee/BlockBee.php +++ b/BlockBee/BlockBee.php @@ -16,8 +16,19 @@ class BlockBee private $parameters = []; private $api_key = null; + /** + * @throws Exception + */ public function __construct($coin, $own_address, $callback_url, $parameters = [], $bb_params = [], $api_key = '') { + if (empty($coin)) { + throw new Exception('Please provide a valid coin/ticker.'); + } + + if (empty($callback_url)) { + throw new Exception('Please provide a valid callback url.'); + } + $this->valid_coins = BlockBee::get_supported_coins($api_key); if (!in_array($coin, $this->valid_coins)) { @@ -33,6 +44,9 @@ public function __construct($coin, $own_address, $callback_url, $parameters = [] $this->api_key = $api_key; } + /** + * @throws ApiException + */ public static function get_supported_coins($api_key = '') { $info = BlockBee::get_info(null, true); @@ -62,10 +76,6 @@ public static function get_supported_coins($api_key = '') */ public function get_address() { - if (empty($this->coin) || empty($this->callback_url)) { - return null; - } - $callback_url = $this->callback_url; if (!empty($this->parameters)) { @@ -92,10 +102,6 @@ public function get_address() public function check_logs() { - if (empty($this->coin) || empty($this->callback_url)) { - return null; - } - $callback_url = $this->callback_url; if (!empty($this->parameters)) { $req_parameters = http_build_query($this->parameters); @@ -121,10 +127,6 @@ public function check_logs() */ public function get_qrcode($value = false, $size = false) { - if (empty($this->coin)) { - return null; - } - $address = $this->payment_address; if (empty($address)) { diff --git a/BlockBee/Requests.php b/BlockBee/Requests.php index 33ab9fb..e79ecf9 100644 --- a/BlockBee/Requests.php +++ b/BlockBee/Requests.php @@ -35,7 +35,7 @@ public static function _request_get($coin, $endpoint, $params = [], $assoc = fal $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $response_object = json_decode($response, $assoc); - if (isset($response_object->status) && $response_object->status === 'error') { + if ((is_object($response_object) && isset($response_object->status) && $response_object->status === 'error') || (is_array($response_object) && isset($response_object['status']) && $response_object['status'] === 'error')) { $statusCode = $http_code; $apiError = $response_object->error ?? null; @@ -85,7 +85,7 @@ public static function _request_post($coin, $endpoint, $api_key, $body = [], $is $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $response_object = json_decode($response, $assoc); - if (isset($response_object->status) && $response_object->status === 'error') { + if ((is_object($response_object) && isset($response_object->status) && $response_object->status === 'error') || (is_array($response_object) && isset($response_object['status']) && $response_object['status'] === 'error')) { $statusCode = $http_code; $apiError = $response_object->error ?? null; diff --git a/README.md b/README.md index 5acb07e..4999375 100644 --- a/README.md +++ b/README.md @@ -717,6 +717,9 @@ Contact us @ https://blockbee.io/contacts/ * Minor bugfixes * Improve error handling +#### 2.1.1 +* Minor bugfixes + ### Breaking Changes #### 2.0.0 diff --git a/composer.json b/composer.json index 10d7122..4b0cf16 100644 --- a/composer.json +++ b/composer.json @@ -29,5 +29,5 @@ "BlockBee\\": "BlockBee/" } }, - "version": "2.1.0" + "version": "2.1.1" }