Skip to content

Commit

Permalink
configurable connection and queue (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
diogogomeswww authored Jun 6, 2023
1 parent 2387f0d commit 9f8246a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions config/stripe-webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
*/
'profile' => \Spatie\StripeWebhooks\StripeWebhookProfile::class,

/*
* Specify a connection and or a queue to process the webhooks
*/
'connection' => env('STRIPE_WEBHOOK_CONNECTION'),
'queue' => env('STRIPE_WEBHOOK_QUEUE'),

/*
* When disabled, the package will not verify if the signature is valid.
* This can be handy in local environments.
Expand Down
10 changes: 9 additions & 1 deletion src/ProcessStripeWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@

use Spatie\StripeWebhooks\Exceptions\WebhookFailed;
use Spatie\WebhookClient\Jobs\ProcessWebhookJob;
use Spatie\WebhookClient\Models\WebhookCall;

class ProcessStripeWebhookJob extends ProcessWebhookJob
{
public function __construct(WebhookCall $webhookCall)
{
parent::__construct($webhookCall);
$this->onConnection(config('stripe-webhooks.connection'));
$this->onQueue(config('stripe-webhooks.queue'));
}

public function handle()
{
if (! isset($this->webhookCall->payload['type']) || $this->webhookCall->payload['type'] === '') {
Expand All @@ -31,7 +39,7 @@ public function handle()
protected function determineJobClass(string $eventType): string
{
$jobConfigKey = str_replace('.', '_', $eventType);

$defaultJob = config('stripe-webhooks.default_job', '');

return config("stripe-webhooks.jobs.{$jobConfigKey}", $defaultJob);
Expand Down
20 changes: 20 additions & 0 deletions tests/StripeWebhookCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,24 @@ public function it_will_dispatch_events_even_when_no_corresponding_job_is_config

$this->assertNull(cache('dummyjob'));
}

/** @test */
public function it_can_specify_a_connection_in_the_config()
{
config(['stripe-webhooks.connection' => 'some-connection']);

$processStripeWebhookJob = new ProcessStripeWebhookJob($this->webhookCall);

$this->assertEquals('some-connection', $processStripeWebhookJob->connection);
}

/** @test */
public function it_can_specify_a_queue_in_the_config()
{
config(['stripe-webhooks.queue' => 'some-queue']);

$processStripeWebhookJob = new ProcessStripeWebhookJob($this->webhookCall);

$this->assertEquals('some-queue', $processStripeWebhookJob->queue);
}
}

0 comments on commit 9f8246a

Please sign in to comment.