Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canceling payment leads to 500 status code #575

Open
ts-mothership opened this issue May 3, 2023 · 5 comments
Open

Canceling payment leads to 500 status code #575

ts-mothership opened this issue May 3, 2023 · 5 comments

Comments

@ts-mothership
Copy link

Summary

When customer cancels Mollie payment, the order is canceled too. Somehow Mollie tries to create a new payment, which leads to an ApiException "Cannot create a new payment for order ord_6ljr39 when the order status is "canceled"".

Shopware Version: 6.4.20.1
Mollie Plugin Version: 3.6.0

Reproduce

  1. Add a product to cart, go to checkout and select Mollie Giropay
  2. Confirm order.
    => The order state is now "open".
    => You are redirected to Mollie https://www.mollie.com/checkout/test-mode?method=giropay&token=...
  3. On the bottom left click on the back to shop button
    => You're redirected first to https://www.mollie.com/checkout/test-mode/cancel
    => then to http://shop.test/mollie/payment/235b2bef5e28416d8e3fc5aef1e95bbb

The order is correctly canceled but an error is displayed.

Should be

You should not see an error page. Instead there should be a page where you can change your Mollie payment method or retry again. If you choose to retry, the order status should change back to open, and then a new payment should be created.

More Details and Background

We're currently trying to upgrade the shop from 6.4.16.0 to 6.4.20.1 and with it, the Mollie plugin from 3.1.0 to 3.6.0. In the old version there was no problem when you cancel the payment. I'm not sure what could've caused it, but from current analysis it looks like the plugin tries to create a new payment when it should not do (yet). In the old version the order status and payment was changed on URL /mollie/payment/retry/...

Exception trace on URI "/mollie/payment/247eb01c16bf4bd4bbffc2dd379c7cb6":

