I have created one third party Payment gateway.

It is working fine except, It is sending two order confirmation email. One email I have added in my custom module success controller to send email after validate Transaction Id. But one default email is also triggered by magento after place order.

Below is My Payment module payment.js file:

    function ($, ko, url, Component, quote, customer) {
        'use strict';
        return Component.extend({
            defaults: {
                template: 'Stack_Custompay/payment/custompay-form'
            redirectAfterPlaceOrder: false,
            /** Returns payment method instructions */
            getInstructions: function() {
                return window.checkoutConfig.payment.instructions[this.item.method];
            afterPlaceOrder: function () {
                    type: 'POST',
                    url: url.build('custompay/payment/order'),
                    success: function (response) {
                        if (response.success) {
                            var order_id = response.order_id;
                            var amount = response.amount;
                            var billing_address = quote.billingAddress();
                            var name =  billing_address.firstname;
                            var contact = billing_address.telephone;
                            var email = customer.customerData.email;
                            var data = {
                              amount: amount,
                              email: email,
                              contact: contact,

I have checked many posts and found there is some option to disable default order email by plugin. but I think it is not the standard approach. I read, there are some changes we need to perform in payment.js file to stop these confirmation email as implemeneted in braintree payment gateway.

how I could achieve this in the right way? Any help would be appreciated. Thanks.

1 Answer 1


Magento uses \Magento\Sales\Model\Order\Email\Sender\OrderSender to send order emails.

I would suggest replacing OrderService dependency in the \Magento\Quote\Observer\Webapi\SubmitObserver by your own implementation via di.xml in the following way:

class CustomOrderSender extends \Magento\Sales\Model\Order\Email\Sender\OrderSender
    public function send(Order $order, $forceSyncMode = false)
        // custom implementation

and specify it in di.xml:

<type name="Magento\Quote\Observer\Webapi\SubmitObserver">
        <argument name="orderSender" xsi:type="object">NS\CustomOrderSender</argument>

So, you don't need to use your own controller and an email will be sent only once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.