-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOAuthException.php
55 lines (44 loc) · 1.59 KB
/
OAuthException.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
<?php
declare(strict_types=1);
namespace Ankurk91\StripeExceptions;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Response;
use Stripe\Exception;
use Throwable;
class OAuthException extends AbstractException
{
/**
* Where to redirect when an exception occurred.
*/
protected string $redirectTo;
protected array $dontReport = [
Exception\OAuth\InvalidGrantException::class,
Exception\OAuth\InvalidScopeException::class,
Exception\OAuth\UnsupportedResponseTypeException::class,
];
public function __construct(Throwable $exception, string $redirectTo)
{
$this->redirectTo = $redirectTo;
parent::__construct($exception);
}
/**
* {@inheritdoc}
*/
public function render($request)
{
$exception = $this->getPrevious();
$stripeCode = null;
$message = match (get_class($exception)) {
Exception\OAuth\InvalidClientException::class => Lang::get('stripe::exceptions.oauth.invalid_client'),
Exception\OAuth\InvalidRequestException::class => Lang::get('stripe::exceptions.oauth.invalid_request'),
Exception\OAuth\OAuthErrorException::class => Lang::get('stripe::exceptions.oauth.general'),
default => Lang::get('stripe::exceptions.oauth.unknown'),
};
if ($exception instanceof Exception\ApiErrorException) {
$stripeCode = $exception->getStripeCode();
}
return Response::redirectTo($this->redirectTo)
->with('error', $message)
->with('stripe_code', $stripeCode);
}
}