Order confirmation email sent before redirecting to third party payment gateway in Magento 2
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:
define(
[
'jquery',
'ko',
'mage/url',
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer'
],
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 () {
$.ajax({
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,
order_id:order_id
};
custompay.createPayment(data);
}
},
});
}
});
}
);
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.
magento2 payment payment-gateway
bumped to the homepage by Community♦ 2 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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:
define(
[
'jquery',
'ko',
'mage/url',
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer'
],
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 () {
$.ajax({
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,
order_id:order_id
};
custompay.createPayment(data);
}
},
});
}
});
}
);
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.
magento2 payment payment-gateway
bumped to the homepage by Community♦ 2 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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:
define(
[
'jquery',
'ko',
'mage/url',
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer'
],
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 () {
$.ajax({
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,
order_id:order_id
};
custompay.createPayment(data);
}
},
});
}
});
}
);
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.
magento2 payment payment-gateway
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:
define(
[
'jquery',
'ko',
'mage/url',
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer'
],
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 () {
$.ajax({
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,
order_id:order_id
};
custompay.createPayment(data);
}
},
});
}
});
}
);
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.
magento2 payment payment-gateway
magento2 payment payment-gateway
edited Nov 17 '17 at 10:15
Pankaj Pareek
asked Nov 17 '17 at 9:27
Pankaj PareekPankaj Pareek
2,44411338
2,44411338
bumped to the homepage by Community♦ 2 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 2 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Magento uses MagentoSalesModelOrderEmailSenderOrderSender
to send order emails.
I would suggest replacing OrderService
dependency in the MagentoQuoteObserverWebapiSubmitObserver
by your own implementation via di.xml in the following way:
class CustomOrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
{
public function send(Order $order, $forceSyncMode = false)
{
// custom implementation
}
}
and specify it in di.xml:
<type name="MagentoQuoteObserverWebapiSubmitObserver">
<arguments>
<argument name="orderSender" xsi:type="object">NSCustomOrderSender</argument>
</arguments>
</type>
So, you don't need to use your own controller and an email will be sent only once.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f202001%2forder-confirmation-email-sent-before-redirecting-to-third-party-payment-gateway%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Magento uses MagentoSalesModelOrderEmailSenderOrderSender
to send order emails.
I would suggest replacing OrderService
dependency in the MagentoQuoteObserverWebapiSubmitObserver
by your own implementation via di.xml in the following way:
class CustomOrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
{
public function send(Order $order, $forceSyncMode = false)
{
// custom implementation
}
}
and specify it in di.xml:
<type name="MagentoQuoteObserverWebapiSubmitObserver">
<arguments>
<argument name="orderSender" xsi:type="object">NSCustomOrderSender</argument>
</arguments>
</type>
So, you don't need to use your own controller and an email will be sent only once.
add a comment |
Magento uses MagentoSalesModelOrderEmailSenderOrderSender
to send order emails.
I would suggest replacing OrderService
dependency in the MagentoQuoteObserverWebapiSubmitObserver
by your own implementation via di.xml in the following way:
class CustomOrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
{
public function send(Order $order, $forceSyncMode = false)
{
// custom implementation
}
}
and specify it in di.xml:
<type name="MagentoQuoteObserverWebapiSubmitObserver">
<arguments>
<argument name="orderSender" xsi:type="object">NSCustomOrderSender</argument>
</arguments>
</type>
So, you don't need to use your own controller and an email will be sent only once.
add a comment |
Magento uses MagentoSalesModelOrderEmailSenderOrderSender
to send order emails.
I would suggest replacing OrderService
dependency in the MagentoQuoteObserverWebapiSubmitObserver
by your own implementation via di.xml in the following way:
class CustomOrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
{
public function send(Order $order, $forceSyncMode = false)
{
// custom implementation
}
}
and specify it in di.xml:
<type name="MagentoQuoteObserverWebapiSubmitObserver">
<arguments>
<argument name="orderSender" xsi:type="object">NSCustomOrderSender</argument>
</arguments>
</type>
So, you don't need to use your own controller and an email will be sent only once.
Magento uses MagentoSalesModelOrderEmailSenderOrderSender
to send order emails.
I would suggest replacing OrderService
dependency in the MagentoQuoteObserverWebapiSubmitObserver
by your own implementation via di.xml in the following way:
class CustomOrderSender extends MagentoSalesModelOrderEmailSenderOrderSender
{
public function send(Order $order, $forceSyncMode = false)
{
// custom implementation
}
}
and specify it in di.xml:
<type name="MagentoQuoteObserverWebapiSubmitObserver">
<arguments>
<argument name="orderSender" xsi:type="object">NSCustomOrderSender</argument>
</arguments>
</type>
So, you don't need to use your own controller and an email will be sent only once.
answered Nov 17 '17 at 20:30
joni jonesjoni jones
1,836414
1,836414
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f202001%2forder-confirmation-email-sent-before-redirecting-to-third-party-payment-gateway%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown