|
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\Payone\Controller; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\PayoneCancelRedirectTransfer; |
|
|
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\PayoneGetFileTransfer; |
|
|
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\PayoneGetInvoiceTransfer; |
|
|
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\PayoneTransactionStatusUpdateTransfer; |
|
|
|
|
|
|
14
|
|
|
use Spryker\Yves\Kernel\Controller\AbstractController; |
|
15
|
|
|
use SprykerEco\Yves\Payone\Plugin\Provider\PayoneControllerProvider; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @method \SprykerEco\Client\Payone\PayoneClientInterface getClient() |
|
22
|
|
|
* @method \SprykerEco\Yves\Payone\PayoneFactory getFactory() |
|
23
|
|
|
*/ |
|
24
|
|
|
class IndexController extends AbstractController |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @uses \SprykerShop\Yves\CheckoutPage\Plugin\Router\CheckoutPageRouteProviderPlugin::CHECKOUT_SUCCESS |
|
28
|
|
|
*/ |
|
29
|
|
|
protected const ROUTE_CHECKOUT_SUCCESS = 'checkout-success'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @uses \SprykerShop\Yves\CheckoutPage\Plugin\Router\CheckoutPageRouteProviderPlugin::CHECKOUT_ERROR |
|
33
|
|
|
*/ |
|
34
|
|
|
protected const ROUTE_CHECKOUT_ERROR = 'checkout-error'; |
|
35
|
|
|
|
|
36
|
|
|
protected const REQUEST_PARAM_ORDER_REFERENCE = 'orderReference'; |
|
37
|
|
|
|
|
38
|
|
|
protected const GLOSSARY_KEY_CHECKOUT_ERROR = 'checkout.step.error.text'; |
|
39
|
|
|
protected const GLOSSARY_KEY_PAYMENT_ERROR = 'payone.payment.error'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
43
|
|
|
* |
|
44
|
|
|
* @return \Symfony\Component\HttpFoundation\StreamedResponse |
|
45
|
|
|
*/ |
|
46
|
|
|
public function indexAction(Request $request) |
|
47
|
|
|
{ |
|
48
|
|
|
$statusUpdateTransfer = new PayoneTransactionStatusUpdateTransfer(); |
|
49
|
|
|
$statusUpdateTransfer->fromArray($request->request->all(), true); |
|
50
|
|
|
|
|
51
|
|
|
$response = $this->getClient()->updateStatus($statusUpdateTransfer)->getResponse(); |
|
52
|
|
|
|
|
53
|
|
|
$callback = function () use ($response) { |
|
54
|
|
|
echo $response; |
|
55
|
|
|
}; |
|
56
|
|
|
|
|
57
|
|
|
return $this->streamedResponse($callback); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
62
|
|
|
* |
|
63
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
|
64
|
|
|
*/ |
|
65
|
|
|
public function paymentSuccessAction(Request $request): RedirectResponse |
|
66
|
|
|
{ |
|
67
|
|
|
$orderReference = $request->query->get(static::REQUEST_PARAM_ORDER_REFERENCE); |
|
68
|
|
|
$quoteTransfer = $this->getFactory()->getCartClient()->getQuote(); |
|
69
|
|
|
|
|
70
|
|
|
if (!$quoteTransfer->getOrderReference() || $quoteTransfer->getOrderReference() !== $orderReference) { |
|
71
|
|
|
$this->addErrorMessage(static::GLOSSARY_KEY_CHECKOUT_ERROR); |
|
72
|
|
|
|
|
73
|
|
|
return $this->redirectResponseInternal(static::ROUTE_CHECKOUT_ERROR); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $this->redirectResponseInternal(static::ROUTE_CHECKOUT_SUCCESS); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
81
|
|
|
* |
|
82
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
|
83
|
|
|
*/ |
|
84
|
|
|
public function paymentFailureAction(Request $request): RedirectResponse |
|
85
|
|
|
{ |
|
86
|
|
|
$orderReference = $request->query->get(static::REQUEST_PARAM_ORDER_REFERENCE); |
|
87
|
|
|
$quoteTransfer = $this->getFactory()->getCartClient()->getQuote(); |
|
88
|
|
|
|
|
89
|
|
|
if (!$quoteTransfer->getOrderReference() || $quoteTransfer->getOrderReference() !== $orderReference) { |
|
90
|
|
|
$this->addErrorMessage(static::GLOSSARY_KEY_CHECKOUT_ERROR); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$this->addErrorMessage(static::GLOSSARY_KEY_PAYMENT_ERROR); |
|
94
|
|
|
|
|
95
|
|
|
return $this->redirectResponseInternal(static::ROUTE_CHECKOUT_ERROR); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
100
|
|
|
* |
|
101
|
|
|
* @return \Symfony\Component\HttpFoundation\StreamedResponse |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getFileAction(Request $request) |
|
104
|
|
|
{ |
|
105
|
|
|
$customerClient = $this->getFactory()->getCustomerClient(); |
|
106
|
|
|
$customerTransfer = $customerClient->getCustomer(); |
|
107
|
|
|
|
|
108
|
|
|
if (!$customerTransfer) { |
|
109
|
|
|
return $this->redirectResponseInternal(PayoneControllerProvider::ROUTE_LOGIN); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$getFileTransfer = new PayoneGetFileTransfer(); |
|
113
|
|
|
$getFileTransfer->setReference($request->query->get('id')); |
|
114
|
|
|
$getFileTransfer->setCustomerId($customerTransfer->getIdCustomer()); |
|
115
|
|
|
|
|
116
|
|
|
$response = $this->getClient()->getFile($getFileTransfer); |
|
117
|
|
|
|
|
118
|
|
|
if ($response->getStatus() === 'ERROR') { |
|
119
|
|
|
return $this->viewResponse(['errormessage' => $response->getCustomerErrorMessage()]); |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$callback = function () use ($response) { |
|
123
|
|
|
echo base64_decode($response->getRawResponse()); |
|
124
|
|
|
}; |
|
125
|
|
|
|
|
126
|
|
|
return $this->streamedResponse($callback, 200, ["Content-type" => "application/pdf"]); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
131
|
|
|
* |
|
132
|
|
|
* @return \Symfony\Component\HttpFoundation\StreamedResponse |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getInvoiceAction(Request $request) |
|
135
|
|
|
{ |
|
136
|
|
|
$customerClient = $this->getFactory()->getCustomerClient(); |
|
137
|
|
|
$customerTransfer = $customerClient->getCustomer(); |
|
138
|
|
|
|
|
139
|
|
|
if (!$customerTransfer) { |
|
140
|
|
|
return $this->redirectResponseInternal(PayoneControllerProvider::ROUTE_LOGIN); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
$getInvoiceTransfer = new PayoneGetInvoiceTransfer(); |
|
144
|
|
|
$getInvoiceTransfer->setReference($request->query->get('id')); |
|
145
|
|
|
$getInvoiceTransfer->setCustomerId($customerTransfer->getIdCustomer()); |
|
146
|
|
|
|
|
147
|
|
|
$response = $this->getClient()->getInvoice($getInvoiceTransfer); |
|
148
|
|
|
|
|
149
|
|
|
if ($response->getStatus() === 'ERROR') { |
|
150
|
|
|
return $this->viewResponse(['errormessage' => $response->getInternalErrorMessage()]); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
$callback = function () use ($response) { |
|
154
|
|
|
echo base64_decode($response->getRawResponse()); |
|
155
|
|
|
}; |
|
156
|
|
|
|
|
157
|
|
|
return $this->streamedResponse($callback, 200, ["Content-type" => "application/pdf"]); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
162
|
|
|
* |
|
163
|
|
|
* @return \Symfony\Component\HttpFoundation\StreamedResponse |
|
164
|
|
|
*/ |
|
165
|
|
|
public function getSecurityInvoiceAction(Request $request) |
|
166
|
|
|
{ |
|
167
|
|
|
$customerClient = $this->getFactory()->getCustomerClient(); |
|
168
|
|
|
$customerTransfer = $customerClient->getCustomer(); |
|
169
|
|
|
|
|
170
|
|
|
if (!$customerTransfer) { |
|
171
|
|
|
return $this->redirectResponseInternal(PayoneControllerProvider::ROUTE_LOGIN); |
|
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
$getInvoiceTransfer = new PayoneGetInvoiceTransfer(); |
|
175
|
|
|
$getInvoiceTransfer->setReference($request->query->get('id')); |
|
176
|
|
|
$getInvoiceTransfer->setCustomerId($customerTransfer->getIdCustomer()); |
|
177
|
|
|
|
|
178
|
|
|
$response = $this->getClient()->getInvoice($getInvoiceTransfer); |
|
179
|
|
|
|
|
180
|
|
|
if ($response->getStatus() === 'ERROR') { |
|
181
|
|
|
return $this->viewResponse(['errormessage' => $response->getInternalErrorMessage()]); |
|
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
$callback = function () use ($response) { |
|
185
|
|
|
echo base64_decode($response->getRawResponse()); |
|
186
|
|
|
}; |
|
187
|
|
|
|
|
188
|
|
|
return $this->streamedResponse($callback, 200, ["Content-type" => "application/pdf"]); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
193
|
|
|
* |
|
194
|
|
|
* @return \Symfony\Component\HttpFoundation\StreamedResponse |
|
195
|
|
|
*/ |
|
196
|
|
|
public function cancelRedirectAction(Request $request) |
|
197
|
|
|
{ |
|
198
|
|
|
$orderReference = $request->query->get('orderReference'); |
|
199
|
|
|
$urlHmac = $request->query->get('sig'); |
|
200
|
|
|
|
|
201
|
|
|
if ($orderReference) { |
|
202
|
|
|
$cancelRedirectTransfer = new PayoneCancelRedirectTransfer(); |
|
203
|
|
|
$cancelRedirectTransfer->setOrderReference($orderReference); |
|
204
|
|
|
$cancelRedirectTransfer->setUrlHmac($urlHmac); |
|
205
|
|
|
|
|
206
|
|
|
$response = $this->getClient()->cancelRedirect($cancelRedirectTransfer); |
|
|
|
|
|
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
|
210
|
|
|
$quoteTransfer->setOrderReference(null); |
|
211
|
|
|
$this->getFactory()->getQuoteClient()->setQuote($quoteTransfer); |
|
212
|
|
|
|
|
213
|
|
|
return $this->redirectResponseInternal(PayoneControllerProvider::CHECKOUT_PAYMENT); |
|
|
|
|
|
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param callable|null $callback |
|
218
|
|
|
* @param int $status |
|
219
|
|
|
* @param array $headers |
|
220
|
|
|
* |
|
221
|
|
|
* @return \Symfony\Component\HttpFoundation\StreamedResponse |
|
222
|
|
|
*/ |
|
223
|
|
|
protected function streamedResponse($callback = null, $status = 200, $headers = []) |
|
224
|
|
|
{ |
|
225
|
|
|
$streamedResponse = new StreamedResponse($callback, $status, $headers); |
|
226
|
|
|
$streamedResponse->send(); |
|
227
|
|
|
|
|
228
|
|
|
return $streamedResponse; |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
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