|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Eres\SyliusIyzicoPlugin\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Eres\SyliusIyzicoPlugin\Event\PaymentEvent; |
|
8
|
|
|
use FOS\RestBundle\View\View; |
|
9
|
|
|
use Payum\Core\Payum; |
|
10
|
|
|
use Payum\Core\Request\Generic; |
|
11
|
|
|
use Payum\Core\Request\GetStatusInterface; |
|
12
|
|
|
use Payum\Core\Security\HttpRequestVerifierInterface; |
|
13
|
|
|
use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; |
|
14
|
|
|
use Sylius\Bundle\PayumBundle\Factory\ResolveNextRouteFactoryInterface; |
|
15
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface; |
|
16
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\ViewHandlerInterface; |
|
17
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
18
|
|
|
use Sylius\Component\Order\Repository\OrderRepositoryInterface; |
|
19
|
|
|
use Sylius\Component\Resource\Metadata\MetadataInterface; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; |
|
23
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
24
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
25
|
|
|
|
|
26
|
|
|
class PayumController |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var Payum */ |
|
29
|
|
|
private $payum; |
|
30
|
|
|
|
|
31
|
|
|
/** @var OrderRepositoryInterface */ |
|
32
|
|
|
private $orderRepository; |
|
33
|
|
|
|
|
34
|
|
|
/** @var MetadataInterface */ |
|
35
|
|
|
private $orderMetadata; |
|
36
|
|
|
|
|
37
|
|
|
/** @var RequestConfigurationFactoryInterface */ |
|
38
|
|
|
private $requestConfigurationFactory; |
|
39
|
|
|
|
|
40
|
|
|
/** @var ViewHandlerInterface */ |
|
41
|
|
|
private $viewHandler; |
|
42
|
|
|
|
|
43
|
|
|
/** @var RouterInterface */ |
|
44
|
|
|
private $router; |
|
45
|
|
|
|
|
46
|
|
|
/** @var GetStatusFactoryInterface */ |
|
47
|
|
|
private $getStatusRequestFactory; |
|
48
|
|
|
|
|
49
|
|
|
/** @var ResolveNextRouteFactoryInterface */ |
|
50
|
|
|
private $resolveNextRouteRequestFactory; |
|
51
|
|
|
|
|
52
|
|
|
/** @var EventDispatcherInterface */ |
|
53
|
|
|
private $eventDispatcher; |
|
54
|
|
|
|
|
55
|
|
|
public function __construct( |
|
56
|
|
|
Payum $payum, |
|
57
|
|
|
OrderRepositoryInterface $orderRepository, |
|
58
|
|
|
MetadataInterface $orderMetadata, |
|
59
|
|
|
RequestConfigurationFactoryInterface $requestConfigurationFactory, |
|
60
|
|
|
ViewHandlerInterface $viewHandler, |
|
61
|
|
|
RouterInterface $router, |
|
62
|
|
|
GetStatusFactoryInterface $getStatusFactory, |
|
63
|
|
|
ResolveNextRouteFactoryInterface $resolveNextRouteFactory, |
|
64
|
|
|
EventDispatcherInterface $eventDispatcher |
|
65
|
|
|
) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->payum = $payum; |
|
68
|
|
|
$this->orderRepository = $orderRepository; |
|
69
|
|
|
$this->orderMetadata = $orderMetadata; |
|
70
|
|
|
$this->requestConfigurationFactory = $requestConfigurationFactory; |
|
71
|
|
|
$this->viewHandler = $viewHandler; |
|
72
|
|
|
$this->router = $router; |
|
73
|
|
|
$this->getStatusRequestFactory = $getStatusFactory; |
|
74
|
|
|
$this->resolveNextRouteRequestFactory = $resolveNextRouteFactory; |
|
75
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function afterCaptureAction(Request $request): Response |
|
79
|
|
|
{ |
|
80
|
|
|
$configuration = $this->requestConfigurationFactory->create($this->orderMetadata, $request); |
|
81
|
|
|
|
|
82
|
|
|
$token = $this->getHttpRequestVerifier()->verify($request); |
|
83
|
|
|
|
|
84
|
|
|
/** @var Generic|GetStatusInterface $status */ |
|
85
|
|
|
$status = $this->getStatusRequestFactory->createNewWithModel($token); |
|
86
|
|
|
$this->payum->getGateway($token->getGatewayName())->execute($status); |
|
87
|
|
|
|
|
88
|
|
|
$resolveNextRoute = $this->resolveNextRouteRequestFactory->createNewWithModel($status->getFirstModel()); |
|
|
|
|
|
|
89
|
|
|
$this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute); |
|
90
|
|
|
|
|
91
|
|
|
$this->getHttpRequestVerifier()->invalidate($token); |
|
92
|
|
|
|
|
93
|
|
|
if (PaymentInterface::STATE_NEW !== $status->getValue()) { |
|
94
|
|
|
|
|
95
|
|
|
$model = $status->getModel(); |
|
96
|
|
|
|
|
97
|
|
|
/** @var FlashBagInterface $flashBag */ |
|
98
|
|
|
$flashBag = $request->getSession()->getBag('flashes'); |
|
99
|
|
|
|
|
100
|
|
|
if (isset($model['iyzico_error_message']) && $model['iyzico_error_message']) { |
|
101
|
|
|
$flashBagMessage = $model['iyzico_error_message']; |
|
102
|
|
|
} else { |
|
103
|
|
|
$flashBagMessage = sprintf('sylius.payment.%s', $status->getValue()); |
|
104
|
|
|
} |
|
105
|
|
|
$flashBag->add('info', $flashBagMessage); |
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$paymentEvent = new PaymentEvent(); |
|
110
|
|
|
$paymentEvent->setPayment($status->getFirstModel()); |
|
111
|
|
|
$this->eventDispatcher->dispatch('eres_sylius_iyzico_plugin.payment.post', $paymentEvent); |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
return $this->viewHandler->handle( |
|
114
|
|
|
$configuration, |
|
115
|
|
|
View::createRouteRedirect($resolveNextRoute->getRouteName(), $resolveNextRoute->getRouteParameters()) |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
private function getHttpRequestVerifier(): HttpRequestVerifierInterface |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->payum->getHttpRequestVerifier(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.