mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
101 stars 52 forks source link

Quote not restored due to wrong date handling #575

Closed HenKun closed 1 year ago

HenKun commented 1 year ago

Describe the bug When coming back to Magento from Mollie Payment page by using back button, the quote is not restored. This is due to an issue in the handling of dates.

Used versions

To Reproduce Steps to reproduce the behavior: Pre: Timezone is configured to be GMT+2 (MESZ/CEST)

  1. Disable loading_screen
  2. Go to checkout
  3. Choose Mollie payment method
  4. Place order
  5. Return by clicking back button

Expected behavior The quote is restored and checkout #payment step is openend.

Actual behavior Customer is redirected to empty cart.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context I tracked down the issue to the observer Observer/ControllerActionPredispatchCheckoutIndexIndex/RestoreQuoteOfUnsuccessfulPayment.php On line 54 the order creation date is transformed to current timezone by using:

$createdAt = $this->timezone->date($order->getCreatedAt());

This leads to a completely wrong time. In my case the year is modified by 2 years, seconds get removed and hours are not transformed to correct timezone. I do not know if this is a Magento bug, I did not find any related issues. Due to this wrong transformation, the check for being greater than 5 minutes hits and the method returns. (Sie question: What would be the disadvantage to raise this limit or completely remove the check?) However, the following code works perfectly fine:

$createdAt = $this->timezone->date(new \DateTime($order->getCreatedAt()));

So I assume the Magento internal handling of stringified dates is wrong, wheres the new \DateTime constructor handles the string correctly.

I logged the wrong output, so you can see the difference:

[2022-10-18 13:36:16] Mollie.INFO: info: Diff Minutes: 58 [] []
[2022-10-18 13:36:16] Mollie.INFO: info: Order date original string 2022-10-18 13:35:47 [] []
[2022-10-18 13:36:16] Mollie.INFO: info: Order date after timezone used 2024-04-13-13-35-00 [] [] <-- wrong!
[2022-10-18 13:36:16] Mollie.INFO: info: Now after timezone used 2022-10-18-15-36-16 [] []
[2022-10-18 13:36:16] Mollie.INFO: info: greater 5 min - return [] []

The log after the proposed change:

[2022-10-18 13:59:12] Mollie.INFO: info: Diff Minutes: 2 [] []
[2022-10-18 13:59:12] Mollie.INFO: info: Order date original string 2022-10-18 13:56:25 [] []
[2022-10-18 13:59:12] Mollie.INFO: info: Order date after timezone used 2022-10-18-15-56-25 [] [] <-- correct!
[2022-10-18 13:59:12] Mollie.INFO: info: Now after timezone used 2022-10-18-15-59-12 [] []
[2022-10-18 13:59:12] Mollie.INFO: info: less 5 min [] []
Frank-Magmodules commented 1 year ago

HI @HenKun ,

We are happy to share that we've just released the new 2.18.0 version where we have fixed this issue.
Thank you for opening this issue and for the detailed issue report.

We are closing this issue now but please feel free to reopen the issue if this still occurs.