1 | <?php |
||
7 | class Request |
||
8 | { |
||
9 | /** |
||
10 | * @const string API URL. |
||
11 | */ |
||
12 | const API_URL = 'https://<subdomain>.postpay.io'; |
||
13 | |||
14 | /** |
||
15 | * @const string Accept HTTP header. |
||
16 | */ |
||
17 | const ACCEPT_HEADER = 'application/vnd.postpay+json; version='; |
||
18 | |||
19 | /** |
||
20 | * @var string The HTTP method. |
||
21 | */ |
||
22 | protected $method; |
||
23 | |||
24 | /** |
||
25 | * @var string The path URL. |
||
26 | */ |
||
27 | protected $path; |
||
28 | |||
29 | /** |
||
30 | * @var array The basic auth credentials. |
||
31 | */ |
||
32 | protected $auth = []; |
||
33 | |||
34 | /** |
||
35 | * @var array The headers to send with the request. |
||
36 | */ |
||
37 | protected $headers = []; |
||
38 | |||
39 | /** |
||
40 | * @var array The parameters to send with the request. |
||
41 | */ |
||
42 | protected $params = []; |
||
43 | |||
44 | /** |
||
45 | * @var string API version. |
||
46 | */ |
||
47 | protected $apiVersion; |
||
48 | |||
49 | /** |
||
50 | * @var bool Set to true for sandbox request. |
||
51 | */ |
||
52 | protected $sandbox; |
||
53 | |||
54 | /** |
||
55 | * Creates a new Request entity. |
||
56 | * |
||
57 | * @param string $method |
||
58 | * @param string|null $path |
||
59 | * @param array $params |
||
60 | * @param array $auth |
||
61 | * @param string|null $apiVersion |
||
62 | * @param bool $sandbox |
||
63 | */ |
||
64 | 31 | public function __construct( |
|
79 | |||
80 | /** |
||
81 | * Return the HTTP method. |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | 10 | public function getMethod() |
|
89 | |||
90 | /** |
||
91 | * Set the HTTP method. |
||
92 | * |
||
93 | * @param string |
||
94 | */ |
||
95 | 31 | public function setMethod($method) |
|
99 | |||
100 | /** |
||
101 | * Return the path URL. |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | 1 | public function getPath() |
|
109 | |||
110 | /** |
||
111 | * Return the basic auth credentials. |
||
112 | * |
||
113 | * @return array|null |
||
114 | */ |
||
115 | 4 | public function getAuth() |
|
119 | |||
120 | /** |
||
121 | * Set the basic auth credentials. |
||
122 | * |
||
123 | * @param array $auth |
||
124 | */ |
||
125 | 1 | public function setAuth(array $auth) |
|
129 | |||
130 | /** |
||
131 | * Generate and return HTTP headers. |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | 5 | public function getHeaders() |
|
139 | |||
140 | /** |
||
141 | * Set the headers. |
||
142 | * |
||
143 | * @param array $headers |
||
144 | */ |
||
145 | 2 | public function setHeaders(array $headers) |
|
149 | |||
150 | /** |
||
151 | * Return the default headers. |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | 5 | public function getDefaultHeaders() |
|
164 | |||
165 | /** |
||
166 | * Return the params. |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | 1 | public function getParams() |
|
174 | |||
175 | /** |
||
176 | * Set the params. |
||
177 | * |
||
178 | * @param array $params |
||
179 | */ |
||
180 | 2 | public function setParams(array $params) |
|
184 | |||
185 | /** |
||
186 | * Return JSON params on POST requests. |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | 3 | public function json() |
|
197 | |||
198 | /** |
||
199 | * The API version. |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | 1 | public function getApiVersion() |
|
207 | |||
208 | /** |
||
209 | * Set the API version. |
||
210 | * |
||
211 | * @param string $apiVersion |
||
212 | */ |
||
213 | 2 | public function setApiVersion($apiVersion) |
|
217 | |||
218 | /** |
||
219 | * Return true if it's a GraphQL request. |
||
220 | * |
||
221 | * @return bool |
||
222 | */ |
||
223 | 21 | public function isGraphQL() |
|
227 | |||
228 | 4 | public function getApiUrl() |
|
233 | |||
234 | /** |
||
235 | * Generate and return the URL. |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | 4 | public function getUrl() |
|
248 | } |
||
249 |