Skip to content

Instantly share code, notes, and snippets.

@nasrulhazim
Created May 6, 2020 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasrulhazim/9659298fc56679d0de12cfd901ef2c5b to your computer and use it in GitHub Desktop.
Save nasrulhazim/9659298fc56679d0de12cfd901ef2c5b to your computer and use it in GitHub Desktop.
Webhook Handler Controller
<?php
namespace App\Http\Controllers\Webhooks;
use App\Http\Controllers\Controller;
use App\Models\WebhookCall;
use App\WebhookClient\SignatureValidator\GitHubSignatureValidator;
use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;
use Spatie\WebhookClient\WebhookProcessor;
use Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile;
class GitHubController extends Controller
{
/**
* Handle the incoming request.
*
* @return \Illuminate\Http\Response
*/
public function __invoke(Request $request, string $configKey = null)
{
$webhookConfig = new WebhookConfig([
'name' => 'github',
'signing_secret' => ($configKey) ?
config('webhooks.github.signing_secret.' . $configKey) :
config('webhooks.github.signing_secret'),
'signature_header_name' => config('webhooks.github.signature_header_name'),
'signature_validator' => GitHubSignatureValidator::class,
'webhook_profile' => ProcessEverythingWebhookProfile::class,
'webhook_model' => WebhookCall::class,
'process_webhook_job' => config('webhooks.github.model'),
]);
(new WebhookProcessor($request, $webhookConfig))->process();
return response()->json([
'message' => 'ok',
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment