GloBee-Official /
payment-api-php
| 1 | <?php |
||
| 2 | |||
| 3 | namespace GloBee\PaymentApi\Connectors; |
||
| 4 | |||
| 5 | use GloBee\PaymentApi\Exceptions\Http\AuthenticationException; |
||
| 6 | use GloBee\PaymentApi\Exceptions\Http\ForbiddenException; |
||
| 7 | use GloBee\PaymentApi\Exceptions\Http\HttpException; |
||
| 8 | use GloBee\PaymentApi\Exceptions\Http\NotFoundException; |
||
| 9 | use GloBee\PaymentApi\Exceptions\Http\ServerErrorException; |
||
| 10 | use GloBee\PaymentApi\Exceptions\Validation\ValidationException; |
||
| 11 | |||
| 12 | abstract class Connector |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @param string $uri |
||
|
0 ignored issues
–
show
Coding Style
Documentation
introduced
by
Loading history...
|
|||
| 16 | * |
||
| 17 | * @return array |
||
| 18 | */ |
||
| 19 | abstract public function getJson($uri); |
||
|
0 ignored issues
–
show
|
|||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $uri |
||
|
0 ignored issues
–
show
|
|||
| 23 | * @param array $data |
||
|
0 ignored issues
–
show
|
|||
| 24 | * |
||
| 25 | * @return array |
||
| 26 | */ |
||
| 27 | abstract public function postJson($uri, array $data); |
||
|
0 ignored issues
–
show
|
|||
| 28 | |||
| 29 | /** |
||
|
0 ignored issues
–
show
|
|||
| 30 | * @param $code |
||
|
0 ignored issues
–
show
|
|||
| 31 | * @param $body |
||
|
0 ignored issues
–
show
|
|||
| 32 | * |
||
| 33 | * @throws \GloBee\PaymentApi\Exceptions\Http\HttpException; |
||
|
0 ignored issues
–
show
|
|||
| 34 | */ |
||
|
0 ignored issues
–
show
|
|||
| 35 | 6 | protected function handleErrors($code, $body) |
|
|
0 ignored issues
–
show
|
|||
| 36 | { |
||
| 37 | switch ($code) { |
||
| 38 | 6 | case 401: |
|
| 39 | 1 | throw new AuthenticationException(); |
|
| 40 | 5 | case 403: |
|
| 41 | 1 | throw new ForbiddenException(); |
|
| 42 | 4 | case 404: |
|
| 43 | 1 | throw new NotFoundException(); |
|
| 44 | 3 | case 422: |
|
| 45 | 1 | throw new ValidationException(json_decode($body, true)['errors']); |
|
| 46 | } |
||
| 47 | |||
| 48 | 2 | if ($code >= 500) { |
|
| 49 | 1 | throw new ServerErrorException(); |
|
| 50 | } |
||
| 51 | |||
| 52 | 1 | throw new HttpException('Unknown HTTP exception', $code); |
|
| 53 | } |
||
| 54 | } |
||
| 55 |