| @@ 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. |
|
| @@ 271-299 (lines=29) @@ | ||
| 268 | * |
|
| 269 | * @return array |
|
| 270 | */ |
|
| 271 | public function balance($dealerMsisdn) |
|
| 272 | { |
|
| 273 | try { |
|
| 274 | $response = $this->get( |
|
| 275 | sprintf( |
|
| 276 | '/webservice/smartload/balance/%s', |
|
| 277 | $dealerMsisdn |
|
| 278 | ), |
|
| 279 | [ |
|
| 280 | 'headers' => [ |
|
| 281 | 'Authorization' => sprintf( |
|
| 282 | 'Bearer %s', |
|
| 283 | $this->options['token'] |
|
| 284 | ), |
|
| 285 | ], |
|
| 286 | ] |
|
| 287 | ); |
|
| 288 | ||
| 289 | return [ |
|
| 290 | 'status' => 'ok', |
|
| 291 | 'http_code' => $response->getStatusCode(), |
|
| 292 | 'body' => (string) $response->getBody(), |
|
| 293 | ]; |
|
| 294 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 295 | return $this->clientError($e); |
|
| 296 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 297 | return $this->parseError($e); |
|
| 298 | } |
|
| 299 | } |
|
| 300 | /** |
|
| 301 | * Authenticate and request current day cashup report. |
|
| 302 | * |
|
| @@ 309-337 (lines=29) @@ | ||
| 306 | * |
|
| 307 | * @return array |
|
| 308 | */ |
|
| 309 | public function cashupToday($dealerMsisdn) |
|
| 310 | { |
|
| 311 | try { |
|
| 312 | $response = $this->get( |
|
| 313 | sprintf( |
|
| 314 | '/webservice/smartload/cashup/%s', |
|
| 315 | $dealerMsisdn |
|
| 316 | ), |
|
| 317 | [ |
|
| 318 | 'headers' => [ |
|
| 319 | 'Authorization' => sprintf( |
|
| 320 | 'Bearer %s', |
|
| 321 | $this->options['token'] |
|
| 322 | ), |
|
| 323 | ], |
|
| 324 | ] |
|
| 325 | ); |
|
| 326 | ||
| 327 | return [ |
|
| 328 | 'status' => 'ok', |
|
| 329 | 'http_code' => $response->getStatusCode(), |
|
| 330 | 'body' => (string) $response->getBody(), |
|
| 331 | ]; |
|
| 332 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 333 | return $this->clientError($e); |
|
| 334 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 335 | return $this->parseError($e); |
|
| 336 | } |
|
| 337 | } |
|
| 338 | ||
| 339 | /** |
|
| 340 | * Authenticate and request to transfer funds from one Smartload account to another. |
|
| @@ 391-419 (lines=29) @@ | ||
| 388 | * |
|
| 389 | * @return array |
|
| 390 | */ |
|
| 391 | public function network($id) |
|
| 392 | { |
|
| 393 | try { |
|
| 394 | $response = $this->get( |
|
| 395 | sprintf( |
|
| 396 | '/webservice/smartload/networks/%d', |
|
| 397 | $id |
|
| 398 | ), |
|
| 399 | [ |
|
| 400 | 'headers' => [ |
|
| 401 | 'Authorization' => sprintf( |
|
| 402 | 'Bearer %s', |
|
| 403 | $this->options['token'] |
|
| 404 | ), |
|
| 405 | ], |
|
| 406 | ] |
|
| 407 | ); |
|
| 408 | ||
| 409 | return [ |
|
| 410 | 'status' => 'ok', |
|
| 411 | 'http_code' => $response->getStatusCode(), |
|
| 412 | 'body' => (string) $response->getBody(), |
|
| 413 | ]; |
|
| 414 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 415 | return $this->clientError($e); |
|
| 416 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 417 | return $this->parseError($e); |
|
| 418 | } |
|
| 419 | } |
|
| 420 | ||
| 421 | /** |
|
| 422 | * Authenticate and retrieves a list of all available networks. |
|
| @@ 428-453 (lines=26) @@ | ||
| 425 | * |
|
| 426 | * @return array |
|
| 427 | */ |
|
| 428 | public function networks() |
|
| 429 | { |
|
| 430 | try { |
|
| 431 | $response = $this->get( |
|
| 432 | '/webservice/smartload/networks', |
|
| 433 | [ |
|
| 434 | 'headers' => [ |
|
| 435 | 'Authorization' => sprintf( |
|
| 436 | 'Bearer %s', |
|
| 437 | $this->options['token'] |
|
| 438 | ), |
|
| 439 | ], |
|
| 440 | ] |
|
| 441 | ); |
|
| 442 | ||
| 443 | return [ |
|
| 444 | 'status' => 'ok', |
|
| 445 | 'http_code' => $response->getStatusCode(), |
|
| 446 | 'body' => (string) $response->getBody(), |
|
| 447 | ]; |
|
| 448 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 449 | return $this->clientError($e); |
|
| 450 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 451 | return $this->parseError($e); |
|
| 452 | } |
|
| 453 | } |
|
| 454 | ||
| 455 | /** |
|
| 456 | * Test SmartCall is responding. |
|
| @@ 488-516 (lines=29) @@ | ||
| 485 | * |
|
| 486 | * @return array |
|
| 487 | */ |
|
| 488 | public function products($id) |
|
| 489 | { |
|
| 490 | try { |
|
| 491 | $response = $this->get( |
|
| 492 | sprintf( |
|
| 493 | '/webservice/smartload/products/%d', |
|
| 494 | $id |
|
| 495 | ), |
|
| 496 | [ |
|
| 497 | 'headers' => [ |
|
| 498 | 'Authorization' => sprintf( |
|
| 499 | 'Bearer %s', |
|
| 500 | $this->options['token'] |
|
| 501 | ), |
|
| 502 | ], |
|
| 503 | ] |
|
| 504 | ); |
|
| 505 | ||
| 506 | return [ |
|
| 507 | 'status' => 'ok', |
|
| 508 | 'http_code' => $response->getStatusCode(), |
|
| 509 | 'body' => (string) $response->getBody(), |
|
| 510 | ]; |
|
| 511 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 512 | return $this->clientError($e); |
|
| 513 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 514 | return $this->parseError($e); |
|
| 515 | } |
|
| 516 | } |
|
| 517 | ||
| 518 | /** |
|
| 519 | * Authenticate and checks if the provided ID (MSISDN) is registered with Smartload. |
|
| @@ 527-555 (lines=29) @@ | ||
| 524 | * |
|
| 525 | * @return array |
|
| 526 | */ |
|
| 527 | public function registered($dealerMsisdn) |
|
| 528 | { |
|
| 529 | try { |
|
| 530 | $response = $this->get( |
|
| 531 | sprintf( |
|
| 532 | '/webservice/smartload/registered/%s', |
|
| 533 | $dealerMsisdn |
|
| 534 | ), |
|
| 535 | [ |
|
| 536 | 'headers' => [ |
|
| 537 | 'Authorization' => sprintf( |
|
| 538 | 'Bearer %s', |
|
| 539 | $this->options['token'] |
|
| 540 | ), |
|
| 541 | ], |
|
| 542 | ] |
|
| 543 | ); |
|
| 544 | ||
| 545 | return [ |
|
| 546 | 'status' => 'ok', |
|
| 547 | 'http_code' => $response->getStatusCode(), |
|
| 548 | 'body' => (string) $response->getBody(), |
|
| 549 | ]; |
|
| 550 | } catch (\GuzzleHttp\Exception\ClientException $e) { |
|
| 551 | return $this->clientError($e); |
|
| 552 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
|
| 553 | return $this->parseError($e); |
|
| 554 | } |
|
| 555 | } |
|
| 556 | ||
| 557 | /** |
|
| 558 | * Parse the java exception that we receive from Smartcall's Tomcat's. |
|