How to get Paypal Fee

Hello folks

As far as you know Magento has built-in Paypal extension that allows us to use paypal out of the box. If you are seller you should know that Paypal has fees for each transaction it's something like 2.9% + $0.30. You can find more detailed info there Fees to Send and Receive Money.

But Magento doesn't display that fees value anywhere. So assume that your client wants to see that data. Sure you can calculate it on the fly on Magento side using formula mentioned above but the big question is can we calculate it accurately to the penny? Answer is 'No', judging from my experience.

So in this article I'll show you how to get that data from PayPal API. So first you need to get order and payment objects, see below:

$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$payment = $order->getPayment();

$orderId is incremental ID of you order, you can use also just load($id) function and load order by internal ID. Then getPayment function returns current payment method object in our cause it should be PayPal one.You can check it easily by the following condition if ($payment->getMethod() == 'paypal_express').... After these steps you need just run the following code:

$transactionDetails = $payment->getMethodInstance()->setStore($order->getStoreId())->fetchTransactionInfo($payment, $payment->getLastTransId());
$fee = $transactionDetails['FEEAMT'];

That's it. Note: this solution is tested only with built-in Magento PayPal extension.

Blog Comments powered by Disqus.