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) |
|
|
|
|
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
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.