MultiSafepay / magento2

MultiSafepay plugin for Magento 2
Open Software License 3.0
19 stars 8 forks source link

Order confirmation email is ignoring the gateway override setting. #37

Closed rbouma closed 1 year ago

rbouma commented 1 year ago

Describe the bug Order confirmation gateway override setting "After paid transaction" is ignored if the default is set to after transaction

To Reproduce Steps to reproduce the behavior:

  1. set the default to after transaction in general settings in de module: CleanShot 2022-10-11 at 10 53 44
  2. set override to after paid transaction for the Klarna gateway in this example: CleanShot 2022-10-11 at 10 54 57
  3. Place an order on the frontend of the shop and submit the order
  4. You will be redirected to multisafepay but the order confirmation email is already send because of this code:

Service/OrderService.php:

if (in_array($transactionStatus, [
                TransactionStatus::COMPLETED,
                TransactionStatus::INITIALIZED,
                TransactionStatus::RESERVED,
                TransactionStatus::SHIPPED,
            ], true)
            && $this->emailSender->sendOrderConfirmationEmail($order)) {
            $this->logger->logInfoForOrder(
                $orderId,
                __('Order confirmation email after transaction has been sent')->render(),
                Logger::DEBUG
            );
        }

After the order is placed it is pending payment with gateway status Initialised

$this->emailSender->sendOrderConfirmationEmail($order)) is called

Referenced to this file Service/EmailSender.php

$emailTypes = [
      $this->config->getOrderConfirmationEmail()
];

The default setting after transaction is pushed in the array.

then if a gateway override is defined it also pushed in the same array here:

if ($this->gatewayConfig->getValue(Config::OVERRIDE_ORDER_CONFIRMATION_EMAIL)) {
      $emailTypes[] = $this->gatewayConfig->getValue(Config::ORDER_CONFIRMATION_EMAIL) ?? '';
}

Then it checks if the order can be send here:

if (in_array($emailType, $emailTypes, true)) {
       $this->orderSender->send($order);

       return true;
}

An $emailType is not given in the Service/OrderService.php#L174 So after_transaction is used as default for this check en its true in this case when the transaction is placed not paid.

In the log files it shows

[2022-10-11 08:28:23] MultiSafepay.INFO: (Order ID: #############): Payment URL is: https://payv2.multisafepay.com/connect/#############/?lang=nl_NL [] []
[2022-10-11 08:28:23] MultiSafepay.DEBUG: (Order ID: #############) User redirected to the following page: https://payv2.multisafepay.com/connect/#############/?lang=nl_NL [] []
[2022-10-11 08:28:26] MultiSafepay.DEBUG: (Order ID: #############): Order ID has been retrieved from the order [] []
[2022-10-11 08:28:26] MultiSafepay.DEBUG: (Order ID: #############): Transaction data was retrieved: {
    "description": "Bestelling ##############",
    "order_id": "#############",
[2022-10-11 08:28:27] MultiSafepay.DEBUG: (Order ID: #############): Order confirmation email after transaction has been sent [] []

Where the last line is 'Order confirmation email after transaction has been sent' not the one that needs to be logged is: 'Order confirmation email after paid transaction has been sent' in Service/Order/ProcessOrderByTransactionStatus.php#L197

Expected behavior The override setting that is configured is used instead the default, so the email is send after the order is paid in this case.

vinodsowdagar commented 1 year ago

Hi @rbouma ,

Thank you for your report including the analysis already done on the matter.

We are going to look into it as soon as possible and we will keep you updated with feedback later this week.

If there are any questions or updates in the meantime, please let me know.

vinodsowdagar commented 1 year ago

Hi @rbouma ,

We have successfully reproduced this issue. Currently we have a fix ready for the next release.

When I have an update about the release, I will let you know.

vinodsowdagar commented 1 year ago

Hi @rbouma ,

We have updated our payment module with a fix for this issue: https://github.com/MultiSafepay/magento2/releases/tag/2.21.1

If there are more questions, feel free to reopen this issue or create a new one. For now i am closing this issue.

rbouma commented 1 year ago

@Vinod-MultiSafepay Thank you, i will update the extension