1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\Computop\Controller; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\ComputopApiResponseHeaderTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\ComputopNotificationTransfer; |
|
|
|
|
12
|
|
|
use Spryker\Shared\Config\Config; |
13
|
|
|
use Spryker\Yves\Kernel\Controller\AbstractController; |
14
|
|
|
use SprykerEco\Shared\Computop\ComputopConfig; |
15
|
|
|
use SprykerEco\Shared\Computop\Config\ComputopApiConfig; |
16
|
|
|
use SprykerEco\Shared\ComputopApi\ComputopApiConstants; |
17
|
|
|
use SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface; |
18
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @method \SprykerEco\Yves\Computop\ComputopFactory getFactory() |
24
|
|
|
* @method \SprykerEco\Client\Computop\ComputopClientInterface getClient() |
25
|
|
|
*/ |
26
|
|
|
class CallbackController extends AbstractController |
27
|
|
|
{ |
28
|
|
|
public const MESSAGE_PAYMENT_SUCCESS = 'Your order has been placed successfully! Thank you for shopping with us!'; |
29
|
|
|
|
30
|
|
|
public const MESSAGE_LOG_OUT_ERROR = 'Please login and try again.'; |
31
|
|
|
|
32
|
|
|
public const MESSAGE_RESPONSE_ERROR = 'Error: %s ( %s )'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
36
|
|
|
* |
37
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
38
|
|
|
*/ |
39
|
|
|
public function successCreditCardAction(Request $request) |
40
|
|
|
{ |
41
|
|
|
return $this->executeSuccessPostPlaceAction( |
42
|
|
|
$this->getFactory()->createCreditCardPaymentHandler(), |
43
|
|
|
$request->request->all() |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
49
|
|
|
* |
50
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
51
|
|
|
*/ |
52
|
|
|
public function successPayNowAction(Request $request) |
53
|
|
|
{ |
54
|
|
|
return $this->executeSuccessPostPlaceAction( |
55
|
|
|
$this->getFactory()->createPayNowPaymentHandler(), |
56
|
|
|
$request->request->all() |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
62
|
|
|
* |
63
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
64
|
|
|
*/ |
65
|
|
|
public function successPayPalAction(Request $request) |
66
|
|
|
{ |
67
|
|
|
return $this->executeSuccessPostPlaceAction( |
68
|
|
|
$this->getFactory()->createPayPalPaymentHandler(), |
69
|
|
|
$request->query->all() |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
75
|
|
|
* |
76
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
77
|
|
|
*/ |
78
|
|
|
public function successDirectDebitAction(Request $request) |
79
|
|
|
{ |
80
|
|
|
return $this->executeSuccessPostPlaceAction( |
81
|
|
|
$this->getFactory()->createDirectDebitPaymentHandler(), |
82
|
|
|
$request->query->all() |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
88
|
|
|
* |
89
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
90
|
|
|
*/ |
91
|
|
|
public function successEasyCreditAction(Request $request) |
92
|
|
|
{ |
93
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
94
|
|
|
$quoteTransfer = $this->getFactory() |
95
|
|
|
->createEasyCreditPaymentHandler() |
96
|
|
|
->handle($quoteTransfer, $request->query->all()); |
97
|
|
|
|
98
|
|
|
$this->getFactory()->getQuoteClient()->setQuote($quoteTransfer); |
99
|
|
|
$statusResponse = $quoteTransfer->getPayment()->getComputopEasyCredit()->getEasyCreditStatusResponse(); |
100
|
|
|
|
101
|
|
|
if (!$statusResponse->getHeader()->getIsSuccess()) { |
102
|
|
|
$this->addErrorMessage($statusResponse->getErrorText()); |
103
|
|
|
|
104
|
|
|
return $this->redirectResponseInternal($this->getFactory()->getComputopConfig()->getCallbackFailureRedirectPath()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $this->redirectResponseInternal($this->getFactory()->getComputopConfig()->getEasyCreditSuccessAction()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
112
|
|
|
* |
113
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
114
|
|
|
*/ |
115
|
|
|
public function successPayuCeeSingleAction(Request $request): RedirectResponse |
116
|
|
|
{ |
117
|
|
|
return $this->executeSuccessPostPlaceAction( |
118
|
|
|
$this->getFactory()->createPayuCeeSinglePaymentHandler(), |
119
|
|
|
$request->query->all() |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
125
|
|
|
* |
126
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
127
|
|
|
*/ |
128
|
|
|
public function successPaydirektAction(Request $request) |
129
|
|
|
{ |
130
|
|
|
return $this->executeSuccessPostPlaceAction( |
131
|
|
|
$this->getFactory()->createPaydirektPaymentHandler(), |
132
|
|
|
$request->query->all() |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
138
|
|
|
* |
139
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
140
|
|
|
*/ |
141
|
|
|
public function successSofortAction(Request $request) |
142
|
|
|
{ |
143
|
|
|
return $this->executeSuccessPostPlaceAction( |
144
|
|
|
$this->getFactory()->createSofortPaymentHandler(), |
145
|
|
|
$request->query->all() |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
151
|
|
|
* |
152
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
153
|
|
|
*/ |
154
|
|
|
public function successIdealAction(Request $request) |
155
|
|
|
{ |
156
|
|
|
return $this->executeSuccessPostPlaceAction( |
157
|
|
|
$this->getFactory()->createIdealPaymentHandler(), |
158
|
|
|
$request->query->all() |
159
|
|
|
); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface $handler |
164
|
|
|
* @param array $responseArray |
165
|
|
|
* |
166
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
167
|
|
|
*/ |
168
|
|
|
protected function executeSuccessPostPlaceAction(ComputopPrePostPaymentHandlerInterface $handler, array $responseArray) |
169
|
|
|
{ |
170
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
171
|
|
|
$quoteTransfer = $handler->handle($quoteTransfer, $responseArray); |
172
|
|
|
|
173
|
|
|
if (!$quoteTransfer->getCustomer()) { |
174
|
|
|
$this->addSuccessMessage(static::MESSAGE_PAYMENT_SUCCESS); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $this->redirectResponseInternal( |
178
|
|
|
$this->getFactory()->getComputopConfig()->getCallbackSuccessCaptureRedirectPath() |
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
184
|
|
|
* |
185
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
186
|
|
|
*/ |
187
|
|
|
public function failureAction(Request $request) |
188
|
|
|
{ |
189
|
|
|
$requestParameters = $request->query->all(); |
190
|
|
|
|
191
|
|
|
if ($request->isMethod(Request::METHOD_POST)) { |
192
|
|
|
$requestParameters = $request->request->all(); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
$computopApiService = $this->getFactory()->getComputopApiService(); |
196
|
|
|
|
197
|
|
|
$decryptedArray = $computopApiService |
198
|
|
|
->decryptResponseHeader($requestParameters, Config::get(ComputopApiConstants::BLOWFISH_PASSWORD)); |
199
|
|
|
|
200
|
|
|
$responseHeaderTransfer = $computopApiService |
201
|
|
|
->extractResponseHeader($decryptedArray, ComputopConfig::INIT_METHOD); |
202
|
|
|
|
203
|
|
|
$this->addErrorMessage($this->getErrorMessageText($responseHeaderTransfer)); |
204
|
|
|
|
205
|
|
|
$this->resetQuoteAfterFail(); |
206
|
|
|
|
207
|
|
|
return $this->redirectResponseInternal($this->getFactory()->getComputopConfig()->getCallbackFailureRedirectPath()); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
212
|
|
|
* |
213
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
214
|
|
|
*/ |
215
|
|
|
public function notifyAction(Request $request) |
216
|
|
|
{ |
217
|
|
|
$decryptedArray = $this->getFactory() |
218
|
|
|
->getComputopApiService() |
219
|
|
|
->decryptResponseHeader($request->request->all(), Config::get(ComputopApiConstants::BLOWFISH_PASSWORD)); |
220
|
|
|
|
221
|
|
|
$responseHeaderTransfer = $this->getFactory() |
222
|
|
|
->getComputopApiService() |
223
|
|
|
->extractResponseHeader($decryptedArray, ''); |
224
|
|
|
|
225
|
|
|
$computopNotificationTransfer = (new ComputopNotificationTransfer()) |
226
|
|
|
->fromArray($responseHeaderTransfer->toArray(), true) |
227
|
|
|
->setType($decryptedArray[ComputopApiConfig::NOTIFICATION_PARAMETER_PAYMENT_TYPE] ?? ''); |
228
|
|
|
|
229
|
|
|
$computopNotificationTransfer = $this->getClient()->processNotification($computopNotificationTransfer); |
230
|
|
|
|
231
|
|
|
if ($computopNotificationTransfer->getIsProcessed()) { |
232
|
|
|
return new Response(); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
return new Response('', Response::HTTP_NOT_ACCEPTABLE); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param \Generated\Shared\Transfer\ComputopApiResponseHeaderTransfer $responseHeaderTransfer |
240
|
|
|
* |
241
|
|
|
* @return string |
242
|
|
|
*/ |
243
|
|
|
protected function getErrorMessageText(ComputopApiResponseHeaderTransfer $responseHeaderTransfer) |
244
|
|
|
{ |
245
|
|
|
$errorText = $responseHeaderTransfer->getDescription(); |
246
|
|
|
$errorCode = $responseHeaderTransfer->getCode(); |
247
|
|
|
$errorMessageText = sprintf(static::MESSAGE_RESPONSE_ERROR, $errorText, $errorCode); |
248
|
|
|
|
249
|
|
|
return $errorMessageText; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @return void |
254
|
|
|
*/ |
255
|
|
|
protected function resetQuoteAfterFail(): void |
256
|
|
|
{ |
257
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
258
|
|
|
$quoteTransfer |
259
|
|
|
->setIsOrderPlacedSuccessfully(null) |
260
|
|
|
->setOrderReference(null) |
261
|
|
|
->setPayment(null); |
262
|
|
|
|
263
|
|
|
$this->getFactory()->getQuoteClient()->setQuote($quoteTransfer); |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths