Completed
Push — master ( 16ed10...af0efe )
by Freek
01:45
created

ProcessStripeWebhookJob::handle()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
cc 5
nc 4
nop 0
1
<?php
2
3
namespace Spatie\StripeWebhooks;
4
5
use Spatie\StripeWebhooks\Exceptions\WebhookFailed;
6
use Spatie\WebhookClient\ProcessWebhookJob;
7
8
class ProcessStripeWebhookJob extends ProcessWebhookJob
9
{
10
    public function handle()
11
    {
12
        if (!isset($this->webhookCall->payload['type']) || $this->webhookCall->payload['type'] === '') {
13
            throw WebhookFailed::missingType($this->webhookCall);
14
        }
15
16
        event("stripe-webhooks::{$this->webhookCall->payload['type']}", $this->webhookCall);
17
18
        $jobClass = $this->determineJobClass($this->webhookCall->payload['type']);
19
20
        if ($jobClass === '') {
21
            return;
22
        }
23
24
        if (! class_exists($jobClass)) {
25
            throw WebhookFailed::jobClassDoesNotExist($jobClass, $this->webhookCall);
26
        }
27
28
        dispatch(new $jobClass($this->webhookCall));
29
    }
30
31
    protected function determineJobClass(string $eventType): string
32
    {
33
        $jobConfigKey = str_replace('.', '_', $eventType);
34
35
        return config("stripe-webhooks.jobs.{$jobConfigKey}", '');
36
    }
37
}
38