Completed
Pull Request — master (#44)
by Rias
01:16
created

ProcessStripeWebhookJob::determineJobClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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