Paypal gateway has rejected request magento solved

11:49 AM
How To Fix Paypal gateway has rejected request. The totals of the cart item amounts do not match order amounts (#10413: Transaction refused because of an invalid argument. See additional error messages for details).

Solution:

The first step is to copy the Abstract.php file from app/code/core/Mage/Paypal/Model/Api/ 
to 
app/code/local/Mage/Paypal/Model/Api/
You can make these changes directly to the core file if you really have to, but it's not recommended. 




//Find the

 _exportLineItems function

//(line 390 in my version 1.9)


//Before the foreach ($items as $item) { (around line 412) add this:

$running_total = 0;

//Before the $request[sprintf($privateFormat, $i)] = $value; (around line 423) add this:

if ($publicKey == 'amount') {
    $running_total += $value;
}

//Before the return $result; (around line 427) add this:

// Check ITEMAMT. If different to running total, offset prices
if ((isset($request['ITEMAMT'])) && ($request['ITEMAMT'] > 0)) {
    if ($running_total <> (float) $request['ITEMAMT']) {
        $difference = ($running_total - (float) $request['ITEMAMT']);
        // Apply difference to first product.
        $request['L_AMT0'] = (string) ((float) $request['L_AMT0'] - $difference);
    }
}

I am Web Developer and Web Designer. Also Part Time Blogger. Love To Code in HTML, CSS, JS, jQuery, Bootstrap, PHP, WordPress, Magento.

RELATED POSTS

Previous
Next Post »