|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Payment; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentFinalizeException; |
|
6
|
|
|
use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; |
|
7
|
|
|
use Shopware\Core\Checkout\Payment\Exception\CapturePreparedPaymentException; |
|
8
|
|
|
use Shopware\Core\Checkout\Payment\Exception\CustomerCanceledAsyncPaymentException; |
|
9
|
|
|
use Shopware\Core\Checkout\Payment\Exception\InvalidOrderException; |
|
10
|
|
|
use Shopware\Core\Checkout\Payment\Exception\InvalidRefundTransitionException; |
|
11
|
|
|
use Shopware\Core\Checkout\Payment\Exception\InvalidTokenException; |
|
12
|
|
|
use Shopware\Core\Checkout\Payment\Exception\InvalidTransactionException; |
|
13
|
|
|
use Shopware\Core\Checkout\Payment\Exception\PluginPaymentMethodsDeleteRestrictionException; |
|
14
|
|
|
use Shopware\Core\Checkout\Payment\Exception\RefundException; |
|
15
|
|
|
use Shopware\Core\Checkout\Payment\Exception\SyncPaymentProcessException; |
|
16
|
|
|
use Shopware\Core\Checkout\Payment\Exception\TokenExpiredException; |
|
17
|
|
|
use Shopware\Core\Checkout\Payment\Exception\TokenInvalidatedException; |
|
18
|
|
|
use Shopware\Core\Checkout\Payment\Exception\UnknownPaymentMethodException; |
|
19
|
|
|
use Shopware\Core\Checkout\Payment\Exception\UnknownRefundException; |
|
20
|
|
|
use Shopware\Core\Checkout\Payment\Exception\UnknownRefundHandlerException; |
|
21
|
|
|
use Shopware\Core\Checkout\Payment\Exception\ValidatePreparedPaymentException; |
|
22
|
|
|
use Shopware\Core\Framework\Feature; |
|
23
|
|
|
use Shopware\Core\Framework\HttpException; |
|
24
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
25
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
26
|
|
|
|
|
27
|
|
|
#[Package('customer-order')] |
|
28
|
|
|
class PaymentException extends HttpException |
|
29
|
|
|
{ |
|
30
|
|
|
final public const PAYMENT_ASYNC_FINALIZE_INTERRUPTED = 'CHECKOUT__ASYNC_PAYMENT_FINALIZE_INTERRUPTED'; |
|
31
|
|
|
final public const PAYMENT_ASYNC_PROCESS_INTERRUPTED = 'CHECKOUT__ASYNC_PAYMENT_PROCESS_INTERRUPTED'; |
|
32
|
|
|
final public const PAYMENT_CAPTURE_PREPARED_ERROR = 'CHECKOUT__CAPTURE_PREPARED_PAYMENT_ERROR'; |
|
33
|
|
|
final public const PAYMENT_CUSTOMER_CANCELED_EXTERNAL = 'CHECKOUT__CUSTOMER_CANCELED_EXTERNAL_PAYMENT'; |
|
34
|
|
|
final public const PAYMENT_INVALID_ORDER_ID = 'CHECKOUT__INVALID_ORDER_ID'; |
|
35
|
|
|
final public const PAYMENT__REFUND_INVALID_TRANSITION_ERROR = 'CHECKOUT__REFUND_INVALID_TRANSITION_ERROR'; |
|
36
|
|
|
final public const PAYMENT_INVALID_TOKEN = 'CHECKOUT__INVALID_PAYMENT_TOKEN'; |
|
37
|
|
|
final public const PAYMENT_INVALID_TRANSACTION_ID = 'CHECKOUT__INVALID_TRANSACTION_ID'; |
|
38
|
|
|
|
|
39
|
|
|
final public const PAYMENT_PROCESS_ERROR = 'CHECKOUT__PAYMENT_ERROR'; |
|
40
|
|
|
final public const PAYMENT_PLUGIN_PAYMENT_METHOD_DELETE_RESTRICTION = 'CHECKOUT__PLUGIN_PAYMENT_METHOD_DELETE_RESTRICTION'; |
|
41
|
|
|
final public const PAYMENT_REFUND_PROCESS_INTERRUPTED = 'CHECKOUT__REFUND_PROCESS_INTERRUPTED'; |
|
42
|
|
|
final public const PAYMENT_REFUND_PROCESS_ERROR = 'CHECKOUT__REFUND_PROCESS_ERROR'; |
|
43
|
|
|
final public const PAYMENT_SYNC_PROCESS_INTERRUPTED = 'CHECKOUT__SYNC_PAYMENT_PROCESS_INTERRUPTED'; |
|
44
|
|
|
final public const PAYMENT_TOKEN_EXPIRED = 'CHECKOUT__PAYMENT_TOKEN_EXPIRED'; |
|
45
|
|
|
final public const PAYMENT_TOKEN_INVALIDATED = 'CHECKOUT__PAYMENT_TOKEN_INVALIDATED'; |
|
46
|
|
|
final public const PAYMENT_UNKNOWN_PAYMENT_METHOD = 'CHECKOUT__UNKNOWN_PAYMENT_METHOD'; |
|
47
|
|
|
final public const PAYMENT_REFUND_UNKNOWN_ERROR = 'CHECKOUT__REFUND_UNKNOWN_ERROR'; |
|
48
|
|
|
final public const PAYMENT_REFUND_UNKNOWN_HANDLER_ERROR = 'CHECKOUT__REFUND_UNKNOWN_HANDLER_ERROR'; |
|
49
|
|
|
final public const PAYMENT_VALIDATE_PREPARED_ERROR = 'CHECKOUT__VALIDATE_PREPARED_PAYMENT_ERROR'; |
|
50
|
|
|
|
|
51
|
|
|
public static function asyncFinalizeInterrupted(string $orderTransactionId, string $errorMessage, ?\Throwable $e = null): self |
|
52
|
|
|
{ |
|
53
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
54
|
|
|
return new AsyncPaymentFinalizeException($orderTransactionId, $errorMessage, $e); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return new self( |
|
58
|
|
|
Response::HTTP_BAD_REQUEST, |
|
59
|
|
|
self::PAYMENT_ASYNC_FINALIZE_INTERRUPTED, |
|
60
|
|
|
'The asynchronous payment finalize was interrupted due to the following error:' . \PHP_EOL . '{{ errorMessage }}', |
|
61
|
|
|
[ |
|
62
|
|
|
'errorMessage' => $errorMessage, |
|
63
|
|
|
'orderTransactionId' => $orderTransactionId, |
|
64
|
|
|
], |
|
65
|
|
|
$e |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public static function asyncProcessInterrupted(string $orderTransactionId, string $errorMessage, ?\Throwable $e = null): self |
|
70
|
|
|
{ |
|
71
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
72
|
|
|
return new AsyncPaymentProcessException($orderTransactionId, $errorMessage, $e); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return new self( |
|
76
|
|
|
Response::HTTP_BAD_REQUEST, |
|
77
|
|
|
self::PAYMENT_ASYNC_PROCESS_INTERRUPTED, |
|
78
|
|
|
'The asynchronous payment process was interrupted due to the following error:' . \PHP_EOL . '{{ errorMessage }}', |
|
79
|
|
|
[ |
|
80
|
|
|
'errorMessage' => $errorMessage, |
|
81
|
|
|
'orderTransactionId' => $orderTransactionId, |
|
82
|
|
|
], |
|
83
|
|
|
$e |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public static function syncProcessInterrupted(string $orderTransactionId, string $errorMessage, ?\Throwable $e = null): self |
|
88
|
|
|
{ |
|
89
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
90
|
|
|
return new SyncPaymentProcessException($orderTransactionId, $errorMessage, $e); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return new self( |
|
94
|
|
|
Response::HTTP_BAD_REQUEST, |
|
95
|
|
|
self::PAYMENT_SYNC_PROCESS_INTERRUPTED, |
|
96
|
|
|
'The synchronous payment process was interrupted due to the following error:' . \PHP_EOL . '{{ errorMessage }}', |
|
97
|
|
|
[ |
|
98
|
|
|
'errorMessage' => $errorMessage, |
|
99
|
|
|
'orderTransactionId' => $orderTransactionId, |
|
100
|
|
|
], |
|
101
|
|
|
$e |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public static function capturePreparedException(string $orderTransactionId, string $errorMessage, ?\Throwable $e = null): self |
|
106
|
|
|
{ |
|
107
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
108
|
|
|
return new CapturePreparedPaymentException($orderTransactionId, $errorMessage, $e); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return new self( |
|
112
|
|
|
Response::HTTP_BAD_REQUEST, |
|
113
|
|
|
self::PAYMENT_CAPTURE_PREPARED_ERROR, |
|
114
|
|
|
'The capture process of the prepared payment was interrupted due to the following error:' . \PHP_EOL . '{{ errorMessage }}', |
|
115
|
|
|
[ |
|
116
|
|
|
'errorMessage' => $errorMessage, |
|
117
|
|
|
'orderTransactionId' => $orderTransactionId, |
|
118
|
|
|
], |
|
119
|
|
|
$e |
|
120
|
|
|
); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public static function customerCanceled(string $orderTransactionId, string $additionalInformation, ?\Throwable $e = null): self |
|
124
|
|
|
{ |
|
125
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
126
|
|
|
return new CustomerCanceledAsyncPaymentException($orderTransactionId, $additionalInformation, $e); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
return new self( |
|
130
|
|
|
Response::HTTP_BAD_REQUEST, |
|
131
|
|
|
self::PAYMENT_CUSTOMER_CANCELED_EXTERNAL, |
|
132
|
|
|
'The customer canceled the external payment process. {{ additionalInformation }}', |
|
133
|
|
|
[ |
|
134
|
|
|
'additionalInformation' => $additionalInformation, |
|
135
|
|
|
'orderTransactionId' => $orderTransactionId, |
|
136
|
|
|
], |
|
137
|
|
|
$e |
|
138
|
|
|
); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public static function invalidOrder(string $orderId, ?\Throwable $e = null): self |
|
142
|
|
|
{ |
|
143
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
144
|
|
|
return new InvalidOrderException($orderId, $e); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
return new self( |
|
148
|
|
|
Response::HTTP_NOT_FOUND, |
|
149
|
|
|
self::PAYMENT_INVALID_ORDER_ID, |
|
150
|
|
|
'The order with id {{ orderId }} is invalid or could not be found.', |
|
151
|
|
|
[ |
|
152
|
|
|
'orderId' => $orderId, |
|
153
|
|
|
], |
|
154
|
|
|
$e |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public static function refundInvalidTransition(string $refundId, string $stateName, ?\Throwable $e = null): self |
|
159
|
|
|
{ |
|
160
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
161
|
|
|
return new InvalidRefundTransitionException($refundId, $stateName, $e); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
return new self( |
|
165
|
|
|
Response::HTTP_BAD_REQUEST, |
|
166
|
|
|
self::PAYMENT__REFUND_INVALID_TRANSITION_ERROR, |
|
167
|
|
|
'The Refund process failed with following exception: Can not process refund with id {{ refundId }} as refund has state {{ stateName }}.', |
|
168
|
|
|
['refundId' => $refundId, 'stateName' => $stateName], |
|
169
|
|
|
$e |
|
170
|
|
|
); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public static function invalidToken(string $token, ?\Throwable $e = null): self |
|
174
|
|
|
{ |
|
175
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
176
|
|
|
return new InvalidTokenException($token, $e); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
return new self( |
|
180
|
|
|
Response::HTTP_BAD_REQUEST, |
|
181
|
|
|
self::PAYMENT_INVALID_TOKEN, |
|
182
|
|
|
'The provided token {{ token }} is invalid and the payment could not be processed.', |
|
183
|
|
|
['token' => $token], |
|
184
|
|
|
$e |
|
185
|
|
|
); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public static function invalidTransaction(string $transactionId, ?\Throwable $e = null): self |
|
189
|
|
|
{ |
|
190
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
191
|
|
|
return new InvalidTransactionException($transactionId, $e); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
return new self( |
|
195
|
|
|
Response::HTTP_BAD_REQUEST, |
|
196
|
|
|
self::PAYMENT_INVALID_TRANSACTION_ID, |
|
197
|
|
|
'The transaction with id {{ transactionId }} is invalid or could not be found.', |
|
198
|
|
|
['transactionId' => $transactionId], |
|
199
|
|
|
$e |
|
200
|
|
|
); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public static function pluginPaymentMethodDeleteRestriction(?\Throwable $e = null): self |
|
204
|
|
|
{ |
|
205
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
206
|
|
|
return new PluginPaymentMethodsDeleteRestrictionException($e); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
return new self( |
|
210
|
|
|
Response::HTTP_BAD_REQUEST, |
|
211
|
|
|
self::PAYMENT_PLUGIN_PAYMENT_METHOD_DELETE_RESTRICTION, |
|
212
|
|
|
'Plugin payment methods can not be deleted via API.', |
|
213
|
|
|
[], |
|
214
|
|
|
$e |
|
215
|
|
|
); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public static function refundInterrupted(string $refundId, string $errorMessage, ?\Throwable $e = null): self |
|
219
|
|
|
{ |
|
220
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
221
|
|
|
return new RefundException($refundId, $errorMessage, $e); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
return new self( |
|
225
|
|
|
Response::HTTP_BAD_REQUEST, |
|
226
|
|
|
self::PAYMENT_REFUND_PROCESS_INTERRUPTED, |
|
227
|
|
|
'The refund process was interrupted due to the following error:' . \PHP_EOL . '{{ errorMessage }}', |
|
228
|
|
|
[ |
|
229
|
|
|
'refundId' => $refundId, |
|
230
|
|
|
'errorMessage' => $errorMessage, |
|
231
|
|
|
], |
|
232
|
|
|
$e |
|
233
|
|
|
); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
public static function tokenExpired(string $token, ?\Throwable $e = null): self |
|
237
|
|
|
{ |
|
238
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
239
|
|
|
return new TokenExpiredException($token, $e); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
return new self( |
|
243
|
|
|
Response::HTTP_BAD_REQUEST, |
|
244
|
|
|
self::PAYMENT_TOKEN_EXPIRED, |
|
245
|
|
|
'The provided token {{ token }} is expired and the payment could not be processed.', |
|
246
|
|
|
[ |
|
247
|
|
|
'token' => $token, |
|
248
|
|
|
], |
|
249
|
|
|
$e |
|
250
|
|
|
); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
public static function tokenInvalidated(string $token, ?\Throwable $e = null): self |
|
254
|
|
|
{ |
|
255
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
256
|
|
|
return new TokenInvalidatedException($token, $e); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
return new self( |
|
260
|
|
|
Response::HTTP_BAD_REQUEST, |
|
261
|
|
|
self::PAYMENT_TOKEN_INVALIDATED, |
|
262
|
|
|
'The provided token {{ token }} is invalidated and the payment could not be processed.', |
|
263
|
|
|
[ |
|
264
|
|
|
'token' => $token, |
|
265
|
|
|
], |
|
266
|
|
|
$e |
|
267
|
|
|
); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
public static function unknownPaymentMethod(string $paymentMethodId, ?\Throwable $e = null): self |
|
271
|
|
|
{ |
|
272
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
273
|
|
|
return new UnknownPaymentMethodException($paymentMethodId, $e); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
return new self( |
|
277
|
|
|
Response::HTTP_BAD_REQUEST, |
|
278
|
|
|
self::PAYMENT_UNKNOWN_PAYMENT_METHOD, |
|
279
|
|
|
'The payment method {{ paymentMethodId }} could not be found.', |
|
280
|
|
|
[ |
|
281
|
|
|
'paymentMethodId' => $paymentMethodId, |
|
282
|
|
|
], |
|
283
|
|
|
$e |
|
284
|
|
|
); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
public static function unknownRefund(string $refundId, ?\Throwable $e = null): self |
|
288
|
|
|
{ |
|
289
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
290
|
|
|
return new UnknownRefundException($refundId, $e); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
return new self( |
|
294
|
|
|
Response::HTTP_BAD_REQUEST, |
|
295
|
|
|
self::PAYMENT_REFUND_UNKNOWN_ERROR, |
|
296
|
|
|
'The Refund process failed with following exception: Unknown refund with id {{ refundId }}.', |
|
297
|
|
|
[ |
|
298
|
|
|
'refundId' => $refundId, |
|
299
|
|
|
], |
|
300
|
|
|
$e |
|
301
|
|
|
); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
public static function unknownRefundHandler(string $refundId, ?\Throwable $e = null): self |
|
305
|
|
|
{ |
|
306
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
307
|
|
|
return new UnknownRefundHandlerException($refundId, $e); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
return new self( |
|
311
|
|
|
Response::HTTP_BAD_REQUEST, |
|
312
|
|
|
self::PAYMENT_REFUND_UNKNOWN_HANDLER_ERROR, |
|
313
|
|
|
'The Refund process failed with following exception: Unknown refund handler for refund id {{ refundId }}.', |
|
314
|
|
|
[ |
|
315
|
|
|
'refundId' => $refundId, |
|
316
|
|
|
], |
|
317
|
|
|
$e |
|
318
|
|
|
); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
public static function validatePreparedPaymentInterrupted(string $errorMessage, ?\Throwable $e = null): self |
|
322
|
|
|
{ |
|
323
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
324
|
|
|
return new ValidatePreparedPaymentException($errorMessage, $e); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
return new self( |
|
328
|
|
|
Response::HTTP_BAD_REQUEST, |
|
329
|
|
|
self::PAYMENT_VALIDATE_PREPARED_ERROR, |
|
330
|
|
|
'The validation process of the prepared payment was interrupted due to the following error:' . \PHP_EOL . '{{ errorMessage }}', |
|
331
|
|
|
[ |
|
332
|
|
|
'errorMessage' => $errorMessage, |
|
333
|
|
|
], |
|
334
|
|
|
$e |
|
335
|
|
|
); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
public function getRefundId(): string |
|
339
|
|
|
{ |
|
340
|
|
|
return $this->getParameter('refundId') ?? ''; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
public function getOrderTransactionId(): ?string |
|
344
|
|
|
{ |
|
345
|
|
|
return $this->getParameter('orderTransactionId'); |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
public function getOrderId(): ?string |
|
349
|
|
|
{ |
|
350
|
|
|
return $this->getParameter('orderId'); |
|
351
|
|
|
} |
|
352
|
|
|
} |
|
353
|
|
|
|