PayPalVerifyIPN::verifyIPN()   B
last analyzed

Complexity

Conditions 7
Paths 2

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 7
eloc 19
c 2
b 1
f 0
nc 2
nop 1
dl 0
loc 29
rs 8.8333
1
<?php
2
3
namespace Srmklive\PayPal\Traits;
4
5
trait PayPalVerifyIPN
6
{
7
    protected $webhook_id;
8
9
    public function setWebHookID(string $webhook_id): \Srmklive\PayPal\Services\PayPal
10
    {
11
        $this->webhook_id = $webhook_id;
12
13
        return $this;
14
    }
15
16
    /**
17
     * Verify incoming IPN through a web hook id.
18
     *
19
     * @throws \Throwable
20
     *
21
     * @return array|\Psr\Http\Message\StreamInterface|string
22
     */
23
    public function verifyIPN(\Illuminate\Http\Request $request)
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
    {
25
        $headers = array_change_key_case($request->headers->all(), CASE_UPPER);
26
27
        if (!isset($headers['PAYPAL-AUTH-ALGO'][0]) ||
28
            !isset($headers['PAYPAL-TRANSMISSION-ID'][0]) ||
29
            !isset($headers['PAYPAL-CERT-URL'][0]) ||
30
            !isset($headers['PAYPAL-TRANSMISSION-SIG'][0]) ||
31
            !isset($headers['PAYPAL-TRANSMISSION-TIME'][0]) ||
32
            !isset($this->webhook_id)
33
        ) {
34
            \Log::error('Invalid headers or webhook id supplied for paypal webhook');
35
36
            return ['error' => 'Invalid headers or webhook id provided'];
37
        }
38
39
        $params = json_decode($request->getContent());
40
41
        $payload = [
42
            'auth_algo'         => $headers['PAYPAL-AUTH-ALGO'][0],
43
            'cert_url'          => $headers['PAYPAL-CERT-URL'][0],
44
            'transmission_id'   => $headers['PAYPAL-TRANSMISSION-ID'][0],
45
            'transmission_sig'  => $headers['PAYPAL-TRANSMISSION-SIG'][0],
46
            'transmission_time' => $headers['PAYPAL-TRANSMISSION-TIME'][0],
47
            'webhook_id'        => $this->webhook_id,
48
            'webhook_event'     => $params,
49
        ];
50
51
        return $this->verifyWebHook($payload);
0 ignored issues
show
Bug introduced by
It seems like verifyWebHook() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

51
        return $this->/** @scrutinizer ignore-call */ verifyWebHook($payload);
Loading history...
52
    }
53
}
54