| @@ 124-149 (lines=26) @@ | ||
| 121 | * |
|
| 122 | * @return array |
|
| 123 | */ |
|
| 124 | public function authDelete() |
|
| 125 | { |
|
| 126 | try { |
|
| 127 | $response = $this->delete( |
|
| 128 | '/webservice/auth', |
|
| 129 | [ |
|
| 130 | 'headers' => [ |
|
| 131 | 'Authorization' => sprintf( |
|
| 132 | 'Bearer %s', |
|
| 133 | $this->options['token'] |
|
| 134 | ), |
|
| 135 | ], |
|
| 136 | ] |
|
| 137 | ); |
|
| 138 | ||
| 139 | return [ |
|
| 140 | 'status' => 'ok', |
|
| 141 | 'http_code' => $response->getStatusCode(), |
|
| 142 | 'body' => (string) $response->getBody(), |
|
| 143 | ]; |
|
| 144 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 145 | return $this->clientError($e); |
|
| 146 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 147 | return $this->parseError($e); |
|
| 148 | } |
|
| 149 | } |
|
| 150 | ||
| 151 | /** |
|
| 152 | * Authenticate and invalidates all the user allocated tokens. |
|
| @@ 289-317 (lines=29) @@ | ||
| 286 | * |
|
| 287 | * @return array |
|
| 288 | */ |
|
| 289 | public function cashupToday($dealerMsisdn) |
|
| 290 | { |
|
| 291 | try { |
|
| 292 | $response = $this->get( |
|
| 293 | sprintf( |
|
| 294 | '/webservice/smartload/cashup/%s', |
|
| 295 | $dealerMsisdn |
|
| 296 | ), |
|
| 297 | [ |
|
| 298 | 'headers' => [ |
|
| 299 | 'Authorization' => sprintf( |
|
| 300 | 'Bearer %s', |
|
| 301 | $this->options['token'] |
|
| 302 | ), |
|
| 303 | ], |
|
| 304 | ] |
|
| 305 | ); |
|
| 306 | ||
| 307 | return [ |
|
| 308 | 'status' => 'ok', |
|
| 309 | 'http_code' => $response->getStatusCode(), |
|
| 310 | 'body' => (string) $response->getBody(), |
|
| 311 | ]; |
|
| 312 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 313 | return $this->clientError($e); |
|
| 314 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 315 | return $this->parseError($e); |
|
| 316 | } |
|
| 317 | } |
|
| 318 | ||
| 319 | /** |
|
| 320 | * Authenticate and retrieves a list of all available networks. |
|
| @@ 326-354 (lines=29) @@ | ||
| 323 | * |
|
| 324 | * @return array |
|
| 325 | */ |
|
| 326 | public function network($id) |
|
| 327 | { |
|
| 328 | try { |
|
| 329 | $response = $this->get( |
|
| 330 | sprintf( |
|
| 331 | '/webservice/smartload/networks/%d', |
|
| 332 | $id |
|
| 333 | ), |
|
| 334 | [ |
|
| 335 | 'headers' => [ |
|
| 336 | 'Authorization' => sprintf( |
|
| 337 | 'Bearer %s', |
|
| 338 | $this->options['token'] |
|
| 339 | ), |
|
| 340 | ], |
|
| 341 | ] |
|
| 342 | ); |
|
| 343 | ||
| 344 | return [ |
|
| 345 | 'status' => 'ok', |
|
| 346 | 'http_code' => $response->getStatusCode(), |
|
| 347 | 'body' => (string) $response->getBody(), |
|
| 348 | ]; |
|
| 349 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 350 | return $this->clientError($e); |
|
| 351 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 352 | return $this->parseError($e); |
|
| 353 | } |
|
| 354 | } |
|
| 355 | ||
| 356 | /** |
|
| 357 | * Authenticate and retrieves a list of all available networks. |
|
| @@ 363-388 (lines=26) @@ | ||
| 360 | * |
|
| 361 | * @return array |
|
| 362 | */ |
|
| 363 | public function networks() |
|
| 364 | { |
|
| 365 | try { |
|
| 366 | $response = $this->get( |
|
| 367 | '/webservice/smartload/networks', |
|
| 368 | [ |
|
| 369 | 'headers' => [ |
|
| 370 | 'Authorization' => sprintf( |
|
| 371 | 'Bearer %s', |
|
| 372 | $this->options['token'] |
|
| 373 | ), |
|
| 374 | ], |
|
| 375 | ] |
|
| 376 | ); |
|
| 377 | ||
| 378 | return [ |
|
| 379 | 'status' => 'ok', |
|
| 380 | 'http_code' => $response->getStatusCode(), |
|
| 381 | 'body' => (string) $response->getBody(), |
|
| 382 | ]; |
|
| 383 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 384 | return $this->clientError($e); |
|
| 385 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 386 | return $this->parseError($e); |
|
| 387 | } |
|
| 388 | } |
|
| 389 | ||
| 390 | /** |
|
| 391 | * Test SmartCall is responding. |
|
| @@ 423-451 (lines=29) @@ | ||
| 420 | * |
|
| 421 | * @return array |
|
| 422 | */ |
|
| 423 | public function products($id) |
|
| 424 | { |
|
| 425 | try { |
|
| 426 | $response = $this->get( |
|
| 427 | sprintf( |
|
| 428 | '/webservice/smartload/products/%d', |
|
| 429 | $id |
|
| 430 | ), |
|
| 431 | [ |
|
| 432 | 'headers' => [ |
|
| 433 | 'Authorization' => sprintf( |
|
| 434 | 'Bearer %s', |
|
| 435 | $this->options['token'] |
|
| 436 | ), |
|
| 437 | ], |
|
| 438 | ] |
|
| 439 | ); |
|
| 440 | ||
| 441 | return [ |
|
| 442 | 'status' => 'ok', |
|
| 443 | 'http_code' => $response->getStatusCode(), |
|
| 444 | 'body' => (string) $response->getBody(), |
|
| 445 | ]; |
|
| 446 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 447 | return $this->clientError($e); |
|
| 448 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 449 | return $this->parseError($e); |
|
| 450 | } |
|
| 451 | } |
|
| 452 | ||
| 453 | /** |
|
| 454 | * Parse the java exception that we receive from Smartcall's Tomcat's. |
|