Skip to content

Commit c164322

Browse files
committed
implemented webhook event receiver/dispatcher
1 parent d38cdba commit c164322

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/Events/Hook.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Myckhel\Mono\Events;
4+
5+
use Illuminate\Foundation\Events\Dispatchable;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class Hook
9+
{
10+
use Dispatchable, SerializesModels;
11+
12+
public $event;
13+
14+
/**
15+
* Create a new event instance.
16+
*
17+
* @return void
18+
*/
19+
public function __construct($event)
20+
{
21+
$this->event = $event;
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Myckhel\Mono\Http\Controllers;
4+
5+
use Myckhel\Mono\Events\Hook;
6+
use Mono;
7+
use Illuminate\Http\Request;
8+
9+
class HookController extends Controller
10+
{
11+
public function hook(Request $request) {
12+
if (!Mono::verifyWebHook($request->header('mono-webhook-secret')))
13+
return abort(403);
14+
15+
event(new Hook($request->all()));
16+
return ['status' => true];
17+
}
18+
}

src/routes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Myckhel\Mono\Http\Controllers\PaymentController;
88
use Myckhel\Mono\Http\Controllers\CacController;
99
use Myckhel\Mono\Http\Controllers\WalletController;
10+
use Myckhel\Mono\Http\Controllers\HookController;
1011

1112
$middleware = Config::config('route.middleware');
1213
$prefix = Config::config('route.prefix');
@@ -32,13 +33,15 @@
3233
'cac/lookup' => 'get,cac,lookup',
3334
'cac/company/{id}' => 'get,cac,company',
3435
'wallet' => 'get,wallet,balance',
36+
'hooks' => 'post,hook,hook',
3537
];
3638

3739
$controls = [
3840
'account' => AccountController::class,
3941
'payment' => PaymentController::class,
4042
'cac' => CacController::class,
4143
'wallet' => WalletController::class,
44+
'hook' => HookController::class,
4245
];
4346

4447
collect($routes)->map(function ($route, $endpoint) use($controls){

0 commit comments

Comments
 (0)