/** * refund the amount with transaction id * * @param string $payment Varien_Object object * @return Mage_Authorizenet_Model_Directpost * @throws Mage_Core_Exception */ protected function _refund(Varien_Object $payment, $amount) { if ($amount <= 0) { Mage::throwException(Mage::helper('paygate')->__('Invalid amount for refund.')); } if (!$payment->getParentTransactionId()) { Mage::throwException(Mage::helper('paygate')->__('Invalid transaction ID.')); } $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT); $payment->setAmount($amount); $payment->setXTransId($this->_getRealParentTransactionId($payment)); $request = $this->_buildRequest($payment); $result = $this->_postRequest($request); switch ($result->getResponseCode()) { case self::RESPONSE_CODE_APPROVED: if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) { if ($result->getTransactionId() != $payment->getParentTransactionId()) { $payment->setTransactionId($result->getTransactionId()); } $shouldCloseCaptureTransaction = $payment->getOrder()->canCreditmemo() ? 0 : 1; $payment->setIsTransactionClosed(1)->setShouldCloseParentTransaction($shouldCloseCaptureTransaction)->setTransactionAdditionalInfo($this->_realTransactionIdKey, $result->getTransactionId()); return $this; } Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText())); case self::RESPONSE_CODE_DECLINED: case self::RESPONSE_CODE_ERROR: Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText())); default: Mage::throwException(Mage::helper('paygate')->__('Payment refunding error.')); } }
/** * Send capture request to gateway * * @param Varien_Object $payment * @param decimal $amount * @return Start_Gateway_Model_Paymentmethod * @throws Mage_Core_Exception */ public function capture(Varien_Object $payment, $amount) { if ($amount <= 0) { Mage::throwException('Invalid amount for capture.'); } $payment->setAmount($amount); if ($payment->getParentTransactionId()) { $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE); $payment->setXTransId($this->_getRealParentTransactionId($payment)); } else { $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_CAPTURE); } //please call this function or some function to call API with token and email to capture authorized amount //$this->collectPayment($payment, $amount); //returning this as all good but it should return $this in case success and throw exception in case of error return $this; }