/
OAuthApi.php
360 lines (309 loc) · 12.6 KB
/
OAuthApi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
namespace SquareConnect\Api;
use \SquareConnect\Configuration;
use \SquareConnect\ApiClient;
use \SquareConnect\ApiException;
use \SquareConnect\ObjectSerializer;
/**
* OAuthApi Class Doc Comment
*
* @category Class
* @package SquareConnect
* @author Square Inc.
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
* @link https://squareup.com/developers
*/
class OAuthApi
{
/**
* API Client
* @var \SquareConnect\ApiClient instance of the ApiClient
*/
protected $apiClient;
/**
* Constructor
* @param \SquareConnect\ApiClient|null $apiClient The api client to use
*/
function __construct($apiClient = null)
{
if ($apiClient == null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('https://connect.squareup.com');
}
$this->apiClient = $apiClient;
}
/**
* Get API client
* @return \SquareConnect\ApiClient get the API client
*/
public function getApiClient()
{
return $this->apiClient;
}
/**
* Set the API client
* @param \SquareConnect\ApiClient $apiClient set the API client
* @return OAuthApi
*/
public function setApiClient(ApiClient $apiClient)
{
$this->apiClient = $apiClient;
return $this;
}
/**
* obtainToken
*
* ObtainToken
*
* @param \SquareConnect\Model\ObtainTokenRequest $body An object containing the fields to POST for the request. See the corresponding object definition for field details. (required)
* @return \SquareConnect\Model\ObtainTokenResponse
* @throws \SquareConnect\ApiException on non-2xx response
*/
public function obtainToken($body)
{
list($response, $statusCode, $httpHeader) = $this->obtainTokenWithHttpInfo ($body);
return $response;
}
/**
* obtainTokenWithHttpInfo
*
* ObtainToken
*
* @param \SquareConnect\Model\ObtainTokenRequest $body An object containing the fields to POST for the request. See the corresponding object definition for field details. (required)
* @return Array of \SquareConnect\Model\ObtainTokenResponse, HTTP status code, HTTP response headers (array of strings)
* @throws \SquareConnect\ApiException on non-2xx response
*/
public function obtainTokenWithHttpInfo($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
throw new \InvalidArgumentException('Missing the required parameter $body when calling obtainToken');
}
// parse inputs
$resourcePath = "/oauth2/token";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/json'));
$headerParams['Square-Version'] = "2020-05-28";
// default format to json
$resourcePath = str_replace("{format}", "json", $resourcePath);
// body params
$_tempBody = null;
if (isset($body)) {
$_tempBody = $body;
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} elseif (count($formParams) > 0) {
$httpBody = $formParams; // for HTTP post (form)
}
// make the API Call
try {
list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
$resourcePath, 'POST',
$queryParams, $httpBody,
$headerParams, '\SquareConnect\Model\ObtainTokenResponse'
);
if (!$response) {
return array(null, $statusCode, $httpHeader);
}
return array(\SquareConnect\ObjectSerializer::deserialize($response, '\SquareConnect\Model\ObtainTokenResponse', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = \SquareConnect\ObjectSerializer::deserialize($e->getResponseBody(), '\SquareConnect\Model\ObtainTokenResponse', $e->getResponseHeaders());
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* @deprecated
* renewToken
*
* RenewToken
*
* @param string $client_id Your application ID, available from the [application dashboard](https://connect.squareup.com/apps). (required)
* @param \SquareConnect\Model\RenewTokenRequest $body An object containing the fields to POST for the request. See the corresponding object definition for field details. (required)
* @return \SquareConnect\Model\RenewTokenResponse
* @throws \SquareConnect\ApiException on non-2xx response
*/
public function renewToken($client_id, $body)
{
trigger_error("\x1B[33mCalling deprecated API: OAuthApi.renewToken\x1B[0m", E_USER_DEPRECATED);
list($response, $statusCode, $httpHeader) = $this->renewTokenWithHttpInfo ($client_id, $body);
return $response;
}
/**
* renewTokenWithHttpInfo
*
* RenewToken
*
* @param string $client_id Your application ID, available from the [application dashboard](https://connect.squareup.com/apps). (required)
* @param \SquareConnect\Model\RenewTokenRequest $body An object containing the fields to POST for the request. See the corresponding object definition for field details. (required)
* @return Array of \SquareConnect\Model\RenewTokenResponse, HTTP status code, HTTP response headers (array of strings)
* @throws \SquareConnect\ApiException on non-2xx response
*/
public function renewTokenWithHttpInfo($client_id, $body)
{
// verify the required parameter 'client_id' is set
if ($client_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $client_id when calling renewToken');
}
// verify the required parameter 'body' is set
if ($body === null) {
throw new \InvalidArgumentException('Missing the required parameter $body when calling renewToken');
}
// parse inputs
$resourcePath = "/oauth2/clients/{client_id}/access-token/renew";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/json'));
$headerParams['Square-Version'] = "2020-05-28";
// path params
if ($client_id !== null) {
$resourcePath = str_replace(
"{" . "client_id" . "}",
$this->apiClient->getSerializer()->toPathValue($client_id),
$resourcePath
);
}
// default format to json
$resourcePath = str_replace("{format}", "json", $resourcePath);
// body params
$_tempBody = null;
if (isset($body)) {
$_tempBody = $body;
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} elseif (count($formParams) > 0) {
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires API key authentication
$apiKey = $this->apiClient->getApiKeyWithPrefix('Authorization');
if (strlen($apiKey) !== 0) {
$headerParams['Authorization'] = $apiKey;
}
// make the API Call
try {
list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
$resourcePath, 'POST',
$queryParams, $httpBody,
$headerParams, '\SquareConnect\Model\RenewTokenResponse'
);
if (!$response) {
return array(null, $statusCode, $httpHeader);
}
return array(\SquareConnect\ObjectSerializer::deserialize($response, '\SquareConnect\Model\RenewTokenResponse', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = \SquareConnect\ObjectSerializer::deserialize($e->getResponseBody(), '\SquareConnect\Model\RenewTokenResponse', $e->getResponseHeaders());
$e->setResponseObject($data);
break;
}
throw $e;
}
}
/**
* revokeToken
*
* RevokeToken
*
* @param \SquareConnect\Model\RevokeTokenRequest $body An object containing the fields to POST for the request. See the corresponding object definition for field details. (required)
* @return \SquareConnect\Model\RevokeTokenResponse
* @throws \SquareConnect\ApiException on non-2xx response
*/
public function revokeToken($body)
{
list($response, $statusCode, $httpHeader) = $this->revokeTokenWithHttpInfo ($body);
return $response;
}
/**
* revokeTokenWithHttpInfo
*
* RevokeToken
*
* @param \SquareConnect\Model\RevokeTokenRequest $body An object containing the fields to POST for the request. See the corresponding object definition for field details. (required)
* @return Array of \SquareConnect\Model\RevokeTokenResponse, HTTP status code, HTTP response headers (array of strings)
* @throws \SquareConnect\ApiException on non-2xx response
*/
public function revokeTokenWithHttpInfo($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
throw new \InvalidArgumentException('Missing the required parameter $body when calling revokeToken');
}
// parse inputs
$resourcePath = "/oauth2/revoke";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/json'));
$headerParams['Square-Version'] = "2020-05-28";
// default format to json
$resourcePath = str_replace("{format}", "json", $resourcePath);
// body params
$_tempBody = null;
if (isset($body)) {
$_tempBody = $body;
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} elseif (count($formParams) > 0) {
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires API key authentication
$apiKey = $this->apiClient->getApiKeyWithPrefix('Authorization');
if (strlen($apiKey) !== 0) {
$headerParams['Authorization'] = $apiKey;
}
// make the API Call
try {
list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
$resourcePath, 'POST',
$queryParams, $httpBody,
$headerParams, '\SquareConnect\Model\RevokeTokenResponse'
);
if (!$response) {
return array(null, $statusCode, $httpHeader);
}
return array(\SquareConnect\ObjectSerializer::deserialize($response, '\SquareConnect\Model\RevokeTokenResponse', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = \SquareConnect\ObjectSerializer::deserialize($e->getResponseBody(), '\SquareConnect\Model\RevokeTokenResponse', $e->getResponseHeaders());
$e->setResponseObject($data);
break;
}
throw $e;
}
}
}