Mollie\Api\Exceptions\ApiException:
[2023-05-03T13:58:04+0000] Error executing API call (422: Unprocessable Entity): Cannot create a new payment for order ord_6ljr39 when the order status is "canceled".. Documentation: https://docs.mollie.com/overview/handling-errors

  at vendor/kiener/mollie-payments-plugin/src/Service/MollieApi/Client/MollieHttpClient.php:151
  at Kiener\MolliePayments\Service\MollieApi\Client\MollieHttpClient->parseResponseBody('{"status":422,"title":"Unprocessable Entity","detail":"Cannot create a new payment for order ord_6ljr39 when the order status is \\"canceled\\".","_links":{"documentation":{"href":"https://docs.mollie.com/overview/handling-errors","type":"text/html"}}}', 422, null)
     (vendor/kiener/mollie-payments-plugin/src/Service/MollieApi/Client/MollieHttpClient.php:96)
  at Kiener\MolliePayments\Service\MollieApi\Client\MollieHttpClient->send('POST', 'https://api.mollie.com/v2/orders/ord_6ljr39/payments', array('Accept' => 'application/json', 'Authorization' => 'Bearer test_AUkVDeHtFrTEUxafJ8rMavVknDv3xu', 'User-Agent' => 'Mollie/2.40.1 PHP/8.1.18 Curl/* Shopware/6.4.20.1 MollieShopware6/3.6.0', 'X-Mollie-Client-Info' => 'Linux ec57c4208abe 5.15.0-70-generic #77-Ubuntu SMP Tue Mar 21 14:02:37 UTC 2023 x86_64', 'Content-Type' => 'application/json'), null)
     (vendor/mollie/mollie-api-php/src/MollieApiClient.php:538)
  at Mollie\Api\MollieApiClient->performHttpCallToFullUrl('POST', 'https://api.mollie.com/v2/orders/ord_6ljr39/payments', null)
     (vendor/mollie/mollie-api-php/src/MollieApiClient.php:494)
  at Mollie\Api\MollieApiClient->performHttpCall('POST', 'orders/ord_6ljr39/payments', null)
     (vendor/mollie/mollie-api-php/src/Endpoints/EndpointAbstract.php:76)
  at Mollie\Api\Endpoints\EndpointAbstract->rest_create(array(), array())
     (vendor/mollie/mollie-api-php/src/Endpoints/OrderPaymentEndpoint.php:72)
  at Mollie\Api\Endpoints\OrderPaymentEndpoint->createForId('ord_6ljr39', array(), array())
     (vendor/mollie/mollie-api-php/src/Endpoints/OrderPaymentEndpoint.php:55)
  at Mollie\Api\Endpoints\OrderPaymentEndpoint->createFor(object(Order), array(), array())
     (vendor/mollie/mollie-api-php/src/Resources/Order.php:511)
  at Mollie\Api\Resources\Order->createPayment(array())
     (vendor/kiener/mollie-payments-plugin/src/Facade/MollieOrderPaymentFlow.php:114)
  at Kiener\MolliePayments\Facade\MollieOrderPaymentFlow->process(object(OrderTransactionEntity), object(OrderEntity), object(Order), 'de12e3e170b54d33aa7fbc4caebaa359', object(Context))
     (vendor/kiener/mollie-payments-plugin/src/Facade/Controller/PaymentReturnFacade.php:176)
  at Kiener\MolliePayments\Facade\Controller\PaymentReturnFacade->returnAction('247eb01c16bf4bd4bbffc2dd379c7cb6', object(Context))
     (vendor/kiener/mollie-payments-plugin/src/Controller/Storefront/Payment/ReturnController.php:43)
  at Kiener\MolliePayments\Controller\Storefront\Payment\ReturnController->payment(object(SalesChannelContext), '247eb01c16bf4bd4bbffc2dd379c7cb6')
     (vendor/symfony/http-kernel/HttpKernel.php:163)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:75)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/HttpCache/SubRequestHandler.php:86)
  at Symfony\Component\HttpKernel\HttpCache\SubRequestHandler::handle(object(Kernel), object(Request), 1, true)
     (vendor/symfony/http-kernel/HttpCache/HttpCache.php:479)
  at Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(object(Request), true)
     (vendor/symfony/http-kernel/HttpCache/HttpCache.php:452)
  at Symfony\Component\HttpKernel\HttpCache\HttpCache->fetch(object(Request), true)
     (vendor/symfony/http-kernel/HttpCache/HttpCache.php:346)
  at Symfony\Component\HttpKernel\HttpCache\HttpCache->lookup(object(Request), true)
     (vendor/symfony/http-kernel/HttpCache/HttpCache.php:224)
  at Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(object(Request), 1, true)
     (vendor/shopware/core/HttpKernel.php:156)
  at Shopware\Core\HttpKernel->doHandle(object(Request), 1, true)
     (vendor/shopware/core/HttpKernel.php:81)
  at Shopware\Core\HttpKernel->handle(object(Request))
     (public/index.php:85) 
@ts-mothership
Copy link
Author

I think I found the culprit: With #520 the new setting automaticCancellation has been introduced which is enabled per default. When the customer cancels payment, he is redirected to shop and the order state changes to cancelled in https://github.com/mollie/Shopware6/blob/v3.6.0/src/Facade/MollieOrderPaymentFlow.php#L73. This triggers the CancelOrderSubscriber, which also cancels the mollie order. However, MollieOrderPaymentFlow continues to execute and tries to create a new payment in https://github.com/mollie/Shopware6/blob/v3.6.0/src/Facade/MollieOrderPaymentFlow.php#L114 which then fails.

As workaround I can disable automatic cancellation in shop settings.

@boxblinkracer
Copy link
Collaborator

Hi

thank you for this
really sorry for the late replies, ...shopware 6.5....

ill check it out afterwards
but the interesting thing is, that automatic-cancellation did always exist :D
its now only possible to turn it off, because it led to troubles in a project we had

so good it helps for now :)

@ts-mothership
Copy link
Author

@boxblinkracer No problem. We were using an old version before, at that time auto cancellation did not exist yet. ;) I'm glad that the disable setting exists, so there's no pressure.

@boxblinkracer
Copy link
Collaborator

fun fact...that did always exist, i actually didnt know of it either when we took over :D
but could be we fixed it one day haha

@BlackScorp
Copy link
Collaborator

@ts-mothership the mollie orders API does not allow to cancel payments within order and you cannot create new payments if there is already one which is open.

we will move at some point all payment methods to payments API where we can handle the payment in a better way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants