getting the grand total and email using order id in magento

getting the grand total and email using order id in magento

August 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
getting the grand total and email using order id in magento

Solving Magento Grand Total and Email Retrieval Issue on Redirect

Dear developers,

I recently encountered an intriguing challenge while working on a Magento e-commerce platform integration. The issue revolved around retrieving the grand total of a customer’s cart and their email using the order ID, only to find that upon redirecting to the bank payment gateway, the system reported an “invalid amount” error due to sending empty parameters.

Understanding the Problem

The problem stemmed from the form submission process in the redirect file. The code correctly attempted to retrieve the necessary data—order total using $_order->getBaseGrandTotal(), order ID using Mage::getSingleton('checkout/session')->getLastRealOrderId(), and customer email via Mage::getSingleton('customer/session')->getCustomer()->getEmail().

However, the issue lay in how these values were being passed to the form fields. The form fields, as per the provided code, are named “amt” for the total amount and “email” for the customer’s email address.

<form method="post">
  <input type="hidden" name="amt" value="<?php echo $_order->getBaseGrandTotal(); ?>">
  <input type="hidden" name="orderId" value="<?php echo $orderId; ?>">
  <input type="hidden" name="email" value="<?php echo Mage::getSingleton('customer/session')->getCustomer()->getEmail() ; ?>">
</form>

The Root Cause

Upon closer inspection, I realized the problem wasn’t with the data retrieval but with how Magento’s checkout process handles the redirection to the payment gateway. It seems that when the order is placed and the customer is redirected to the gateway, certain parameters need to be sent in a specific format.

The key lies in ensuring that the total amount parameter matches exactly what the payment gateway expects. In many cases, the gateway may require a currency code appended to the amount value or expect it in a formatted string rather than a raw float number.

The Solution Approach

To resolve this issue effectively, I suggest implementing the following best practices:

  1. Currency Formatting: Ensure that the total amount being sent includes the currency code expected by the payment gateway. You can achieve this by using the Mage::app()->getStore() method to fetch the currency code and append it to your grand total value.
$amount = $_order->getBaseGrandTotal() . Mage::app()->getStore()->getCurrentCurrencyCode();
  1. Parameter Formatting: Check if the payment gateway expects specific formatting for the amount parameter, such as a string or a number with a decimal point. You can use PHP’s number_format() function to format the amount according to these requirements.

  2. Order ID and Email Validation: Ensure that both the order ID and the email are properly encoded or validated before being sent in the form fields. This step is crucial to prevent any unexpected errors during data transmission.

Conclusion

In summary, retrieving the grand total, order ID, and customer email using Magento’s session objects is a straightforward process. However, when integrating with external payment gateways, it is essential to understand the specific requirements for parameter formatting and value expectations.

By following the best practices outlined above—ensuring currency formatting, proper parameter formatting, and data validation—you can effectively resolve issues related to empty parameters being sent during redirection.

Remember, every payment gateway has its unique set of rules. Always consult their documentation or support channels to ensure a smooth integration process.

If you’re looking for more in-depth guides on Magento development, I recommend checking out our comprehensive resources at Laravel Company. We provide detailed tutorials and best practices to help you master the art of e-commerce development using Magento.

Happy coding!

Checkout Email Orders Customers

Our network