Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding of default initial response #41

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/webhook-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
*/
'webhook_model' => \Spatie\WebhookClient\Models\WebhookCall::class,

/*
* The controller to use when handling the initial webhook response. This will use
* the Spatie package default if not provided.
*/
'webhook_response' => null,

/*
* The class name of the job that will process the webhook request.
*
Expand Down
4 changes: 4 additions & 0 deletions src/WebhookConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function __construct(array $properties)

$this->webhookModel = $properties['webhook_model'];

$this->webhookResponse = array_key_exists('webhook_response', $properties) && $properties['webhook_response']
? app($properties['webhook_response'])
: '';

if (! is_subclass_of($properties['process_webhook_job'], ProcessWebhookJob::class)) {
throw InvalidConfig::invalidProcessWebhookJob($properties['process_webhook_job']);
}
Expand Down
4 changes: 4 additions & 0 deletions src/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public function __invoke(Request $request, WebhookConfig $config)
{
(new WebhookProcessor($request, $config))->process();

if ($config->webhookResponse) {
return $config->webhookReponse->response($request);
}

return response()->json(['message' => 'ok']);
}
}