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