1 | <?php |
||
14 | class Postpay |
||
15 | { |
||
16 | /** |
||
17 | * @const string Version number of the Postpay SDK. |
||
18 | */ |
||
19 | const VERSION = '0.1.1'; |
||
20 | |||
21 | /** |
||
22 | * @const string Default API version for requests. |
||
23 | */ |
||
24 | const DEFAULT_API_VERSION = 'v1'; |
||
25 | |||
26 | /** |
||
27 | * @const string GraphQL path. |
||
28 | */ |
||
29 | const GRAPHQL_PATH = '/graphql'; |
||
30 | |||
31 | /** |
||
32 | * @const string GraphQL version for requests. |
||
33 | */ |
||
34 | const GRAPHQL_VERSION = 'graphql'; |
||
35 | |||
36 | /** |
||
37 | * @const string The name of the environment variable that contains the merchant ID. |
||
38 | */ |
||
39 | const MERCHANT_ID_ENV_NAME = 'POSTPAY_MERCHANT_ID'; |
||
40 | |||
41 | /** |
||
42 | * @const string The name of the environment variable that contains the secret key. |
||
43 | */ |
||
44 | const SECRET_KEY_ENV_NAME = 'POSTPAY_SECRET_KEY'; |
||
45 | |||
46 | /** |
||
47 | * @var Client The Postpay client service. |
||
48 | */ |
||
49 | protected $client; |
||
50 | |||
51 | /** |
||
52 | * @var array The basic auth credentials. |
||
53 | */ |
||
54 | protected $auth; |
||
55 | |||
56 | /** |
||
57 | * @var string|null The default API version. |
||
58 | */ |
||
59 | protected $apiVersion; |
||
60 | |||
61 | /** |
||
62 | * @var bool Set to true for sandbox requests. |
||
63 | */ |
||
64 | protected $sandbox; |
||
65 | |||
66 | /** |
||
67 | * @var \Postpay\Http\Response|null Stores the last request. |
||
68 | */ |
||
69 | protected $lastResponse; |
||
70 | |||
71 | /** |
||
72 | * Instantiates a new Postpay super-class object. |
||
73 | * |
||
74 | * @param array $config |
||
75 | * |
||
76 | * @throws PostpayException |
||
77 | */ |
||
78 | 10 | public function __construct(array $config = []) |
|
98 | |||
99 | /** |
||
100 | * Returns the client service. |
||
101 | * |
||
102 | * @return Client |
||
103 | */ |
||
104 | 1 | public function getClient() |
|
108 | |||
109 | /** |
||
110 | * Creates a client handler. |
||
111 | * |
||
112 | * @param ClientInterface|string|null $handler |
||
113 | * |
||
114 | * @return ClientInterface |
||
115 | * |
||
116 | * @throws \Exception If extensions aren't available. |
||
117 | * @throws InvalidArgumentException If client handler is invalid. |
||
118 | */ |
||
119 | 11 | public static function createClientHandler($handler = null) |
|
140 | |||
141 | /** |
||
142 | * Sets the HTTP client handler. |
||
143 | * |
||
144 | * @param ClientInterface $clientHandler |
||
145 | */ |
||
146 | 10 | public function setClientHandler($clientHandler) |
|
152 | |||
153 | /** |
||
154 | * Returns the last response returned from API. |
||
155 | * |
||
156 | * @return \Postpay\Http\Response|null |
||
157 | */ |
||
158 | 1 | public function getLastResponse() |
|
162 | |||
163 | /** |
||
164 | * Sends a GET request to API and returns the response. |
||
165 | * |
||
166 | * @param string $path |
||
167 | * @param array $params |
||
168 | * |
||
169 | * @return \Postpay\Http\Response |
||
170 | * |
||
171 | * @throws PostpayException |
||
172 | */ |
||
173 | 2 | public function get($path, array $params = []) |
|
177 | |||
178 | /** |
||
179 | * Sends a POST request to API and returns the response. |
||
180 | * |
||
181 | * @param string $path |
||
182 | * @param array $params |
||
183 | * |
||
184 | * @return \Postpay\Http\Response |
||
185 | * |
||
186 | * @throws PostpayException |
||
187 | */ |
||
188 | 1 | public function post($path, array $params = []) |
|
192 | |||
193 | /** |
||
194 | * Sends a PUT request to API and returns the response. |
||
195 | * |
||
196 | * @param string $path |
||
197 | * @param array $params |
||
198 | * |
||
199 | * @return \Postpay\Http\Response |
||
200 | * |
||
201 | * @throws PostpayException |
||
202 | */ |
||
203 | 1 | public function put($path, array $params = []) |
|
207 | |||
208 | /** |
||
209 | * Sends a PATCH request to API and returns the response. |
||
210 | * |
||
211 | * @param string $path |
||
212 | * @param array $params |
||
213 | * |
||
214 | * @return \Postpay\Http\Response |
||
215 | * |
||
216 | * @throws PostpayException |
||
217 | */ |
||
218 | 1 | public function patch($path, array $params = []) |
|
222 | |||
223 | /** |
||
224 | * Sends a DELETE request to API and returns the response. |
||
225 | * |
||
226 | * @param string $path |
||
227 | * @param array $params |
||
228 | * |
||
229 | * @return \Postpay\Http\Response |
||
230 | * |
||
231 | * @throws PostpayException |
||
232 | */ |
||
233 | 1 | public function delete($path, array $params = []) |
|
237 | |||
238 | /** |
||
239 | * Sends a query to GraphQL API and returns the response. |
||
240 | * |
||
241 | * @param string $query |
||
242 | * @param array $variables |
||
243 | * |
||
244 | * @return \Postpay\Http\Response |
||
245 | * |
||
246 | * @throws PostpayException |
||
247 | */ |
||
248 | 1 | public function query($query, array $variables = []) |
|
261 | |||
262 | /** |
||
263 | * Sends a request to API and returns the response. |
||
264 | * |
||
265 | * @param string $method |
||
266 | * @param string $path |
||
267 | * @param array $params |
||
268 | * @param string|null $apiVersion |
||
269 | * |
||
270 | * @return \Postpay\Http\Response |
||
271 | * |
||
272 | * @throws PostpayException |
||
273 | */ |
||
274 | 7 | public function request( |
|
290 | } |
||
291 |