Shopware6
Shopware6 copied to clipboard
Cancellation or Failure Payment will lead into fatal exception (SW 6.6.x.x)
If I a cancel the payment or the payment will failure, then a fatal exception will happen within the Shopware Store.
{
"errors": [
{
"code": "0",
"status": "500",
"title": "Internal Server Error",
"detail": "Attempted to load class \u0022AsyncPaymentFinalizeException\u0022 from namespace \u0022Shopware\\Core\\Checkout\\Payment\\Exception\u0022.\nDid you forget a \u0022use\u0022 statement for another namespace?"
}
]
}
Seems like that the Polyfill for PaymentException Class is loaded before Shopware, so the class will be Polyfill-Class will be registered before the Shopware-Class is registered.
Personal opinion of DEV: I do not think it is a good idea, to have too many polyfill for Shopware. It would be better to restrict the compatibility to the Shopware versions. I also develop a few payment provider extensions, and we decided to do not keep the compatibility to lower SW-Versions if the codebase is too different (e.g. missing exception-classes)
Much better solution:
protected function createPaymentException(string $orderTransactionId, string $errorMessage, ?\Throwable $e = null): \Throwable
{
if (class_exists(PaymentException::class)) {
return PaymentException::asyncProcessInterrupted($orderTransactionId, $errorMessage, $e);
} elseif (class_exists(SyncPaymentProcessException::class)) {
// required for shopware version <= 6.5.3
return SyncPaymentProcessException($orderTransactionId, $errorMessage, $e); // @phpstan-ignore-line
}
// should never occur, just to be safe.
return \RuntimeException('payment process was interrupted ' . $orderTransactionId);
}