Magento添加折扣语用显​​示Paypal结帐的错误

I am facing one problem when i try to add discount to cart pragmatically i am able to do that but then user try to fill creditcard then paypal shows error :

PayPal Error 10413 ( " 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 " )

please let me know if anyone know.

If you adding discount by your custom module then you have to add paypal's event. So in your module's Config.xml add new Event for paypal_prepare_line_items.

Like:-

<events>
        <paypal_prepare_line_items>
            <observers>
                <paypal_prepare_line_items>
                    <class>Your_Module_Name/observer</class>
                    <method>updatePaypalTotal</method>
                </paypal_prepare_line_items>
            </observers>
        </paypal_prepare_line_items>
 </events>

Now you have to create a observer class in your module and then create a new function updatePaypalTotal in that

In observer.php

public function updatePaypalTotal(Varien_Event_Observer $observer)
{
    $cart = $observer->getEvent()->getPaypalCart();
    $new_amount = '10'; // This is your Discount amount.
    $cart->updateTotal(Mage_Paypal_Model_Cart::TOTAL_DISCOUNT, $new_amount);

    return $this;
}

Let me know if you have any query.

please check your code is this possible you are adding something extra in in $address-> section

otherwise everything works fine. or please paste your code