1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Gewaer\Api\Controllers; |
||
6 | |||
7 | use Phalcon\Http\Response; |
||
8 | use Gewaer\Exception\NotFoundHttpException; |
||
9 | use Gewaer\Traits\EmailTrait; |
||
10 | use Gewaer\Traits\WebhookHandlersTrait; |
||
11 | |||
12 | /** |
||
13 | * Class PaymentsController |
||
14 | * |
||
15 | * Class to handle payment webhook from our cashier library |
||
16 | * |
||
17 | * @package Gewaer\Api\Controllers |
||
18 | * @property Log $log |
||
19 | * |
||
20 | */ |
||
21 | class PaymentsController extends BaseController |
||
22 | { |
||
23 | /** |
||
24 | * Email Trait |
||
25 | */ |
||
26 | use EmailTrait; |
||
27 | |||
28 | use WebhookHandlersTrait; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
29 | |||
30 | /** |
||
31 | * Handle stripe webhoook calls |
||
32 | * |
||
33 | * @return Response |
||
34 | */ |
||
35 | 4 | public function handleWebhook(): Response |
|
36 | { |
||
37 | //we cant processs if we dont find the stripe header |
||
38 | 4 | if (!defined('API_TESTS')) { |
|
39 | if (!$this->request->hasHeader('Stripe-Signature')) { |
||
40 | throw new NotFoundHttpException('Route not found for this call'); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | 4 | $request = $this->request->getPost(); |
|
45 | |||
46 | 4 | if (empty($request)) { |
|
47 | $request = $this->request->getJsonRawBody(true); |
||
48 | } |
||
49 | 4 | $type = str_replace('.', '', ucwords(str_replace('_', '', $request['type']), '.')); |
|
50 | 4 | $method = 'handle' . $type; |
|
51 | |||
52 | 4 | $payloadContent = json_encode($request); |
|
53 | 4 | $this->log->info("Webhook Handler Method: {$method} \n"); |
|
54 | 4 | $this->log->info("Payload: {$payloadContent} \n"); |
|
55 | |||
56 | 4 | if (method_exists($this, $method)) { |
|
57 | 4 | return $this->{$method}($request); |
|
58 | } else { |
||
59 | return $this->response(['Missing Method to Handled']); |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 |