laravel-liberu /
genealogy
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\Middleware; |
||
| 4 | |||
| 5 | use Closure; |
||
| 6 | use Illuminate\Http\Request; |
||
| 7 | use Stripe\Exception\SignatureVerificationException; |
||
| 8 | use Stripe\WebhookSignature; |
||
| 9 | use Symfony\Component\HttpFoundation\Response; |
||
| 10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
||
| 11 | |||
| 12 | class VerifyStripeWebhook |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Handle an incoming request. |
||
| 16 | * |
||
| 17 | * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next |
||
| 18 | * |
||
| 19 | * @throws \Symfony\Component\HttpKernal\Exception\AccessDeniedHttpException |
||
| 20 | */ |
||
| 21 | public function handle(Request $request, Closure $next): Response |
||
| 22 | { |
||
| 23 | try { |
||
| 24 | WebhookSignature::verifyHeader( |
||
| 25 | $request->getContent(), |
||
| 26 | $request->header('Stripe-Signature'), |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 27 | \Config::get('services.stripe.webhook'), |
||
| 28 | null |
||
| 29 | ); |
||
| 30 | } catch (SignatureVerificationException $exception) { |
||
| 31 | throw new AccessDeniedHttpException($exception->getMessage(), $exception); |
||
| 32 | } |
||
| 33 | |||
| 34 | return $next($request); |
||
| 35 | } |
||
| 36 | } |
||
| 37 |