|
1 | 1 | <?php |
2 | | - |
3 | | - |
4 | 2 | namespace Digikraaft\PaystackSubscription\Http\Controllers; |
5 | 3 |
|
6 | | -use Digikraaft\PaystackSubscription\Events\WebhookHandled; |
7 | | -use Digikraaft\PaystackSubscription\Events\WebhookReceived; |
8 | | -use Digikraaft\PaystackSubscription\Http\Middleware\VerifyWebhookSignature; |
9 | 4 | use Digikraaft\PaystackSubscription\PaystackSubscription; |
10 | | -use Illuminate\Http\Request; |
11 | | -use Illuminate\Routing\Controller; |
12 | | -use Illuminate\Support\Str; |
13 | | -use Symfony\Component\HttpFoundation\Response; |
| 5 | +use Digikraaft\PaystackWebhooks\Http\Controllers\WebhooksController as WebhooksController; |
14 | 6 |
|
15 | | -class WebhookController extends Controller |
| 7 | +class WebhookController extends WebhooksController |
16 | 8 | { |
17 | | - /** |
18 | | - * Create a new WebhookController instance. |
19 | | - * |
20 | | - * @return void |
21 | | - */ |
22 | | - public function __construct() |
23 | | - { |
24 | | - if (config('paystacksubscription.secret', env('PAYSTACK_SECRET'))) { |
25 | | - $this->middleware(VerifyWebhookSignature::class); |
26 | | - } |
27 | | - } |
28 | | - |
29 | | - /** |
30 | | - * Handle Paystack webhook call. |
31 | | - * |
32 | | - * @param \Illuminate\Http\Request $request |
33 | | - * @return \Symfony\Component\HttpFoundation\Response |
34 | | - */ |
35 | | - public function handleWebhook(Request $request) |
36 | | - { |
37 | | - $payload = json_decode($request->getContent(), true); |
38 | | - $method = 'handle'.Str::studly(str_replace('.', '_', $payload['event'])); |
39 | | - |
40 | | - WebhookReceived::dispatch($payload); |
41 | | - |
42 | | - if (method_exists($this, $method)) { |
43 | | - $response = $this->{$method}($payload); |
44 | | - |
45 | | - WebhookHandled::dispatch($payload); |
46 | | - |
47 | | - return $response; |
48 | | - } |
49 | | - |
50 | | - return $this->missingMethod(); |
51 | | - } |
52 | | - |
53 | 9 | /** |
54 | 10 | * Handle disabled customer subscription. |
55 | 11 | * |
@@ -138,26 +94,4 @@ protected function getUserByPaystackId(string $paystackId) |
138 | 94 | { |
139 | 95 | return PaystackSubscription::findBillable($paystackId); |
140 | 96 | } |
141 | | - |
142 | | - /** |
143 | | - * Handle successful calls on the controller. |
144 | | - * |
145 | | - * @param array $parameters |
146 | | - * @return \Symfony\Component\HttpFoundation\Response |
147 | | - */ |
148 | | - protected function successMethod($parameters = []) |
149 | | - { |
150 | | - return new Response('Webhook Handled', 200); |
151 | | - } |
152 | | - |
153 | | - /** |
154 | | - * Handle calls to missing methods on the controller. |
155 | | - * |
156 | | - * @param array $parameters |
157 | | - * @return \Symfony\Component\HttpFoundation\Response |
158 | | - */ |
159 | | - protected function missingMethod($parameters = []) |
160 | | - { |
161 | | - return new Response; |
162 | | - } |
163 | 97 | } |
0 commit comments