|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace vinicinbgs\Autentique; |
|
4
|
|
|
|
|
5
|
|
|
use vinicinbgs\Autentique\Enums\ResourcesEnum; |
|
6
|
|
|
use vinicinbgs\Autentique\Utils\Api; |
|
7
|
|
|
|
|
8
|
|
|
abstract class BaseResource |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Autentique API URL |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
public $autentiqueUrl = "https://api.autentique.com.br/v2/graphql"; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Autentique API |
|
18
|
|
|
* @var Api |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $api; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Autentique API Token |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $token; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Autentique Sandbox Mode |
|
30
|
|
|
* @var string "true"|"false" |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $sandbox; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Autentique Resources Enum |
|
36
|
|
|
* @var ResourcesEnum |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $resourcesEnum; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* BaseResource constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string|null $token Autentique API Token if not set or null it will get from $_ENV["AUTENTIQUE_TOKEN"] |
|
44
|
|
|
* @param int $timeout Request Timeout in seconds |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(string $token = null, int $timeout = 60) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->api = new Api($this->autentiqueUrl, $timeout); |
|
49
|
|
|
$this->setToken($token); |
|
50
|
|
|
$this->setSandbox(); |
|
51
|
|
|
|
|
52
|
|
|
$this->resourcesEnum = ResourcesEnum::class; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Set Autentique API Token but by default it will get from $_ENV["AUTENTIQUE_TOKEN"] |
|
57
|
|
|
* @param string $token Autentique API Token |
|
58
|
|
|
* @return $this |
|
59
|
|
|
*/ |
|
60
|
|
|
public function setToken(?string $token) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->token = $token ?? $_ENV["AUTENTIQUE_TOKEN"]; |
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Set Autentique Sandbox Mode but by default it will get from $_ENV["AUTENTIQUE_SANDBOX"] |
|
68
|
|
|
* @param string $sandbox "true"|"false" |
|
69
|
|
|
* @return $this |
|
70
|
|
|
*/ |
|
71
|
|
|
public function setSandbox(?string $sandbox = null) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->sandbox = $sandbox ?? ($_ENV["AUTENTIQUE_DEV_MODE"] ?? "false"); |
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set Api instance customizing the Autentique API URL and Request Timeout |
|
79
|
|
|
* |
|
80
|
|
|
* @param Api $api |
|
81
|
|
|
* @return $this |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setApi(Api $api) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->api = $api; |
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get Autentique API Token |
|
91
|
|
|
* @return string |
|
92
|
|
|
* |
|
93
|
|
|
* @codeCoverageIgnore |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getToken(): string |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->token; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get Autentique Sandbox Mode |
|
102
|
|
|
* @return string |
|
103
|
|
|
* |
|
104
|
|
|
* @codeCoverageIgnore |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getSandbox(): string |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->sandbox; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get Autentique API |
|
113
|
|
|
* @return Api |
|
114
|
|
|
* |
|
115
|
|
|
* @codeCoverageIgnore |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getApi(): Api |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->api; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..