Magento2: Order confirmation email sent on pending/cancelled order -Payment

Created on 6 Jul 2017  Â·  16Comments  Â·  Source: magento/magento2

The customer tried placing an order 4 times, for the first three times he cancelled the order himself.but the fourth time he hasn't even gone to the payment page from checkout, but he received an order confirmation email on pending state and it went to cancelled state after 8hours.

Since the customer received the order confirmation email, he thought the payment was taken from his card and was asking for an invoice. But we don't have any record either on Magento 2 or Sagepay.
On Magento 2 database for that particular order, it shows null value for sgaepay tracking id, which means customer hasnt even gone to payment page. On the order grid it shows pending, notified and cancelled. even on the database tables it shows pending at 20:54 and cancelled at 05:00.

This is creating a huge issue for us, as the order has been placed for a huge amount where the email has been sent without actually paying for the items.

Preconditions

  1. Debian 8
  2. Php 7
    3.Maria DB(Mysql)
    4.Magento 2.1.6

Steps to reproduce

1.Cancelled the order (email not sent)

  1. cancelled the order(email not sent)
  2. cancelled the order(email not sent)
    4.Pending to cancelled.(email sent)

Expected result

  1. Order cancelled and email not sent.

Actual result

  1. order email sent on cancelled order/pending orders
    db 1
    db 2
    email sent on cancelled
    email sent 1
    email not sent on 3 orders

.

  1. [Screenshot, logs]
Cannot Reproduce Clear Description Format is valid bug report

Most helpful comment

Same problem here, any solution for this?

All 16 comments

Same problem here, any solution for this?

Anyone know from where this email is sent?

@nmallepally, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.1.9

Guys, This is not an bug. Magento just uses wrong event for sending out these emails.

The event we want it to use is sales_order_payment_pay but it is using something different

Hi @magento-engcom-team ,

The issue again occurred today, any work around solution please.
This is causing a big headache with big orders as customers gets notified by email as an order is placed.
Magento 2.1.6
see below again for screen shots
image

image
image

image

Any work around or a quick fix to stop this.
@keevitaja do you have any work around to avoid this issue?, please advise.

We have the same issue on Magento 2.1.9
Order with status Payment pending and confirmation email is send.

Hello, same bug here, I use one step checkout? Can it be the reason?

We are also facing same problem on magento v 2.2.2, is there any solution for this error yet ?

Do you use ogone/engenico?

Sébastien fieloux
Développeur freelance
0698458781
sebastien.[email protected]
http://www.sebfie.com

Le 15 janvier 2018 à 09:25:14, Sunil Verma ([email protected]) a
écrit:

We are also facing same problem on magento v 2.2.2, is there any solution
for this error yet ?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/10162#issuecomment-357612436,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA0nsY1RHSodq80RhOeGRHQMJQcSVQXUks5tKwtqgaJpZM4OPUk0
.

@sebfie no we have created a new payment gateway and no where in the code we are sending the email, so its triggering from core magento somewhere.

I think the called which send email is : ->registerAuthorizationNotification()

Hi @sebfie
Yes, we use one step checkout extension from magestore as well.
Any work around?

Yes, that's an issue on the module.

I overrided this method :

<?php
namespace Sebfie\Core\Model\Response\Type;

class Authorize extends \Netresearch\OPS\Model\Response\Type\Authorize {
    /**
     * @param \Magento\Sales\Model\Order $order
     * @param \Magento\Sales\Model\Order\Payment $payment
     */
    protected function registerFeedback(\Magento\Sales\Model\Order $order, \Magento\Sales\Model\Order\Payment $payment)
    {
        if ($this->getShouldRegisterFeedback()) {
            if ($order->getState() === \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW) {
                if (\Netresearch\OPS\Model\Status::canResendPaymentInfo($this->getStatus())
                    && $this->oPSPaymentHelper->isInlinePayment($payment)
                ) {
                    $targetState = \Magento\Sales\Model\Order::STATE_CANCELED;
                    $payment->setNotificationResult(true);
                    $payment->deny(false);
                } else {
                    $targetState = \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT;
                    $payment->setIsTransactionApproved(true);
                    $payment->update(false);
                }

                if ($order->getState() != $targetState) {
                    $order->setState($targetState);
                    $order->addStatusHistoryComment($this->getFinalStatusComment(), true);
                }
            } elseif ($order->getState() === \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT
                || $order->getState() === \Magento\Sales\Model\Order::STATE_NEW
            ) {
                // SPECIAL FIX FOR CANCELED BY CUSTOMER STATUS
                if ($this->getStatus() != \Netresearch\OPS\Model\Status::CANCELED_BY_CUSTOMER) {
                    $payment->registerAuthorizationNotification($this->getAmount());
                    $order->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT);
                } else {
                    $order->setState(\Magento\Sales\Model\Order::STATE_CANCELED);
                }
                $order->addStatusHistoryComment($this->getFinalStatusComment(), true);
            }
        } else {
            $this->addFinalStatusComment();
        }
    }
}

Check the line :

// SPECIAL FIX FOR CANCELED BY CUSTOMER STATUS

Where is the file located and its the OneStepCheckout extension right?
Have the problem that order witout payment gets send out the order email confirmation.

We are using payu plugin in magento 2.3.3 the movement the it goes to the payment gateway page the order confirmation mail is sent out

We need to know how we can get this working to send mail only after payment confirmation

I se that the above solution working for lower version but not for 2.3.3 do you have any support on this ?

Hi,

Same issue here on Magento 2.3.4-p2 version as well.
The moment it goes to the payment gateway page an order confirmation email is sent out without payment being completed.

This creates a lot of confusion for us and the customer, this could be a possible fraud situation where users can receive order emails without actually making a payment.

Would be great, if the magento team can looking into this quickly @magento-engcom-team

Was this page helpful?
0 / 5 - 0 ratings