PayplugController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ipnAction() 0 17 2
1
<?php
2
3
namespace Alcalyn\PayplugBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Alcalyn\PayplugBundle\Event\PayplugIPNEvent;
10
use Alcalyn\PayplugBundle\Event\PayplugMalformedIPNEvent;
11
12
class PayplugController extends Controller
13
{
14
    /**
15
     * Script for Payplug IPN
16
     * 
17
     * @Route(
18
     *      "payplug_ipn",
19
     *      name = "payplug_ipn",
20
     *      requirements = {
21
     *          "_method" = "POST"
22
     *      }
23
     * )
24
     */
25
    public function ipnAction(Request $request)
26
    {
27
        $ipnService = $this->get('payplug.ipn');
28
        $eventDispatcher = $this->get('event_dispatcher');
29
        $isSignatureValid = $ipnService->verifyIPNRequest($request);
30
        
31
        if ($isSignatureValid) {
32
            $ipn = $ipnService->createIPNFromBody($request->getContent());
33
            $event = new PayplugIPNEvent($ipn);
34
            $eventDispatcher->dispatch(PayplugIPNEvent::PAYPLUG_IPN, $event);
35
        } else {
36
            $event = new PayplugMalformedIPNEvent($request);
37
            $eventDispatcher->dispatch(PayplugMalformedIPNEvent::PAYPLUG_IPN_MALFORMED, $event);
38
        }
39
        
40
        return new Response();
41
    }
42
}
43