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
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
public const MESSAGE_PAYMENT_SUCCESS = 'Your order has been placed successfully! Thank you for shopping with us!'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
public const MESSAGE_LOG_OUT_ERROR = 'Please login and try again.'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
public const MESSAGE_RESPONSE_ERROR = 'Error: %s ( %s )'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
45
|
|
|
* |
46
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
47
|
|
|
*/ |
48
|
|
|
public function successCreditCardAction(Request $request) |
49
|
|
|
{ |
50
|
|
|
return $this->executeSuccessPostPlaceAction( |
51
|
|
|
$this->getFactory()->createCreditCardPaymentHandler(), |
52
|
|
|
$request->request->all() |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
58
|
|
|
* |
59
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
60
|
|
|
*/ |
61
|
|
|
public function successPayNowAction(Request $request) |
62
|
|
|
{ |
63
|
|
|
return $this->executeSuccessPostPlaceAction( |
64
|
|
|
$this->getFactory()->createPayNowPaymentHandler(), |
65
|
|
|
$request->request->all() |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
71
|
|
|
* |
72
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
73
|
|
|
*/ |
74
|
|
|
public function successPayPalAction(Request $request) |
75
|
|
|
{ |
76
|
|
|
return $this->executeSuccessPostPlaceAction( |
77
|
|
|
$this->getFactory()->createPayPalPaymentHandler(), |
78
|
|
|
$request->query->all() |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
84
|
|
|
* |
85
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
86
|
|
|
*/ |
87
|
|
|
public function successDirectDebitAction(Request $request) |
88
|
|
|
{ |
89
|
|
|
return $this->executeSuccessPostPlaceAction( |
90
|
|
|
$this->getFactory()->createDirectDebitPaymentHandler(), |
91
|
|
|
$request->query->all() |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
97
|
|
|
* |
98
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
99
|
|
|
*/ |
100
|
|
|
public function successEasyCreditAction(Request $request) |
101
|
|
|
{ |
102
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
103
|
|
|
$quoteTransfer = $this->getFactory() |
104
|
|
|
->createEasyCreditPaymentHandler() |
105
|
|
|
->handle($quoteTransfer, $request->query->all()); |
106
|
|
|
|
107
|
|
|
$this->getFactory()->getQuoteClient()->setQuote($quoteTransfer); |
108
|
|
|
$statusResponse = $quoteTransfer->getPayment()->getComputopEasyCredit()->getEasyCreditStatusResponse(); |
109
|
|
|
|
110
|
|
|
if (!$statusResponse->getHeader()->getIsSuccess()) { |
111
|
|
|
$this->addErrorMessage($statusResponse->getErrorText()); |
112
|
|
|
|
113
|
|
|
return $this->redirectResponseInternal($this->getFactory()->getComputopConfig()->getCallbackFailureRedirectPath()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $this->redirectResponseInternal($this->getFactory()->getComputopConfig()->getEasyCreditSuccessAction()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
121
|
|
|
* |
122
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
123
|
|
|
*/ |
124
|
|
|
public function successPayuCeeSingleAction(Request $request): RedirectResponse |
125
|
|
|
{ |
126
|
|
|
return $this->executeSuccessPostPlaceAction( |
127
|
|
|
$this->getFactory()->createPayuCeeSinglePaymentHandler(), |
128
|
|
|
$request->query->all() |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
134
|
|
|
* |
135
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
136
|
|
|
*/ |
137
|
|
|
public function successPaydirektAction(Request $request) |
138
|
|
|
{ |
139
|
|
|
return $this->executeSuccessPostPlaceAction( |
140
|
|
|
$this->getFactory()->createPaydirektPaymentHandler(), |
141
|
|
|
$request->query->all() |
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
147
|
|
|
* |
148
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
149
|
|
|
*/ |
150
|
|
|
public function successSofortAction(Request $request) |
151
|
|
|
{ |
152
|
|
|
return $this->executeSuccessPostPlaceAction( |
153
|
|
|
$this->getFactory()->createSofortPaymentHandler(), |
154
|
|
|
$request->query->all() |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
160
|
|
|
* |
161
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
162
|
|
|
*/ |
163
|
|
|
public function successIdealAction(Request $request) |
164
|
|
|
{ |
165
|
|
|
return $this->executeSuccessPostPlaceAction( |
166
|
|
|
$this->getFactory()->createIdealPaymentHandler(), |
167
|
|
|
$request->query->all() |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface $handler |
173
|
|
|
* @param array $responseArray |
174
|
|
|
* |
175
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
176
|
|
|
*/ |
177
|
|
|
protected function executeSuccessPostPlaceAction(ComputopPrePostPaymentHandlerInterface $handler, array $responseArray) |
178
|
|
|
{ |
179
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
180
|
|
|
$quoteTransfer = $handler->handle($quoteTransfer, $responseArray); |
181
|
|
|
|
182
|
|
|
if (!$quoteTransfer->getCustomer()) { |
183
|
|
|
$this->addSuccessMessage(static::MESSAGE_PAYMENT_SUCCESS); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
return $this->redirectResponseInternal( |
187
|
|
|
$this->getFactory()->getComputopConfig()->getCallbackSuccessCaptureRedirectPath() |
188
|
|
|
); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
193
|
|
|
* |
194
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
195
|
|
|
*/ |
196
|
|
|
public function failureAction(Request $request) |
197
|
|
|
{ |
198
|
|
|
$requestParameters = $request->query->all(); |
199
|
|
|
|
200
|
|
|
if ($request->isMethod(Request::METHOD_POST)) { |
201
|
|
|
$requestParameters = $request->request->all(); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
$computopApiService = $this->getFactory()->getComputopApiService(); |
205
|
|
|
|
206
|
|
|
$decryptedArray = $computopApiService |
207
|
|
|
->decryptResponseHeader($requestParameters, Config::get(ComputopApiConstants::BLOWFISH_PASSWORD)); |
208
|
|
|
|
209
|
|
|
$responseHeaderTransfer = $computopApiService |
210
|
|
|
->extractResponseHeader($decryptedArray, ComputopConfig::INIT_METHOD); |
211
|
|
|
|
212
|
|
|
$this->addErrorMessage($this->getErrorMessageText($responseHeaderTransfer)); |
213
|
|
|
|
214
|
|
|
$this->resetQuoteAfterFail(); |
215
|
|
|
|
216
|
|
|
return $this->redirectResponseInternal($this->getFactory()->getComputopConfig()->getCallbackFailureRedirectPath()); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
221
|
|
|
* |
222
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
223
|
|
|
*/ |
224
|
|
|
public function notifyAction(Request $request) |
225
|
|
|
{ |
226
|
|
|
$decryptedArray = $this->getFactory() |
227
|
|
|
->getComputopApiService() |
228
|
|
|
->decryptResponseHeader($request->request->all(), Config::get(ComputopApiConstants::BLOWFISH_PASSWORD)); |
229
|
|
|
|
230
|
|
|
$responseHeaderTransfer = $this->getFactory() |
231
|
|
|
->getComputopApiService() |
232
|
|
|
->extractResponseHeader($decryptedArray, ''); |
233
|
|
|
|
234
|
|
|
$computopNotificationTransfer = (new ComputopNotificationTransfer()) |
235
|
|
|
->fromArray($responseHeaderTransfer->toArray(), true) |
236
|
|
|
->setType($decryptedArray[ComputopApiConfig::NOTIFICATION_PARAMETER_PAYMENT_TYPE] ?? ''); |
237
|
|
|
|
238
|
|
|
$computopNotificationTransfer = $this->getClient()->processNotification($computopNotificationTransfer); |
239
|
|
|
|
240
|
|
|
if ($computopNotificationTransfer->getIsProcessed()) { |
241
|
|
|
return new Response(); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
return new Response('', Response::HTTP_NOT_ACCEPTABLE); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param \Generated\Shared\Transfer\ComputopApiResponseHeaderTransfer $responseHeaderTransfer |
249
|
|
|
* |
250
|
|
|
* @return string |
251
|
|
|
*/ |
252
|
|
|
protected function getErrorMessageText(ComputopApiResponseHeaderTransfer $responseHeaderTransfer) |
253
|
|
|
{ |
254
|
|
|
$errorText = $responseHeaderTransfer->getDescription(); |
255
|
|
|
$errorCode = $responseHeaderTransfer->getCode(); |
256
|
|
|
$errorMessageText = sprintf(static::MESSAGE_RESPONSE_ERROR, $errorText, $errorCode); |
257
|
|
|
|
258
|
|
|
return $errorMessageText; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @return void |
263
|
|
|
*/ |
264
|
|
|
protected function resetQuoteAfterFail(): void |
265
|
|
|
{ |
266
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
267
|
|
|
$quoteTransfer |
268
|
|
|
->setIsOrderPlacedSuccessfully(null) |
269
|
|
|
->setOrderReference(null) |
270
|
|
|
->setPayment(null); |
271
|
|
|
|
272
|
|
|
$this->getFactory()->getQuoteClient()->setQuote($quoteTransfer); |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
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