Magento – Add an extra fee to paypal standard

billingmagento-1.8magento-1.9payment-methodspaypal-standard

enter image description here

i am add some extra fee in cart on base of some special conditions.It's work fine all all place in magento but now i think about add this fee to paypal standard.I am successful but it works only if Transfer Cart Line Items = No.

I want to work it where Transfer Cart Line Items = yes in paypal option.

Now i want one row on paypal bill with fee lable & value.

Paypal standard bill with Transfer Cart Line Items SET yes

It can come with tax and item total or items and shipping both option are good for me.
Can any body help me?

Best Answer

I've managed to add extra lines in PayPal Standard cart using the paypal_prepare_line_items event.

In your module's config.xml:

<config>
    <global>
        <events>
            <paypal_prepare_line_items>
                <observers>
                    <paypal_prepare_line_items>
                        <class>your_module/observer</class>
                        <method>updatePaypalTotal</method>
                    </paypal_prepare_line_items>
                </observers>
            </paypal_prepare_line_items>
        </events>
    </global>
</config>

In your observer:

class Your_Module_Model_Observer
{
    public function updatePaypalTotal(Varien_Event_Observer $observer)
    {
        $feeAmount = <calculated somewhere...>

        /* @var $cart Mage_Paypal_Model_Cart */
        $cart = $observer->getEvent()->getPaypalCart();

        $cart->addItem('Fee label', 1, $feeAmount, 'fee');

        return $this;
    }
}
Related Topic