Repository navigation
M2 system sent email order confirmation when oder status is payment review / declined #1259
Description
Activity
Hello @miracteam ,
Thanks for the report, this is a known issue with a fix targeted for inclusion in the next release. Until then, I can provide a patch here to address the issue. Please let us know if you continue to have problems!
Thanks,
SpencerHello @tungho-copilot ,
Looks like I somehow missed a certain combination of payment action/authorization config values in my testing here... you are absolutely correct, I was able to reproduce this initially with asynchronous email sending disabled and the payment action set to 'authorize and capture'. I was certain I tested this scenario but maybe caching got the best of me; at any rate, I'm attaching another patch here that simplifies things a bit with only one plugin, but should still cover all combinations of Amazon + Magento config in terms of order processing and email settings. Please let us know if you continue to have issues, and my apologies again for missing this the first time!
Thanks,
SpencerHi again @tungho-copilot ,
Very sorry for the continued issues, we hit a couple snags getting the latest release out. I'm attaching the final version of this fix that will be included. My apologies again for the back and forth, and thanks for your patience.
Hell @miracteam , just letting you know these fixes are now live, so we'll closing this issue soon.
Thanks,
SpencerWe have the same issue from a different angle. Somestimes customers do not complete payment on Amazon. We have stale orders afterwards. If we cancel the orders from backend the customer receives another order confirmation mail.
when admin manually cancels a stuck Amazon Pay order (
payment_review/pending_payment), Magento'sOrder::registerCancellation()(Model/Order.php:1361-1391) transiently callssetState(STATE_PROCESSING)if any item hasqtyToRefund— which trips thestate == STATE_PROCESSINGbranch inPlugin/SendEmail::afterSetState(Plugin/SendEmail.php:64) and firesorderSender->send().
The order ends upcanceled, but the new-order confirmation email has already gone out. On our shop 21 canceled Amazon Pay orders ended up withemail_sent=1this way.That's what Claude spit out and I'm using successfully:
diff --git a/Plugin/SendEmail.php b/Plugin/SendEmail.php --- a/Plugin/SendEmail.php +++ b/Plugin/SendEmail.php @@ -61,9 +61,17 @@ class SendEmail if ($this->scopeConfig->getValue('sales_email/order/enabled')) { $subject->setCanSendNewEmailFlag(false); if ($subject->getState() == Order::STATE_PROCESSING && !empty($subject->getStatusHistories()) && !$subject->getEmailSent() ) { + foreach ($subject->getAllItems() as $item) { + if ($item->getQtyCanceled() > 0) { + // Inside Order::registerCancellation(): items are + // cancelled before setState() runs, and a transient + // STATE_PROCESSING can be set when items have qty + // to refund. Suppress the confirmation email. + return $result; + } + } $subject->setCanSendNewEmailFlag(true); $this->orderSender->send($subject); }I just added a PR with hardened fix - our merchant always finds ways...
Hi Amazon Pay Team,
We're facing an issue that M2 system sent an email order confirmation when the order status was payment review / declined
What I expected
The system only sent email when order status is processing (payment captured)
What happened instead
M2 system sent an email order confirmation when the order status was payment review / declined.
Steps to reproduce the issue
For example
We had this issue on the Live environment of the site HammerHead Performance. But it also happened on the fresh Magento 2.4.7 locally as our tried images below:
Our setup
Please help to check it & let me know if you need any further information.
Thank you.
Best Regards