PaymentController::confirmAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\OrderBundle\Controller\Front;
14
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use WellCommerce\Bundle\CoreBundle\Controller\Front\AbstractFrontController;
18
use WellCommerce\Bundle\OrderBundle\Entity\Payment;
19
use WellCommerce\Bundle\OrderBundle\Manager\PaymentManagerInterface;
20
21
/**
22
 * Class PaymentController
23
 *
24
 * @author  Adam Piotrowski <[email protected]>
25
 */
26
class PaymentController extends AbstractFrontController
27
{
28
    /**
29
     * @var PaymentManagerInterface
30
     */
31
    protected $manager;
32
    
33
    public function initializeAction(Payment $payment)
34
    {
35
        $order     = $payment->getOrder();
36
        $processor = $this->manager->getPaymentProcessor($order);
37
        
38
        if (!$payment->isInProgress()) {
39
            $processor->getGateway()->initializePayment($payment);
40
            $this->manager->updatePaymentState($payment);
41
        }
42
        
43
        if ($payment->isInProgress()) {
44
            return new Response($this->renderView($processor->getConfigurator()->getInitializeTemplateName(), [
45
                'payment' => $payment,
46
            ]));
47
        }
48
        
49
        return $this->redirectToAction('cancel', [
50
            'token' => $payment->getToken(),
51
        ]);
52
    }
53
    
54
    public function confirmAction(Payment $payment, Request $request)
55
    {
56
        if (!$payment->isApproved()) {
57
            $order     = $payment->getOrder();
58
            $processor = $this->manager->getPaymentProcessor($order);
59
            $processor->getGateway()->confirmPayment($payment, $request);
60
            $this->manager->updatePaymentState($payment);
61
        }
62
        
63
        return $this->displayTemplate('confirm', [
64
            'payment' => $payment,
65
        ]);
66
    }
67
    
68
    public function cancelAction(Payment $payment, Request $request)
69
    {
70
        if (!$payment->isCancelled()) {
71
            $order     = $payment->getOrder();
72
            $processor = $this->manager->getPaymentProcessor($order);
73
            $processor->getGateway()->cancelPayment($payment, $request);
74
            $this->manager->updatePaymentState($payment);
75
        }
76
        
77
        return $this->displayTemplate('cancel', [
78
            'payment' => $payment,
79
        ]);
80
    }
81
    
82
    public function executeAction(Payment $payment, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $payment is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
    {
84
    }
85
    
86
    public function notifyAction(Payment $payment, Request $request)
87
    {
88
        if (!$payment->isApproved()) {
89
            $order     = $payment->getOrder();
90
            $processor = $this->manager->getPaymentProcessor($order);
91
            $processor->getGateway()->notifyPayment($payment, $request);
92
            $this->manager->updatePaymentState($payment);
93
        }
94
        
95
        return new Response('OK');
96
    }
97
}
98