4
4
5
5
use ErrorException ;
6
6
use GuzzleHttp \Client as GuzzleClient ;
7
+ use GuzzleHttp \HandlerStack ;
8
+ use GuzzleHttp \Middleware ;
7
9
8
10
final class PaymayaClient
9
11
{
@@ -12,32 +14,54 @@ final class PaymayaClient
12
14
13
15
public const ENVIRONMENT_SANDBOX = 'sandbox ' ;
14
16
public const ENVIRONMENT_PRODUCTION = 'production ' ;
17
+ public const ENVIRONMENT_TESTING = 'testing ' ;
15
18
16
19
private string $ public_key ;
17
20
private string $ secret_key ;
18
21
19
22
private string $ environment ;
20
23
private string $ base_url ;
21
24
25
+ private ?HandlerStack $ handler_stack = null ;
26
+
22
27
/**
23
- * Client constructor.
28
+ * PaymayaClient constructor.
24
29
*
25
30
* @param string $secretKey
26
31
* @param string $publicKey
27
32
* @param string $environment
33
+ * @param \GuzzleHttp\HandlerStack|null $handlerStack
34
+ * @param array $historyContainer
28
35
*
29
36
* @throws \ErrorException
30
37
*/
31
- public function __construct (string $ secretKey , string $ publicKey , string $ environment = self ::ENVIRONMENT_SANDBOX )
32
- {
38
+ public function __construct (
39
+ string $ secretKey ,
40
+ string $ publicKey ,
41
+ string $ environment = self ::ENVIRONMENT_SANDBOX ,
42
+ HandlerStack $ handlerStack = null ,
43
+ array &$ historyContainer = []
44
+ ) {
33
45
switch ($ environment ) {
46
+ // @codeCoverageIgnoreStart
34
47
case self ::ENVIRONMENT_PRODUCTION :
35
48
$ this ->base_url = self ::BASE_URL_PRODUCTION ;
36
49
37
50
break ;
38
51
case self ::ENVIRONMENT_SANDBOX :
39
52
$ this ->base_url = self ::BASE_URL_SANDBOX ;
40
53
54
+ break ;
55
+ // @codeCoverageIgnoreEnd
56
+ case self ::ENVIRONMENT_TESTING :
57
+ $ this ->base_url = 'testing ' ;
58
+
59
+ $ this ->handler_stack = $ handlerStack ;
60
+
61
+ if ( ! is_null ($ this ->handler_stack )) {
62
+ $ this ->handler_stack ->push (Middleware::history ($ historyContainer ));
63
+ }
64
+
41
65
break ;
42
66
default :
43
67
throw new ErrorException ("Invalid environment ` $ environment`. " );
@@ -54,6 +78,7 @@ private function client(array $header): GuzzleClient
54
78
[
55
79
'base_uri ' => $ this ->base_url ,
56
80
'headers ' => $ header ,
81
+ 'handler ' => $ this ->handler_stack ,
57
82
]
58
83
);
59
84
}
0 commit comments