Skip to content

Commit

Permalink
authenticate webhook (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
myckhel authored May 26, 2022
1 parent dec7b9e commit 1a477f6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Http/Controllers/HookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@

use Myckhel\Paystack\Events\Hook;
use Illuminate\Http\Request;
use Myckhel\Paystack\Traits\PaystackConfig;

class HookController extends Controller
{
use PaystackConfig;

public function hook(Request $request)
{
$signature = $request->header('x-paystack-signature');
if (!$signature) {
abort(403);
}

$signingSecret = $this->config('secret_key');

if (empty($signingSecret)) {
abort(403, 'Signing Secret Not Set');
}

$computedSignature = hash_hmac('sha512', $request->getContent(), $signingSecret);

if (!hash_equals($signature, $computedSignature)) return abort(403);

event(new Hook($request->all()));

return ['status' => true];
}
}

0 comments on commit 1a477f6

Please sign in to comment.