Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
676 lars 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)
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 response()->json([
37
                'status'  => 'error',
38
                'message' => 'Invalid headers or web hook id provided',
39
            ]);
40
        }
41
 
42
        $params = $request->all();
43
 
44
        $payload = [
45
            'auth_algo'         => $headers['PAYPAL-AUTH-ALGO'][0],
46
            'cert_url'          => $headers['PAYPAL-CERT-URL'][0],
47
            'transmission_id'   => $headers['PAYPAL-TRANSMISSION-ID'][0],
48
            'transmission_sig'  => $headers['PAYPAL-TRANSMISSION-SIG'][0],
49
            'transmission_time' => $headers['PAYPAL-TRANSMISSION-TIME'][0],
50
            'webhook_id'        => $this->webhook_id,
51
            'webhook_event'     => $params,
52
        ];
53
 
54
        return $this->verifyWebHook($payload);
55
    }
56
}