Is there a way to add the order# to a payment Transaction Failed email?

This is what I tried:

{* This is a comment block

Use vars: {{var var_name}}
*}<!--@subject Payment Transaction Failed Reminder @-->
{"var reason":"Transaction Failed Reason",
"var checkoutType":"Checkout Type",
"var customerEmail":"Customer Email",
"var customer":"Customer Name",
"var items":"Shopping Cart Items",
"var total":"Total",
"var billingAddress.format('html')":"Billing Address",
"var shippingAddress.format('html')":"Shipping Address",
"var shippingMethod":"Shipping Method",
"var paymentMethod":"Payment Method",
"var dateAndTime":"Date and Time of Transaction"
"var order.increment_id":"order_id"}

            <th>Payment transaction failed.</th>
                    <b>Order Number:</b><br />
                    {{var order_id}}
                    <b>Reason</b><br />
                    {{var reason}}

            <!-- snipped rest of template -->

However, no order# came through...Even tried using the QUOTE reserved_order_id:

"var reserved_order_id":"order_id"

Still nothing.

2 Answers 2


you can do this easy In paypal payment if order payment becomes failed then it set revered order id null, so

goto copy




Here you will find the filler payment mail function sendPaymentFailedEmail().

add new parameters to mail to which will send order id and order increment id

and here $checkout give quote object you.

so i load order collection and filter by current quote id and sort by order id(entity_id) desc.


then get last order id of this quote.

$lastetOrderIncrementId= $SalesCollection->getFirstItem()->getIncrementId();

and end this parameter in email template

'lastetorderid' => $lastetOrderId,
 'lastetorderincrementid' => $lastetOrderIncrementId,

and on payment failed mail html template get this params by

var lastetorderid
var lastetorderincrementid

and this code


"var lastetorderid":"Order id",
"var lastetorderincrementid":"order increment",


"var shippingAddress.format('html')":"Shipping Address",

You don't get an order id in the payment failed e-mail because the order object is not created yet and the order id is not reserved for the quote.
if the error that triggers the payment failed email happens after the order is saved you will get an order id. But the chance of this happening is close to 0.

The order id is reserved in the order saving process. In Mage_Sales_Model_Service_Quote::submitOrder() there is this $quote->reserveOrderId();.

I don't know why you would need an order id in the payment failed template because there will be no order if that happens. So your number will be useless, but if you really need it here is what you can do.

You need to rewrite the method Mage_Checkout_Helper_Data::sendPaymentFailedEmail and reserve the order id if it's not already reserved before the e-mail is sent.
for that create a module.
Lets call it Easylife_Checkout.
You will need the following files:

app/etc/modules/Easylife_Checkout.xml - the declaration file

<?xml version="1.0"?>
                <Mage_Checkout /><!-- depends on the checkout module -->

app/code/local/Easylife/Checkout/etc/config.xml - the configuration file

<?xml version="1.0"?>
                    <data>Easylife_Checkout_Helper_Data</data><!-- rewrite the chekcout helper -->

app/code/local/Easylife/Checkout/Helper/Data.php - the rewritten helper

class Easylife_Checkout_Helper_Data extends Mage_Checkout_Helper_Data {
    public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage') {
        $reservedOrderId = $checkout->getReservedOrderId();
        if (!$reservedOrderId) {
        return parent::sendPaymentFailedEmail($checkout, $message, $checkoutType);
  • I don't know why you would need an order id in the payment failed template because there will be no order if that happens I really forgot about that. I guess I'll just drop it.
    – MB34
    Sep 10, 2014 at 13:58
  • @MB34. What do you mean you'll drop it? after all the time I spent writing this answer... :). Just kidding. I would drop it also.
    – Marius
    Sep 10, 2014 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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