Magento: Paypal Express Checkout Showing Empty Order Data [FIXED]

I am using Magento verion 1.4.0.1 and I had this issue. I had enabled Paypal Express Checkout payment method. When I choose this method on checkout, I was redirected to Paypal website but order data was not displayed there.

The main reason in my case was due to applied discount to the cart. I had created a shopping cart price rule and applied it to the cart. And, when I choose Paypal Express Checkout as payment method, the paypal website would show empty order data.

However, if I don’t apply discount to the cart, then everything is okay. While choosing Paypal Express, I am redirected to Paypal website and I could see order details there.

So, I reckon this issue to be related with discount / promotion rule applied to cart.

SOLUTION / FIX

To solve this issue, I created local copy of two files of core Paypal module. Creating local copy means copying files from ‘core‘ folder to ‘local‘ folder maintaining the same folder structure.

I copied these two core files:-

– app/code/core/Mage/Paypal/Helper/Data.php
– app/code/core/Mage/Paypal/Model/Express/Checkout.php

To this local folder location:-

– app/code/local/Mage/Paypal/Helper/Data.php
– app/code/local/Mage/Paypal/Model/Express/Checkout.php

After that, I made some changes to these files.

1) Changes made on app/code/local/Mage/Paypal/Helper/Data.php

– Commented some lines of code and added new lines of code
– In Magento 1.4.0.1, the code to comment is present from line #203


public function start($returnUrl, $cancelUrl)
{
	...
	....
	.....
	
	// COMMENT THESE LINES
	// add line items
        /* if ($this->_config->lineItemsEnabled && Mage::helper('paypal')->doLineItemsMatchAmount($this->_quote, $this->_quote->getBaseGrandTotal())) {//For transfering line items order amount must be equal to cart total amount
            list($items, $totals) = Mage::helper('paypal')->prepareLineItems($this->_quote);
            $this->_api->setLineItems($items)->setLineItemTotals($totals);
        } */
        
	// ADD THESE LINES
        if ($this->_config->lineItemsEnabled) {
        	list($items, $totals) = Mage::helper('paypal')->prepareLineItems($this->_quote);
        	if (Mage::helper('paypal')->areCartLineItemsValid($items, $totals, $this->_quote->getBaseGrandTotal())) {
        		$this->_api->setLineItems($items)->setLineItemTotals($totals);
        	}
        }

	...
	....
	.....
}

2) Added a new function on app/code/local/Mage/Paypal/Model/Express/Checkout.php


/**
 * Check whether cart line items are eligible for exporting to PayPal API
 *
 * Requires data returned by self::prepareLineItems()
 *
 * @param array $items
 * @param array $totals
 * @param float $referenceAmount
 * @return bool
 */
public function areCartLineItemsValid($items, $totals, $referenceAmount)
{
	$sum = 0;
	foreach ($items as $i) {
		$sum = $sum + $i['qty'] * $i['amount'];
	}
	/**
	 * numbers are intentionally converted to strings because of possible comparison error
	 * see http://php.net/float
	 */
	return sprintf('%.4F', ($sum + $totals['shipping'] + $totals['tax'])) == sprintf('%.4F', $referenceAmount);
}

Hope it helps. Thanks.