Failed Conditions
Pull Request — master (#54)
by Rafael
14:04 queued 06:57
created

PaymentsController::handleChargeDisputeCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
The trait Gewaer\Traits\WebhookHandlersTrait requires the property $subscriptions which is not provided by Gewaer\Api\Controllers\PaymentsController.
Loading history...
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