Skip to content

M2 system sent email order confirmation when oder status is payment review / declined #1259

Description

@miracteam

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

  1. We were placing an order normally and choosing Amazon Pay as payment method
  2. Login by Amazon account & choose a card to pay, VISA ending 3434 in this case.
  3. The payment processing was loaded and back to cart page with an error message, and the system automatically sent an email confirmation.
    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:

photo_2024-12-18_16-39-04
photo_2024-12-18_16-39-27
photo_2024-12-18_16-39-30

Our setup

  • Magento version: 2.4.6-p3
  • Amazon Pay Extension Version: 5.17.1
  • Magento Edition: Community

Please help to check it & let me know if you need any further information.

Thank you.
Best Regards

Activity

  1. sgabhart22 commented on Jan 2, 2025

    @sgabhart22
    Contributor

    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!

    asd-1236.patch.txt

    Thanks,
    Spencer

  2. sgabhart22 commented on Jan 17, 2025

    @sgabhart22
    Contributor

    Hello @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!

    asd-1236-updated.patch.txt

    Thanks,
    Spencer

  3. sgabhart22 commented on Feb 17, 2025

    @sgabhart22
    Contributor

    Hi 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.

    asd-1236-final.patch.txt

  4. sgabhart22 commented on Aug 21, 2025

    @sgabhart22
    Contributor

    Hell @miracteam , just letting you know these fixes are now live, so we'll closing this issue soon.

    Thanks,
    Spencer

  5. nige-one commented on May 5, 2026

    @nige-one

    We 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's Order::registerCancellation() (Model/Order.php:1361-1391) transiently calls setState(STATE_PROCESSING) if any item has qtyToRefund — which trips the state == STATE_PROCESSING branch in Plugin/SendEmail::afterSetState (Plugin/SendEmail.php:64) and fires orderSender->send().
    The order ends up canceled, but the new-order confirmation email has already gone out. On our shop 21 canceled Amazon Pay orders ended up with email_sent=1 this way.

  6. nige-one commented on May 5, 2026

    @nige-one

    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);                                                                                                                                                                            
                     } 
    
  7. nige-one commented on Jun 7, 2026

    @nige-one

    I just added a PR with hardened fix - our merchant always finds ways...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions