Passed
Pull Request — master (#2330)
by
unknown
10:14
created

VerifyStripeWebhook::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 14
rs 9.9666
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Stripe\WebhookSignature;
9
use Stripe\Exception\SignatureVerificationException;
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
It seems like $request->header('Stripe-Signature') can also be of type array; however, parameter $header of Stripe\WebhookSignature::verifyHeader() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
                /** @scrutinizer ignore-type */ $request->header('Stripe-Signature'),
Loading history...
27
                \Config::get('services.stripe.secret'),
28
                null
29
            );
30
        } catch (SignatureVerificationException $exception) {
31
            throw new AccessDeniedHttpException($exception->getMessage(), $exception);
32
        }
33
34
        return $next($request);
35
    }
36
}
37