|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yabacon; |
|
4
|
|
|
|
|
5
|
|
|
use \Yabacon\Paystack\Helpers\Router; |
|
6
|
|
|
use \Yabacon\Paystack\Exception\ValidationException; |
|
7
|
|
|
|
|
8
|
|
|
class Paystack |
|
9
|
|
|
{ |
|
10
|
|
|
public $secret_key; |
|
11
|
|
|
public $use_guzzle = false; |
|
12
|
|
|
public static $fallback_to_file_get_contents = true; |
|
13
|
|
|
const VERSION="2.1.19"; |
|
14
|
|
|
|
|
15
|
14 |
|
public function __construct($secret_key) |
|
16
|
|
|
{ |
|
17
|
14 |
|
if (!is_string($secret_key) || !(substr($secret_key, 0, 3)==='sk_')) { |
|
18
|
1 |
|
throw new \InvalidArgumentException('A Valid Paystack Secret Key must start with \'sk_\'.'); |
|
19
|
|
|
} |
|
20
|
13 |
|
$this->secret_key = $secret_key; |
|
21
|
13 |
|
} |
|
22
|
|
|
|
|
23
|
1 |
|
public function useGuzzle() |
|
24
|
|
|
{ |
|
25
|
1 |
|
$this->use_guzzle = true; |
|
26
|
1 |
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
public static function disableFileGetContentsFallback() |
|
29
|
|
|
{ |
|
30
|
1 |
|
Paystack::$fallback_to_file_get_contents = false; |
|
31
|
1 |
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
public static function enableFileGetContentsFallback() |
|
34
|
|
|
{ |
|
35
|
1 |
|
Paystack::$fallback_to_file_get_contents = true; |
|
36
|
1 |
|
} |
|
37
|
|
|
|
|
38
|
4 |
|
public function __call($method, $args) |
|
39
|
|
|
{ |
|
40
|
4 |
|
if ($singular_form = Router::singularFor($method)) { |
|
41
|
1 |
|
return $this->handlePlural($singular_form, $method, $args); |
|
42
|
|
|
} |
|
43
|
3 |
|
return $this->handleSingular($method, $args); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
private function handlePlural($singular_form, $method, $args) |
|
47
|
|
|
{ |
|
48
|
1 |
|
if ((count($args) === 1 && is_array($args[0]))||(count($args) === 0)) { |
|
49
|
|
|
return $this->{$singular_form}->__call('getList', $args); |
|
50
|
|
|
} |
|
51
|
1 |
|
throw new \InvalidArgumentException( |
|
52
|
1 |
|
'Route "' . $method . '" can only accept an optional array of filters and ' |
|
53
|
1 |
|
.'paging arguments (perPage, page).' |
|
54
|
1 |
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
3 |
|
private function handleSingular($method, $args) |
|
58
|
|
|
{ |
|
59
|
3 |
|
if (count($args) === 1) { |
|
60
|
1 |
|
$args = [[], [ Router::ID_KEY => $args[0] ] ]; |
|
61
|
1 |
|
return $this->{$method}->__call('fetch', $args); |
|
62
|
|
|
} |
|
63
|
2 |
|
throw new \InvalidArgumentException( |
|
64
|
2 |
|
'Route "' . $method . '" can only accept an id or code.' |
|
65
|
2 |
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @deprecated |
|
70
|
|
|
*/ |
|
71
|
|
|
public static function registerAutoloader() |
|
72
|
|
|
{ |
|
73
|
|
|
trigger_error('Include "src/autoload.php" instead', E_DEPRECATED | E_USER_NOTICE); |
|
74
|
|
|
require_once(__DIR__ . '/../src/autoload.php'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
public function __get($name) |
|
78
|
|
|
{ |
|
79
|
2 |
|
return new Router($name, $this); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|