Skip to content

Commit 9f8246a

Browse files
configurable connection and queue (#159)
1 parent 2387f0d commit 9f8246a

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

config/stripe-webhooks.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
*/
3838
'profile' => \Spatie\StripeWebhooks\StripeWebhookProfile::class,
3939

40+
/*
41+
* Specify a connection and or a queue to process the webhooks
42+
*/
43+
'connection' => env('STRIPE_WEBHOOK_CONNECTION'),
44+
'queue' => env('STRIPE_WEBHOOK_QUEUE'),
45+
4046
/*
4147
* When disabled, the package will not verify if the signature is valid.
4248
* This can be handy in local environments.

src/ProcessStripeWebhookJob.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44

55
use Spatie\StripeWebhooks\Exceptions\WebhookFailed;
66
use Spatie\WebhookClient\Jobs\ProcessWebhookJob;
7+
use Spatie\WebhookClient\Models\WebhookCall;
78

89
class ProcessStripeWebhookJob extends ProcessWebhookJob
910
{
11+
public function __construct(WebhookCall $webhookCall)
12+
{
13+
parent::__construct($webhookCall);
14+
$this->onConnection(config('stripe-webhooks.connection'));
15+
$this->onQueue(config('stripe-webhooks.queue'));
16+
}
17+
1018
public function handle()
1119
{
1220
if (! isset($this->webhookCall->payload['type']) || $this->webhookCall->payload['type'] === '') {
@@ -31,7 +39,7 @@ public function handle()
3139
protected function determineJobClass(string $eventType): string
3240
{
3341
$jobConfigKey = str_replace('.', '_', $eventType);
34-
42+
3543
$defaultJob = config('stripe-webhooks.default_job', '');
3644

3745
return config("stripe-webhooks.jobs.{$jobConfigKey}", $defaultJob);

tests/StripeWebhookCallTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,24 @@ public function it_will_dispatch_events_even_when_no_corresponding_job_is_config
8888

8989
$this->assertNull(cache('dummyjob'));
9090
}
91+
92+
/** @test */
93+
public function it_can_specify_a_connection_in_the_config()
94+
{
95+
config(['stripe-webhooks.connection' => 'some-connection']);
96+
97+
$processStripeWebhookJob = new ProcessStripeWebhookJob($this->webhookCall);
98+
99+
$this->assertEquals('some-connection', $processStripeWebhookJob->connection);
100+
}
101+
102+
/** @test */
103+
public function it_can_specify_a_queue_in_the_config()
104+
{
105+
config(['stripe-webhooks.queue' => 'some-queue']);
106+
107+
$processStripeWebhookJob = new ProcessStripeWebhookJob($this->webhookCall);
108+
109+
$this->assertEquals('some-queue', $processStripeWebhookJob->queue);
110+
}
91111
}

0 commit comments

Comments
 (0)