Completed
Pull Request — master (#4)
by Morten Poul
11:21
created

Webhook::eventName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Signifly\Shopify\Webhooks;
4
5
use Illuminate\Http\Request;
6
7
class Webhook
8
{
9
    const HEADER_HMAC_SIGNATURE = 'X-Shopify-Hmac-Sha256';
10
    const HEADER_SHOP_DOMAIN = 'X-Shopify-Shop-Domain';
11
    const HEADER_TOPIC = 'X-Shopify-Topic';
12
13
    protected string $domain;
14
    protected string $topic;
15
    protected array $payload;
16
17
    public function __construct(string $domain, string $topic, array $payload)
18
    {
19
        $this->domain = $domain;
20
        $this->topic = $topic;
21
        $this->payload = $payload;
22
    }
23
24
    public function domain(): string
25
    {
26
        return $this->domain;
27
    }
28
29
    public function eventName(): string
30
    {
31
        return 'shopify-webhooks.'.str_replace('/', '-', $this->topic());
32
    }
33
34
    public function payload(): array
35
    {
36
        return $this->payload;
37
    }
38
39
    public function topic(): string
40
    {
41
        return $this->topic;
42
    }
43
44
    public static function fromRequest(Request $request): self
45
    {
46
        return new self(
47
            $request->shopifyShopDomain(),
48
            $request->shopifyTopic(),
49
            json_decode($request->getContent(), true)
50
        );
51
    }
52
}
53