mollie / Shopware6

47 stars 52 forks source link

Cancellation or Failure Payment will lead into fatal exception (SW 6.6.x.x) #791

Closed rommelfreddy closed 1 month ago

rommelfreddy commented 2 months ago

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);
}
BlackScorp commented 1 month ago

Hi thx for the info, iam going to add some checks so the polyfill class is not loaded directly.

about shopware version restriction, sadly there are too many merchants which still runs shopware 6.4.x thats why we cant drop the support. i prefer to use the polyfill classes because if we drop a version at some point, i just have to delete the polyfill classes and the code stays the same.

rommelfreddy commented 2 weeks ago

sorry, but this will not solve the issue. still happens on the latest version.

maybe it will help to have two different release-lines.

--

i'm sorry to say that, but these polyfills are very terrible. Your fix would not solve the issue, because it still could happen, that your module got (class-)loaded before shopware - what it look likes. In this case, your check if the PaymentException-Class does exist, will always fail. --> usage of not existing AsyncPaymentFinalizeException

rommelfreddy commented 6 days ago

Hello @BlackScorp can you give me feedback on this please?