1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\WebhookClient; |
4
|
|
|
|
5
|
|
|
use Spatie\WebhookClient\Exceptions\InvalidConfig; |
6
|
|
|
use Spatie\WebhookClient\SignatureValidator\SignatureValidator; |
7
|
|
|
use Spatie\WebhookClient\WebhookProfile\WebhookProfile; |
8
|
|
|
use Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo; |
9
|
|
|
use Spatie\WebhookClient\WebhookResponse\RespondsToWebhook; |
10
|
|
|
|
11
|
|
|
class WebhookConfig |
12
|
|
|
{ |
13
|
|
|
public string $name; |
|
|
|
|
14
|
|
|
|
15
|
|
|
public string $signingSecret; |
16
|
|
|
|
17
|
|
|
public string $signatureHeaderName; |
18
|
|
|
|
19
|
|
|
public SignatureValidator $signatureValidator; |
20
|
|
|
|
21
|
|
|
public WebhookProfile $webhookProfile; |
22
|
|
|
|
23
|
|
|
public RespondsToWebhook $webhookResponse; |
24
|
|
|
|
25
|
|
|
public string $webhookModel; |
26
|
|
|
|
27
|
|
|
public string $processWebhookJobClass; |
28
|
|
|
|
29
|
|
|
public function __construct(array $properties) |
30
|
|
|
{ |
31
|
|
|
$this->name = $properties['name']; |
32
|
|
|
|
33
|
|
|
$this->signingSecret = $properties['signing_secret'] ?? ''; |
34
|
|
|
|
35
|
|
|
$this->signatureHeaderName = $properties['signature_header_name'] ?? ''; |
36
|
|
|
|
37
|
|
|
if (! is_subclass_of($properties['signature_validator'], SignatureValidator::class)) { |
38
|
|
|
throw InvalidConfig::invalidSignatureValidator($properties['signature_validator']); |
39
|
|
|
} |
40
|
|
|
$this->signatureValidator = app($properties['signature_validator']); |
41
|
|
|
|
42
|
|
|
if (! is_subclass_of($properties['webhook_profile'], WebhookProfile::class)) { |
43
|
|
|
throw InvalidConfig::invalidWebhookProfile($properties['webhook_profile']); |
44
|
|
|
} |
45
|
|
|
$this->webhookProfile = app($properties['webhook_profile']); |
46
|
|
|
|
47
|
|
|
$webhookResponseClass = $properties['webhook_response'] ?? DefaultRespondsTo::class; |
48
|
|
|
if (! is_subclass_of($webhookResponseClass, RespondsToWebhook::class)) { |
49
|
|
|
throw InvalidConfig::invalidWebhookResponse($webhookResponseClass); |
50
|
|
|
} |
51
|
|
|
$this->webhookResponse = app($webhookResponseClass); |
52
|
|
|
|
53
|
|
|
$this->webhookModel = $properties['webhook_model']; |
54
|
|
|
|
55
|
|
|
if (! is_subclass_of($properties['process_webhook_job'], ProcessWebhookJob::class)) { |
56
|
|
|
throw InvalidConfig::invalidProcessWebhookJob($properties['process_webhook_job']); |
57
|
|
|
} |
58
|
|
|
$this->processWebhookJobClass = $properties['process_webhook_job']; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|