Skip to content

Commit fb68b69

Browse files
committed
webhooks update
1 parent 6a1dfcf commit fb68b69

File tree

7 files changed

+3
-285
lines changed

7 files changed

+3
-285
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"require": {
2323
"php": "^7.4",
2424
"ext-json": "^7.4",
25+
"digikraaft/laravel-paystack-webhooks": "^1.0",
2526
"digikraaft/paystack-php": "^1.0",
2627
"dompdf/dompdf": "^0.8.5",
2728
"guzzlehttp/guzzle": "^6.5",

src/Events/WebhookHandled.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Events/WebhookReceived.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Http/Controllers/WebhookController.php

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,11 @@
11
<?php
2-
3-
42
namespace Digikraaft\PaystackSubscription\Http\Controllers;
53

6-
use Digikraaft\PaystackSubscription\Events\WebhookHandled;
7-
use Digikraaft\PaystackSubscription\Events\WebhookReceived;
8-
use Digikraaft\PaystackSubscription\Http\Middleware\VerifyWebhookSignature;
94
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;
146

15-
class WebhookController extends Controller
7+
class WebhookController extends WebhooksController
168
{
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-
539
/**
5410
* Handle disabled customer subscription.
5511
*
@@ -138,26 +94,4 @@ protected function getUserByPaystackId(string $paystackId)
13894
{
13995
return PaystackSubscription::findBillable($paystackId);
14096
}
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-
}
16397
}

src/Http/Middleware/VerifyWebhookSignature.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/Feature/VerifyWebhookSignatureTest.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/Unit/WebhookControllerTest.php

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)