-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiException.php
69 lines (56 loc) · 2.29 KB
/
ApiException.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
<?php
declare(strict_types=1);
namespace Ankurk91\StripeExceptions;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Response;
use Stripe\Exception;
class ApiException extends AbstractException
{
protected array $dontReport = [
Exception\ApiConnectionException::class,
Exception\CardException::class,
Exception\IdempotencyException::class,
];
/**
* {@inheritdoc}
*/
public function render($request)
{
$exception = $this->getPrevious();
$response['message'] = Lang::get('stripe::exceptions.api.unknown');
$response['stripe'] = [];
$httpCode = 500;
if ($exception instanceof Exception\ApiErrorException) {
$response['stripe']['code'] = $exception->getStripeCode();
}
switch (get_class($exception)) {
case Exception\CardException::class:
$httpCode = 400;
$response['message'] = data_get(
$exception->getJsonBody(), 'error.message',
Lang::get('stripe::exceptions.api.invalid_card')
);
$response['stripe']['declined_code'] = $exception->getDeclineCode();
$response['stripe']['param'] = $exception->getStripeParam();
break;
case Exception\RateLimitException::class:
$response['message'] = Lang::get('stripe::exceptions.api.rate_limit');
break;
case Exception\InvalidRequestException::class:
$httpCode = 400;
$response['message'] = Lang::get('stripe::exceptions.api.invalid_request');
$response['stripe']['param'] = $exception->getStripeParam();
break;
case Exception\AuthenticationException::class:
$response['message'] = Lang::get('stripe::exceptions.api.authentication');
break;
case Exception\ApiConnectionException::class:
$response['message'] = Lang::get('stripe::exceptions.api.connection');
break;
case Exception\ApiErrorException::class:
$response['message'] = Lang::get('stripe::exceptions.api.general');
break;
}
return Response::json($response, $httpCode);
}
}