magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.37k stars 9.28k forks source link

Pending Payment Order Lifetime & sales_clean_orders Cronjob Conflict? #37878

Open drinkingsouls opened 10 months ago

drinkingsouls commented 10 months ago

Preconditions and environment

The sales_clean_orders cronjob is run every hour, on the hour. This is set it in the crobtab.xml at vendor/magento/module-sales/etc

`

0 * * * *

`

This cancels orders with "Pending Payment" status correctly. However, it does this once per hour, as set by the cron.

There is a setting to reduce order pending lifetime in Stores > Configuration >Sales > Sales > Orders Cron Settings >Pending Payment Order Lifetime (minutes) If you set this to anything less than an hour, the order stays in Pending Payment status until the sales_clean_orders cron is run (once an hour), it doesn't trigger the cron any earlier. If the time is set to more than an hour then this setting works as expected. The default setting of 8 hours works as expected.

Steps to reproduce

Navigate to setting: Stores > Configuration >Sales > Sales > Orders Cron Settings >Pending Payment Order Lifetime (minutes). Change to a value less than 60 minutes. E.g 10 minutes.

Expected result

Pending Payment orders are Closed when time value set is reached.

Actual result

Payment Pending orders are not Closed until the sales_clean_orders cron is run every hour.

Additional information

I can tell that the time in the Pending Payment Order Lifetime (minutes) is honoured in some way, for example:

If I set the value to 15 minutes and I place an order at 13:50, when the cron sales_clean_orders is ran at 14:00, the order remains pending (as 15 minutes had not passed - 5 minutes remain). This should, in theory, change to Cancelled status at 14:05. In reality it will not be changed to Cancelled until 15:00 when the next sales_clean_order cron is ran.

If the cronjob time for sales_clean_orders is edited down to run more frequently, for example, every five minutes <schedule>*/5 * * * *</schedule> then this runs a bit more accurately as the cron checks for orders to cancel more frequently.

In reality, should the minutes set in "Pending Payment Order Lifetime (minutes)." not dictate how often the sales_clean_orders cron is run?

Release note

No response

Triage and priority

m2-assistant[bot] commented 10 months ago

Hi @drinkingsouls. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

drinkingsouls commented 10 months ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 10 months ago

Hi @drinkingsouls. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 10 months ago

Hi @drinkingsouls, here is your Magento Instance: https://b58b3f0843b51ebd1c286fc967a00a2c.instances-prod.magento-community.engineering Admin access: https://b58b3f0843b51ebd1c286fc967a00a2c.instances-prod.magento-community.engineering/admin_f0de Login: 4ce89cbb Password: 31dba01f8239

drinkingsouls commented 10 months ago

Can't be replicated on Dev Instance as there is no Payment Gateway to set "Pending Payment" status to an order.

m2-assistant[bot] commented 10 months ago

Hi @engcom-Dash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:


drinkingsouls commented 10 months ago

Looks like similar issue to #23682

To simplify, the "Pending Payment Order Lifetime (minutes)" setting is in conflict with the sales_clean_orders cron that only runs once an hour.

If anything less than 60 minutes is set for "Pending Payment Order Lifetime (minutes)", it doesn't cancel Pending Payment orders because it has to wait for the sales_clean_orders cron to be run hourly.

m2-assistant[bot] commented 10 months ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 10 months ago

Hi @drinkingsouls,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Steps to reproduce

Screenshot 2023-09-05 at 10 18 51 PM Screenshot 2023-09-05 at 11 39 12 PM

Pending Payment orders are not Closed when time value set is reached.

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 10 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-9466 is successfully created for this GitHub issue.

m2-assistant[bot] commented 10 months ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

drinkingsouls commented 10 months ago

Pending Payment orders are Closed when time value set is reached.

Pending Payment orders are not closed when time value set is reached. That is the problem.

MilenV commented 6 months ago

Hello Team,

We observe the following issue. We have a lot of orders stuck in "Pending Payment" after these orders have been "Refunded". Example order is 002006663. Pending Payment

Nov 14, 2023 4:57:05 PM Pending Payment Customer Not Notified Refund Webhook successfully handled Nov 14, 2023 4:57:05 PM Pending Payment Customer Not Notified Adyen HTTP Notification(s): eventCode: REFUND pspReference: VRCQBWR6W46XZP52 paymentMethod: visa success: true Nov 14, 2023 4:54:22 PM Pending Payment Customer Not Notified Refunded by D.T. 231114-000235 Nov 14, 2023 4:54:12 PM Closed Customer Not Notified We refunded £35.44 online. Transaction ID: "GS3GQ3GJHVM89VB2-capture-refund" Nov 14, 2023 4:54:12 PM Processing Customer Not Notified Adyen Result response: authResult: [refund-received] pspReference: VRCQBWR6W46XZP52 Oct 18, 2023 10:07:33 PM Complete Customer Not Notified Oct 18, 2023 10:03:15 PM Complete Customer Not Notified Oct 18, 2023 10:03:14 PM Processing Customer Not Notified Captured amount of £35.44 online. Transaction ID: "GS3GQ3GJHVM89VB2-capture" Oct 18, 2023 10:03:14 PM Exported Customer Not Notified Adyen Result response: authResult: [capture-received] pspReference: BHQ2X7RLKQZMWPG2 Oct 17, 2023 6:02:59 AM Exported Customer Not Notified Oct 16, 2023 11:17:05 PM Sent to Fullfilment Customer Not Notified Oct 16, 2023 11:01:09 PM Processing Customer Not Notified Capture Mode set to Manual Oct 16, 2023 11:01:09 PM Processing Customer Not Notified AUTHORISATION webhook notification w/amount GBP 35.44 was processed Oct 16, 2023 11:01:09 PM Payment Review Customer Not Notified Adyen HTTP Notification(s): eventCode: AUTHORISATION pspReference: GS3GQ3GJHVM89VB2 paymentMethod: visa success: true reason:004385:9205:06/2025 Oct 16, 2023 10:41:30 PM Payment Review Customer Not Notified We will authorize £35.44 after the payment is approved at the payment gateway. Oct 16, 2023 10:41:30 PM Customer Not Notified Adyen Result response: authResult: IdentifyShopper

I have checked the following article https://magento.stackexchange.com/questions/280686/pending-payment-order-lifetime-doesnt-expire-or-cancel-orders where it says that:

The "Pending Payment Order Lifetime" is only related to orders which are in the state "Pending Payment", e.g. if the customer has entered the online transaction payment process and cancels or quits the payment process. Then the order in Magento 2 will stay in the state "Pending Payment". After the timeout of "Pending Payment Order Lifetime" is reached, these orders will be automatically canceled by the Magento cronjob.

In admin panel of Adobe Commerce (known as Magento) here is what configuration have been settled. Stores==>Configuration==>Sales==>Orders Cron Settings(Pending Payment Order Lifetime (minutes) is 480 mins or 8 hours. image Furthermore on Stores==>Configuration==>Sales==>Order Cancelling(time to cancel is 72 hours) this status "Pending Payment" is not selected.
image

The questions that we have as exposed as follows.

  1. If we select "Pending Payment" in Stores==>Configuration==>Sales==>Order Cancelling this will make these orders that stuck in this status "Pending Payment" but being "Refunded" to cancelled as we have sales_cron_job picked them up? image
  2. As we already have set "Pending Payment Order Lifetime" to 480 mins or 8 hours why our orders still stuck in "Pending Payment" ?

Default order states in Magento include: "Pending Payment" – assigned to an order for which the payment has been initiated but is awaiting confirmation. Please note that status of the invoice is paid for all of affected orders.

Regards, Milen Velinov