protected function _getBuildPaymentObject($quoteObj, $params = array('payment' => array())) { $payment = new Varien_Object(); if (isset($params['payment']) && !empty($params['payment'])) { $payment->addData($params['payment']); } if (Mage::helper('sagepaysuite')->creatingAdminOrder()) { $payment->addData($quoteObj->getPayment()->toArray()); } $payment->setTransactionType(strtoupper($this->getConfigData('payment_action'))); $payment->setAmountOrdered($this->formatAmount($quoteObj->getGrandTotal(), $quoteObj->getQuoteCurrencyCode())); $payment->setRealCapture(true); //To difference invoice from capture $payment->setOrder(clone $quoteObj); $payment->setAnetTransType(strtoupper($this->getConfigData('payment_action'))); $payment->getOrder()->setOrderCurrencyCode($quoteObj->getQuoteCurrencyCode()); $payment->getOrder()->setBillingAddress($quoteObj->getBillingAddress()); if ($quoteObj->isVirtual()) { $payment->getOrder()->setShippingAddress($quoteObj->getBillingAddress()); } else { $payment->getOrder()->setShippingAddress($quoteObj->getShippingAddress()); } return $payment; }
/** * 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.')); } }
/** * refund the amount with transaction id * * @param string $payment Varien_Object object * @return Mage_Paygate_Model_Authorizenet * @throws Mage_Core_Exception */ public function refund(Varien_Object $payment, $amount) { if ($payment->getRefundTransactionId() && $amount > 0) { $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT); $request = $this->_buildRequest($payment); $request->setXTransId($payment->getRefundTransactionId()); /** * need to send last 4 digit credit card number to authorize.net * otherwise it will give an error */ $request->setXCardNum($payment->getCcLast4()); $result = $this->_postRequest($request); if ($result->getResponseCode() == self::RESPONSE_CODE_APPROVED) { $payment->setStatus(self::STATUS_SUCCESS); return $this; } Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText())); } Mage::throwException(Mage::helper('paygate')->__('Error in refunding the payment.')); }
/** * 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; }
/** * 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) { $error = false; if ($payment->getRefundTransactionId() && $amount > 0) { $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT); $request = $this->_buildRequest($payment); $request->setXTransId($payment->getRefundTransactionId()); $result = $this->_postRequest($request); if ($result->getResponseCode() == self::RESPONSE_CODE_APPROVED) { $payment->setStatus(self::STATUS_SUCCESS); } else { $error = $result->getResponseReasonText(); } } else { $error = AO::helper('paygate')->__('Error in refunding the payment'); } if ($error !== false) { AO::throwException($error); } return $this; }
protected function _getBuildPaymentObject($quoteObj, $params = array('payment' => array())) { $payment = new Varien_Object(); if (isset($params['payment'])) { $payment->addData($params['payment']); } $billingAddressObj = $this->_getQuote()->getBillingAddress(); $shippingAddressObj = $this->_getQuote()->getShippingAddress(); $payment->setTransactionType(strtoupper($this->getConfigData('payment_action'))); $payment->setAmountOrdered($this->formatAmount($this->_getQuote()->getGrandTotal(), $this->_getQuote()->getQuoteCurrencyCode())); $payment->setRealCapture(true); //To difference invoice from capture $payment->setOrder(new Varien_Object($this->_getQuote()->toArray())); $payment->setAnetTransType(strtoupper($this->getConfigData('payment_action'))); $payment->getOrder()->setOrderCurrencyCode($this->_getQuote()->getQuoteCurrencyCode()); $payment->getOrder()->setBillingAddress($this->_getQuote()->getBillingAddress()); $payment->getOrder()->setShippingAddress($this->_getQuote()->getShippingAddress()); return $payment; }
/** * 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() && $amount > 0) { $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT); $request = $this->_buildRequest($payment); $result = $this->_postRequest($request); if ($result->getResponseCode() == self::RESPONSE_CODE_APPROVED) { $payment->setStatus(self::STATUS_SUCCESS); } else { $payment->setStatus(self::STATUS_ERROR); $payment->setStatusDescription($result->getResponseReasonText()); } } else { $payment->setStatus(self::STATUS_ERROR); $payment->setStatusDescription(Mage::helper('paygate')->__('Error in refunding the payment')); } return $this; }