示例#1
0
 /**
  * @param Varien_Object $payment
  * @param float         $amount
  *
  * @return $this|Mage_Payment_Model_Abstract
  */
 public function refund(Varien_Object $payment, $amount)
 {
     //RY - fix for shop currency transactions being refunded in base currency amount
     $transactionCurrencyMode = (string) $this->getConfigData('trncurrency');
     if ($transactionCurrencyMode == 'store' or $transactionCurrencyMode == 'switcher') {
         $creditmemo = Mage::registry('current_creditmemo');
         $amount = (string) Mage::app()->getStore()->roundPrice($creditmemo->getGrandTotal());
     }
     $order = $payment->getOrder();
     $trn = $this->getTransactionDetails($order->getId());
     if (!$trn->getId()) {
         $msg = $this->_getCoreHelper()->__('Transaction does not exist, order id -> %s', $order->getId());
         self::log($msg);
         Mage::throwException($msg);
     }
     /**
      * If we are REFUNDing a FORM transaction we HAVE to retrieve the
      * SecurityKey from the "Admin & Access API"
      */
     if (!$trn->getSecurityKey() && strtoupper($trn->getIntegration()) == 'FORM') {
         $this->_addSecurityKey($trn);
     }
     $paymentId = Mage::app()->getRequest()->getParam('sagepaysuiterefundtrn');
     if (!is_null($paymentId)) {
         $action = Mage::getModel('sagepaysuite2/sagepaysuite_action')->load((int) $paymentId);
         if ($action->getVpsTxId() && $action->getSecurityKey() && $action->getTxAuthNo()) {
             $trn->setVpsTxId($action->getVpsTxId())->setSecurityKey($action->getSecurityKey())->setTxAuthNo($action->getTxAuthNo())->setVendorTxCode($action->getVendorTxCode());
         }
     }
     //@TODO: If it is PAYPAL dont VOID
     //VOID payment if refunding full amount
     if ($this->floatsEqual($order->getGrandTotal(), $payment->getCreditmemo()->getGrandTotal())) {
         try {
             $this->voidPayment($trn);
             return $this;
         } catch (Exception $e) {
             Sage_Log::logException($e);
         }
     }
     $data = array();
     $data['VPSProtocol'] = $trn->getVpsProtocol();
     $data['TxType'] = self::REQUEST_TYPE_REFUND;
     $data['ReferrerID'] = $this->getConfigData('referrer_id');
     $data['Vendor'] = $trn->getVendorname();
     $data['VendorTxCode'] = substr(time(), 0, 30) . substr($trn->getVendorTxCode(), 0, 10);
     $data['Amount'] = $this->formatAmount($amount, $trn->getTrnCurrency());
     $data['Currency'] = $trn->getTrnCurrency();
     $data['Description'] = '.';
     $data['RelatedVPSTxId'] = $trn->getVpsTxId();
     $data['RelatedVendorTxCode'] = $trn->getVendorTxCode();
     $data['RelatedSecurityKey'] = $trn->getSecurityKey();
     $data['RelatedTxAuthNo'] = $trn->getTxAuthNo();
     //$data['RelatedSecurityKey']  = (isset($formSecKey) ? $formSecKey : $trn->getSecurityKey());
     if (strtoupper($trn->getTxType()) == self::REQUEST_TYPE_AUTHENTICATE && is_null($paymentId)) {
         $lastAuthorise = Mage::getModel('sagepaysuite2/sagepaysuite_action')->getLastAuthorise($order->getId());
         if (is_null($lastAuthorise->getId())) {
             Mage::throwException('AUTHORISE transaction not found. Refund online cannot be completed.');
         }
         $data['RelatedVPSTxId'] = $lastAuthorise->getVpsTxId();
         $data['RelatedVendorTxCode'] = $lastAuthorise->getVendorTxCode();
         $data['RelatedSecurityKey'] = $lastAuthorise->getSecurityKey();
         $data['RelatedTxAuthNo'] = $lastAuthorise->getTxAuthNo();
     }
     $result = $this->requestPost($this->getUrl('refund', false, $this->_getIntegrationCode($trn->getIntegration()), $trn->getMode()), $data);
     if ($result['Status'] != 'OK') {
         Sage_log::log($result['StatusDetail']);
         Mage::throwException(Mage::helper('sagepaysuite')->__($result['StatusDetail']));
     }
     //For saving purposes
     $result['Amount'] = $data['Amount'];
     $this->saveAction($order->getId(), $data, $result);
     return $this;
 }
 private function _returnInvalid($message = 'Unable to find the transaction in our database.')
 {
     header('Content-type: text/plain');
     $response = 'Status=INVALID' . $this->eoln;
     $response .= 'RedirectURL=' . $this->_getFailedRedirectUrl() . '?SID=' . $this->getRequest()->getParam('SID', '') . $this->eoln;
     $response .= 'StatusDetail=' . $message . $this->eoln;
     Sage_Log::log($message);
     Sage_Log::log($this->getRequest()->getPost());
     Sage_log::log($this->_getSagePayServerSession()->getData());
     Sage_Log::log("[MOTO] " . $response, null, 'SagePaySuite_SERVER_RESPONSE.log');
     echo $response;
     exit;
 }
 private function _returnInvalid($message = 'Unable to find the transaction in our database.')
 {
     $response = 'Status=INVALID' . $this->eoln;
     $response .= 'RedirectURL=' . $this->_getFailedRedirectUrl() . $this->eoln;
     $response .= 'StatusDetail=' . $message . $this->eoln;
     if (!$this->_getSagePayServerSession()->getFailStatus()) {
         $this->_getSagePayServerSession()->setFailStatus($message);
     }
     Sage_Log::log($message);
     Sage_Log::log($this->getRequest()->getPost());
     Sage_log::log($this->_getSagePayServerSession()->getData());
     $this->getResponse()->setHeader('Content-type', 'text/plain');
     $this->getResponse()->setBody($response);
     return;
 }
 private function _returnInvalid($message = 'Unable to find the transaction in our database.')
 {
     $response = 'Status=INVALID' . $this->eoln;
     $response .= 'RedirectURL=' . $this->_getFailedRedirectUrl() . $this->eoln;
     $response .= 'StatusDetail=' . $message . $this->eoln;
     if (!$this->_getSagePayServerSession()->getFailStatus()) {
         $this->_getSagePayServerSession()->setFailStatus($message);
     }
     Sage_Log::log($message);
     Sage_Log::log($this->getRequest()->getPost());
     Sage_log::log($this->_getSagePayServerSession()->getData());
     Mage::dispatchEvent('sagepay_payment_failed', array('quote' => $this->getOnepage()->getQuote(), 'message' => $message));
     $this->getResponse()->setHeader('Content-type', 'text/plain');
     $this->getResponse()->setBody($response);
     Sage_Log::log($response, null, 'SagePaySuite_SERVER_RESPONSE.log');
     return;
 }