/** * refund the amount with transaction id * * @access public * @param string $payment Varien_Object object * @return Mage_Payment_Model_Abstract */ public function refund(Varien_Object $payment, $amount) { if ($payment->getCcTransId() && $payment->getAmount() > 0) { $api = $this->getApi(); //we can refund the amount full or partial so it is good to set up as partial refund $api->setTransactionId($payment->getCcTransId())->setRefundType(Mage_Paypal_Model_Api_Nvp::REFUND_TYPE_PARTIAL)->setAmount($amount); if ($api->callRefundTransaction() !== false) { $payment->setStatus('SUCCESS')->setCcTransId($api->getTransactionId()); } else { $e = $api->getError(); $payment->setStatus('ERROR')->setStatusDescription($e['short_message'] . ': ' . $e['long_message']); } } else { $payment->setStatus('ERROR'); $payment->setStatusDescription(Mage::helper('paypal')->__('Error in refunding the payment')); } }