digikraaft /
paystack-php
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Digikraaft\Paystack; |
||
| 4 | |||
| 5 | use Digikraaft\Paystack\Exceptions\InvalidArgumentException; |
||
| 6 | |||
| 7 | class Paystack |
||
| 8 | { |
||
| 9 | /** @var string The Paystack API key to be used for requests. */ |
||
| 10 | public static string $apiKey; |
||
| 11 | |||
| 12 | /** @var string The instance API key, settable once per new instance */ |
||
| 13 | private $instanceApiKey; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 14 | |||
| 15 | /** @var string The base URL for the Paystack API. */ |
||
| 16 | public static $apiBase = 'https://api.paystack.co'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @return string the API key used for requests |
||
| 20 | */ |
||
| 21 | public static function getApiKey(): string |
||
| 22 | { |
||
| 23 | return self::$apiKey; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Sets the API key to be used for requests. |
||
| 28 | * |
||
| 29 | * @param string $apiKey |
||
| 30 | */ |
||
| 31 | public static function setApiKey($apiKey): void |
||
| 32 | { |
||
| 33 | self::validateApiKey($apiKey); |
||
| 34 | self::$apiKey = $apiKey; |
||
| 35 | } |
||
| 36 | |||
| 37 | private static function validateApiKey($apiKey): bool |
||
| 38 | { |
||
| 39 | if ($apiKey == '' || ! is_string($apiKey)) { |
||
| 40 | throw new InvalidArgumentException('Api key must be a string and cannot be empty'); |
||
| 41 | } |
||
| 42 | |||
| 43 | return true; |
||
| 44 | } |
||
| 45 | } |
||
| 46 |