-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Minor bugfixes * Improve error handling
- Loading branch information
1 parent
8dc02be
commit eb59544
Showing
6 changed files
with
142 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,8 @@ venv | |
*.sqlite3 | ||
|
||
# MacOS | ||
.DS_STORE | ||
.DS_STORE | ||
|
||
composer.lock | ||
|
||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace CryptAPI\Exceptions; | ||
|
||
use Exception; | ||
|
||
class ApiException extends Exception { | ||
protected $statusCode; | ||
|
||
public function __construct($message = "", $statusCode = 0, ?\Exception $previous = null) { | ||
parent::__construct($message, $statusCode, $previous); | ||
$this->statusCode = $statusCode; | ||
} | ||
|
||
public static function withStatus($statusCode, $apiError = null, Exception $previous = null): ApiException | ||
{ | ||
$message = $apiError ?? self::getDefaultMessageForStatusCode($statusCode); | ||
|
||
return new self($message, $statusCode, $previous); | ||
} | ||
|
||
// Method to get a default message based on the status code | ||
private static function getDefaultMessageForStatusCode($statusCode): string | ||
{ | ||
switch ($statusCode) { | ||
case 400: return "Bad Request"; | ||
case 401: return "Unauthorized"; | ||
case 403: return "Forbidden"; | ||
case 404: return "Not Found"; | ||
case 500: return "Internal Server Error"; | ||
default: return "An unexpected error occurred"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "cryptapi/php-cryptapi", | ||
"type": "library", | ||
"description": "CryptAPI's PHP library", | ||
"keywords": ["cryptapi", "crypto", "bitcoin", "litecoin", "ethereum", "bitcoin cash", "monero", "iota", "payments", "cryptocurrencies", "cryptapi pro"], | ||
"keywords": ["cryptapi", "crypto", "bitcoin", "litecoin", "ethereum", "bitcoin cash", "polygon", "base", "avalanche-c", "payments", "cryptocurrencies"], | ||
"homepage": "https://github.com/cryptapi/php-cryptapi", | ||
"license": "MIT", | ||
"authors": [ | ||
|
@@ -16,7 +16,7 @@ | |
"support": { | ||
"email": "[email protected]", | ||
"chat": "https://cryptapi.io", | ||
"docs": "https://cryptapi.io/docs/" | ||
"docs": "https://docs.cryptapi.io/" | ||
}, | ||
"require": { | ||
"php": ">=7.2.0", | ||
|
@@ -29,5 +29,5 @@ | |
"CryptAPI\\": "CryptAPI/" | ||
} | ||
}, | ||
"version": "1.6.2" | ||
"version": "1.7.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Testing BlockBee Library... | ||
*/ | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
$coin = "bep20_usdt"; | ||
$callback_url = "https://example.com"; | ||
$parameters = [ | ||
'payment_id' => 12345, | ||
]; | ||
|
||
$cryptapi_params = [ | ||
'pending' => 1, | ||
]; | ||
|
||
try { | ||
$ca = new CryptAPI\CryptAPI($coin, '0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d', $callback_url, $parameters, $cryptapi_params); | ||
|
||
# var_dump($ca->get_address()) . PHP_EOL; | ||
|
||
# var_dump($ca->check_logs()) . PHP_EOL; | ||
|
||
# var_dump($ca->get_qrcode()) . PHP_EOL; | ||
|
||
# var_dump($ca->get_qrcode(2, 500)) . PHP_EOL; | ||
|
||
# var_dump(\CryptAPI\CryptAPI::get_info('btc', true)) . PHP_EOL; | ||
|
||
# var_dump(\CryptAPI\CryptAPI::get_info($coin, false)) . PHP_EOL; | ||
|
||
# var_dump(\CryptAPI\CryptAPI::get_supported_coins()) . PHP_EOL; | ||
|
||
# var_dump(\CryptAPI\CryptAPI::get_estimate($coin, 1, '')) . PHP_EOL; | ||
|
||
# var_dump(\CryptAPI\CryptAPI::get_convert($coin, 3, 'usd')) . PHP_EOL; | ||
} catch (Exception $e) { | ||
var_dump($e); | ||
} |