Example #1
0
 /**
  * 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.'));
 }
Example #2
0
 /**
  * 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) {
         $api = $this->getApi();
         //we can refund the amount full or partial so it is good to set up as partial refund
         $api->setTransactionId($payment->getRefundTransactionId())->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();
             $error = $e['short_message'] . ': ' . $e['long_message'];
         }
     } else {
         $error = AO::helper('paypal')->__('Error in refunding the payment');
     }
     if ($error !== false) {
         AO::throwException($error);
     }
     return $this;
 }
Example #3
0
 public function refund(Varien_Object $payment, $amount)
 {
     $error = false;
     if ($payment->getRefundTransactionId() && $amount > 0) {
         $api = $this->getApi()->setTransactionId($payment->getRefundTransactionId())->setPayment($payment)->setAmount($amount);
         if ($api->refund() !== false) {
             $payment->setCcTransId($api->getTransactionId());
             $payment->setStatus(self::STATUS_SUCCESS);
         } else {
             $e = $api->getError();
             $error = $e['message'];
         }
     } else {
         $error = Mage::helper('paypalUk')->__('Error in refunding the payment');
     }
     if ($error !== false) {
         Mage::throwException($error);
     }
     return $this;
 }
Example #4
0
 /**
  * Refund the payment transaction
  *
  * @param Mage_Sale_Model_Order_Payment $payment
  * @param flaot $amount
  * @return Mage_Cybersource_Model_Soap
  */
 public function refund(Varien_Object $payment, $amount)
 {
     $error = false;
     if ($payment->getRefundTransactionId() && $payment->getRefundCybersourceToken() && $amount > 0) {
         $soapClient = $this->getSoapApi();
         $this->iniRequest();
         $ccCreditService = new stdClass();
         $ccCreditService->run = "true";
         $ccCreditService->captureRequestToken = $payment->getCybersourceToken();
         $ccCreditService->captureRequestID = $payment->getCcTransId();
         $this->_request->ccCreditService = $ccCreditService;
         $purchaseTotals = new stdClass();
         $purchaseTotals->grandTotalAmount = $amount;
         $this->_request->purchaseTotals = $purchaseTotals;
         try {
             $result = $soapClient->runTransaction($this->_request);
             if ($result->reasonCode == self::RESPONSE_CODE_SUCCESS) {
                 $payment->setLastTransId($result->requestID)->setLastCybersourceToken($result->requestToken);
             } else {
                 $error = Mage::helper('cybersource')->__('There is an error in processing payment. Please try again or contact us.');
             }
         } catch (Exception $e) {
             Mage::throwException(Mage::helper('cybersource')->__('Gateway request error: %s', $e->getMessage()));
         }
     } else {
         $error = Mage::helper('cybersource')->__('Error in refunding the payment');
     }
     if ($error !== false) {
         Mage::throwException($error);
     }
     return $this;
 }
 /**
  * Refund
  */
 public function refund(Varien_Object $payment, $amount)
 {
     if (!$this->canRefund()) {
         Mage::throwException('Unable to refund.');
     }
     $order = $payment->getOrder();
     $result = $this->_getApi()->refund($payment->getRefundTransactionId(), $this->_getMagentoReferenceId($payment) . substr(md5($this->_getMagentoReferenceId($payment) . microtime()), -4) . '-refund', $amount, $order->getBaseCurrencyCode(), null, $this->_getSoftDescriptor());
     $payment->setTransactionId($result->getAmazonRefundId());
     $payment->setParentTransactionId($payment->getRefundTransactionId());
     $message = Mage::helper('payment')->__('A refund request for %s sent to Amazon Payments.', $order->getStore()->convertPrice($amount, true, false));
     $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, null, false, $message);
     return $this;
 }
Example #6
0
 /**
  * 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;
 }
 /**
  * Refunds specified amount
  * 
  * @param Varien_Object $payment
  * @param decimal $amount
  * @return Braintree_Payments_Model_Paymentmethod
  */
 public function refund(Varien_Object $payment, $amount)
 {
     $transactionId = Mage::helper('braintree_payments')->clearTransactionId($payment->getRefundTransactionId());
     try {
         $transaction = Braintree_Transaction::find($transactionId);
         $this->_debug($payment->getCcTransId());
         $this->_debug($transaction);
         if ($transaction->status === Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             if ($transaction->amount != $amount) {
                 Mage::throwException(Mage::helper('braintree_payments')->__('This refund is for a partial amount but the Transaction has not settled. ' . 'Please wait 24 hours before trying to issue a partial refund.'));
             } else {
                 Mage::throwException(Mage::helper('braintree_payments')->__('The Transaction has not settled. ' . 'Please wait 24 hours before trying to issue a refund or use Void option.'));
             }
         }
         if ($transaction->status === Braintree_Transaction::SETTLED || $transaction->status === Braintree_Transaction::SETTLING) {
             $result = Braintree_Transaction::refund($transactionId, $amount);
         } else {
             $result = Braintree_Transaction::void($transactionId);
         }
         $this->_debug($result);
         if ($result->success) {
             $payment->setIsTransactionClosed(1);
         } else {
             Mage::throwException(Mage::helper('braintree_payments/error')->parseBraintreeError($result));
         }
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('braintree_payments')->__('There was an error refunding the transaction.') . ' ' . $e->getMessage());
     }
     return $this;
 }
Example #8
0
 /**
  * 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->setTransactionId($payment->getRefundTransactionId());
         $payment->setTrxtype(self::TRXTYPE_CREDIT);
         $request = $this->_buildBasicRequest($payment);
         $request->setAmt(round($amount, 2));
         $result = $this->_postRequest($request);
         if ($this->getConfigData('debug')) {
             $payment->setCcDebugRequestBody($result->getRequestBody())->setCcDebugResponseSerialized(serialize($result));
         }
         if ($result->getResultCode() == self::RESPONSE_CODE_APPROVED) {
             $payment->setStatus(self::STATUS_SUCCESS);
             $payment->setCcTransId($result->getPnref());
         } else {
             $error = $result->getRespmsg() ? $result->getRespmsg() : Mage::helper('paygate')->__('Error in refunding the payment.');
         }
     } else {
         $error = Mage::helper('paygate')->__('Error in refunding the payment');
     }
     if ($error !== false) {
         Mage::throwException($error);
     }
     return $this;
 }
 /**
  * called if refunding
  */
 public function refund(Varien_Object $payment, $amount)
 {
     $txid = $payment->getRefundTransactionId();
     $profile = $this->_profile->Refund($payment, $amount);
     Mage::helper('paymentech')->Log("--------------refund profile--------------------");
     Mage::helper('paymentech')->Log(print_r($profile, true));
     Mage::helper('paymentech')->Log("--------------end refund profile--------------------");
     if ($profile->getResponse()->error) {
         foreach ($profile->getResponse()->error as $error) {
             Mage::helper('paymentech')->Log($error, Zend_Log::ERR);
             Mage::throwException($error);
         }
         return $this;
     }
     $payment->setTransactionId($txid);
     return $this;
 }
Example #10
0
 public function refund(Varien_Object $payment, $amount)
 {
     $payment->setAmount($amount);
     $payment->setOpcode(self::OPCODE_REFUND);
     $this->setTransactionId($payment->getRefundTransactionId());
     $request = $this->_buildRequest($payment);
     $result = $this->_postRequest($request);
     $payment->setStatus(self::STATUS_APPROVED);
     $payment->setLastTransId($result->getTransaction());
     return $this;
 }
Example #11
0
 /**
  * Called before the request is processed
  *
  * @param string $request
  * @param mixed $options
  * @param Varien_Object $payment
  */
 protected function _beforeProcessRequest($request, &$options, Varien_Object $payment)
 {
     switch ($request) {
         case 'capture':
             $options['origTrxNumber'] = $payment->getCcTransId() ? $payment->getCcTransId() : $payment->getLastTransId();
             break;
         case 'refund':
             $options['origTrxNumber'] = $payment->getRefundTransactionId();
             break;
     }
 }
Example #12
0
 /**
  * callApi is the major piece in the puzzle
  *
  * prepares information and call specific xml api
  *
  * @param object $payment Payment Object
  * @param int $amount Amount to charge
  * @param string $type either CIM or AIM
  * @param int $ccSaveId Used to determine whether or not a profile exists for the customer
  * @param int $tokenProfileId Checks if the payment profile already exists, if not, creates it
  */
 public function callApi(Varien_Object $payment, $amount, $type)
 {
     /**
      * =====================================================================
      * BEGIN AAI HACK
      *
      * Cleaned up so it would be a little easier to understand
      * =====================================================================
      */
     $order = $payment->getOrder();
     $orderId = $order->getIncrementId();
     $postData = Mage::app()->getRequest()->getPost('payment', array());
     $ccSaveId = array_key_exists('ccsave_id', $postData) ? $postData['ccsave_id'] : null;
     if ($type != 'authorizeandcaptureAIM') {
         $customerID = $order->getCustomerId();
         // for Guests, set the customerId to the Order's increment_id
         if (!$customerID) {
             $customerID = $orderId;
         }
         // order values
         $customerEmail = $order->getCustomerEmail();
         $billingInfo = $order->getBillingAddress();
         $shippingInfo = $order->getShippingAddress();
         // payment values
         $ccType = $payment->getCcType();
         $ccNumber = $payment->getCcNumber();
         $ccExpDate = $payment->getCcExpYear() . '-' . str_pad($payment->getCcExpMonth(), 2, '0', STR_PAD_LEFT);
         $ccCCV = $payment->getCcCid();
         // CIM token values
         $tokenProfileId = $payment->getTokenProfileId();
         $tokenPaymentProfileId = $payment->getTokenPaymentProfileId();
         if ($tokenProfileId == 0 && $tokenPaymentProfileId == 0 && in_array($type, array('authorize', 'capture', 'authorizeandcapture'))) {
             if (!is_null($ccSaveId)) {
                 $profile = $this->getAuthnetcimCardProfileById($ccSaveId);
                 $profileData = $profile->getData();
                 $tokenProfileId = $profileData['token_profile_id'];
                 $tokenPaymentProfileId = $profileData['token_payment_profile_id'];
             } else {
                 $profileCollection = $this->getAuthnetcimCardProfilesByCustomerId($customerID);
                 if (count($profileCollection) === 0) {
                     // Create new customer profile
                     $responseXML = $this->createCustomerProfileRequest($customerID, $customerEmail, $billingInfo, $shippingInfo, $ccNumber, $ccExpDate, $ccCCV, $ccType);
                     $tokenProfileId = $responseXML->customerProfileId;
                     $tokenPaymentProfileId = $responseXML->customerPaymentProfileIdList->numericString;
                 } else {
                     $tokenProfileId = $profileCollection->getFirstItem()->getTokenProfileId();
                     $tokenPaymentProfileId = null;
                     $ccLast4 = substr($ccNumber, -4, 4);
                     foreach ($profileCollection as $profile) {
                         if ($profile->getData("cc_last4") == $ccLast4) {
                             $tokenPaymentProfileId = $profile->getData("token_payment_profile_id");
                         }
                     }
                     if (is_null($tokenPaymentProfileId)) {
                         $tokenPaymentProfileId = $this->createCustomerPaymentProfileRequest($customerID, $tokenProfileId, $billingInfo, $ccNumber, $ccExpDate, $ccCCV, $ccType);
                     }
                 }
             }
         }
     }
     /**
      * =====================================================================
      * END AAI HACK
      *
      * Cleaned up so it would be a little easier to understand
      * =====================================================================
      */
     // call xml creation functions
     switch ($type) {
         case 'authorize':
             $payment->setTokenProfileId($tokenProfileId);
             $payment->setTokenPaymentProfileId($tokenPaymentProfileId);
             $response = $this->createAuthorize($amount, $tokenProfileId, $tokenPaymentProfileId, $orderId, $ccCCV);
             break;
         case 'capture':
             $teoAuths = Mage::getModel('authorizenetcim/teoauths');
             $authsCollection = $teoAuths->getCollection()->addFieldToFilter('order_id', $orderId);
             if (count($authsCollection) > 1) {
                 $amountLeftToCapture = $amount;
                 foreach ($authsCollection as $auths) {
                     $teoAuths->load($auths->getId());
                     $teoAuthAmount = $teoAuths->getAuthorizationAmount();
                     $teoAuthAmountPaid = $teoAuths->getAmountPaid();
                     if ($amountLeftToCapture > 0) {
                         $amountLeftOnAuth = $teoAuthAmount - $teoAuthAmountPaid;
                         $authorizeTransactionId = $teoAuths->getAuthorizationNumber();
                         if ($amountLeftToCapture > $amountLeftOnAuth) {
                             $response = $this->createCapture($amountLeftOnAuth, $tokenProfileId, $tokenPaymentProfileId, $authorizeTransactionId);
                             $teoAuths->setAmountPaid($amountLeftOnAuth);
                             $teoAuths->save();
                             $amountLeftToCapture = $amountLeftToCapture - $amountLeftOnAuth;
                         } else {
                             $response = $this->createCapture($amountLeftToCapture, $tokenProfileId, $tokenPaymentProfileId, $authorizeTransactionId);
                             $teoAuths->setAmountPaid($amountLeftToCapture);
                             $teoAuths->save();
                             $amountLeftToCapture = 0;
                         }
                     }
                 }
             } else {
                 //get authorize transaction id for capture
                 $authorizeTransactionId = $payment->getCcTransId();
                 $response = $this->createCapture($amount, $tokenProfileId, $tokenPaymentProfileId, $authorizeTransactionId);
             }
             break;
             /**
              * =================================================================
              * BEGIN AAI HACK
              *
              * ADD SPECIFIC METHOD FOR PARTIAL AUTH/CAPTURE(S)
              * =================================================================
              */
         /**
          * =================================================================
          * BEGIN AAI HACK
          *
          * ADD SPECIFIC METHOD FOR PARTIAL AUTH/CAPTURE(S)
          * =================================================================
          */
         case 'partialcapture':
             $teoAuth = $this->getTeoAuthorizationByOrderId($orderId);
             $transId = $teoAuth->getData('authorization_number');
             // Generate the XML for the API request and make a call to the API for a response
             $response = $this->createPartialCapture($amount, $tokenProfileId, $tokenPaymentProfileId, $transId, $order);
             break;
             /**
              * =================================================================
              * END AAI HACK
              *
              * ADD SPECIFIC METHOD FOR PARTIAL AUTH/CAPTURE(S)
              * =================================================================
              */
         /**
          * =================================================================
          * END AAI HACK
          *
          * ADD SPECIFIC METHOD FOR PARTIAL AUTH/CAPTURE(S)
          * =================================================================
          */
         case 'authorizeandcapture':
             $payment->setTokenProfileId($tokenProfileId);
             $payment->setTokenPaymentProfileId($tokenPaymentProfileId);
             $response = $this->createAuthorizeCapture($amount, $tokenProfileId, $tokenPaymentProfileId, $orderId, $ccCCV);
             break;
         case 'void':
             $refundTransactionId = $payment->getRefundTransactionId();
             $response = $this->createVoid($tokenProfileId, $tokenPaymentProfileId, $refundTransactionId);
             break;
         case 'refund':
             $teoAuths = Mage::getModel('authorizenetcim/teoauths');
             $authsCollection = $teoAuths->getCollection()->addFieldToFilter('order_id', $orderId);
             if (count($authsCollection) > 1) {
                 $amountLeftToRefund = $amount;
                 foreach ($authsCollection as $auths) {
                     $teoAuths->load($auths->getId());
                     $teoAuthAmount = $teoAuths->getAuthorizationAmount();
                     $teoAuthAmountRefunded = $teoAuths->getAmountRefunded();
                     if ($amountLeftToRefund > 0) {
                         $amountLeftOnAuth = $teoAuthAmount - $teoAuthAmountRefunded;
                         $authorizeTransactionId = $teoAuths->getAuthorizationNumber();
                         if ($amountLeftToRefund > $amountLeftOnAuth) {
                             $response = $this->createRefund($amountLeftOnAuth, $tokenProfileId, $tokenPaymentProfileId, $authorizeTransactionId);
                             $teoAuths->setAmountRefunded($amountLeftOnAuth);
                             $teoAuths->save();
                             $amountLeftToRefund = $amountLeftToRefund - $amountLeftOnAuth;
                         } else {
                             $response = $this->createRefund($amountLeftToRefund, $tokenProfileId, $tokenPaymentProfileId, $authorizeTransactionId);
                             $teoAuths->setAmountRefunded($amountLeftToRefund);
                             $teoAuths->save();
                             $amountLeftToRefund = 0;
                         }
                     }
                 }
             } else {
                 $refundTransactionId = $payment->getRefundTransactionId();
                 $response = $this->createRefund($amount, $tokenProfileId, $tokenPaymentProfileId, $refundTransactionId);
             }
             break;
         case 'authorizeandcaptureAIM':
             $response = $this->createAuthorizeCaptureAIM($amount, $payment, $order);
             break;
         case 'captureAIM':
             $response = $this->captureAIM($tokenProfileId);
             break;
             /**
              * AAI HACK
              *
              * clone of 'captureAIM' but adds an amount to be captured
              * instead of assuming that the full amount will be captured
              */
         /**
          * AAI HACK
          *
          * clone of 'captureAIM' but adds an amount to be captured
          * instead of assuming that the full amount will be captured
          */
         case 'captureWithAmountAIM':
             $teoAuth = $this->getTeoAuthorizationByOrderId($orderId);
             $transId = $teoAuth->getData('authorization_number');
             $response = $this->captureWithAmountAIM($transId, $amount);
             break;
             /**
              * END AAI HACK
              */
         /**
          * END AAI HACK
          */
         case 'createauthorizeaim':
             $response = $this->createAuthorizeAim($amount, $payment, $order);
             break;
         case 'refundAIM':
             $response = $this->createRefundAIM($amount, $payment, $order);
             break;
     }
     return $response;
 }
Example #13
0
 public function refund(Varien_Object $payment, $amount)
 {
     if ($payment->getRefundTransactionId() && $amount > 0) {
         $transId = $payment->getCcTransId();
         //if transaction type was purchase (authorize & capture)
         if (is_null($transId)) {
             $transId = $payment->getLastTransId();
         }
         $txnDetails = array('txn_type' => self::TRANSACTION_TYPE_REFUND, 'refund_transaction_id' => $transId, 'paynz_account_id' => $payment->getFlo2cashAccountId(), 'amount' => sprintf('%.2f', $amount));
     } else {
         AO::throwException(AO::helper('flo2cash')->__('Error in refunding the payment.'));
     }
     $response = $this->_sendRequest($txnDetails);
     if ($response['txn_status'] == self::TRANSACTION_STATUS_DECLINED) {
         AO::throwException(AO::helper('flo2cash')->__('Payment transaction has been declined.'));
     }
     $payment->setLastTransId($response['transaction_id']);
     return $this;
 }
Example #14
0
 /**
  * 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) {
         $data = $this->_prepareData();
         $data['ordertype'] = "CREDIT";
         $data["oid"] = $payment->getRefundTransactionId();
         $merchantinfo = array();
         $merchantinfo['configfile'] = $data['storenumber'];
         $merchantinfo['keyfile'] = $data['key'];
         $paymentdetails = array();
         $paymentdetails['chargetotal'] = $amount;
         $data = array_merge($data, $merchantinfo, $paymentdetails);
         $result = $this->_postRequest($data);
         if (is_array($result) && count($result) > 0) {
             if (array_key_exists("r_approved", $result)) {
                 if ($result["r_approved"] != "APPROVED") {
                     Mage::throwException("Gateway error : {" . (string) $result["r_error"] . "}");
                 } else {
                     $payment->setStatus(self::STATUS_SUCCESS);
                     return $this;
                 }
             } else {
                 Mage::throwException("No approval found");
             }
         } else {
             Mage::throwException("No response found");
         }
     }
     Mage::throwException(Mage::helper('paygate')->__('Error in refunding the payment.'));
 }
 public function refund(Varien_Object $payment, $amount)
 {
     $order = $payment->getOrder();
     $CaptureData = Mage::getModel('hcd/transaction')->loadLastTransactionDataByUniqeId((string) $payment->getRefundTransactionId());
     $config = $this->getMainConfig($this->_code, $CaptureData['CRITERION_STOREID']);
     $config['PAYMENT.TYPE'] = 'RF';
     $frontend = $this->getFrontend($order->getRealOrderId(), $CaptureData['CRITERION_STOREID']);
     $frontend['FRONTEND.MODE'] = 'DEFAULT';
     $frontend['FRONTEND.ENABLED'] = 'false';
     $user = $this->getUser($order, true);
     $basketData = $this->getBasketData($order, false, $amount);
     $basketData['IDENTIFICATION.REFERENCEID'] = (string) $payment->getRefundTransactionId();
     $params = Mage::helper('hcd/payment')->preparePostData($config, $frontend, $user, $basketData, $criterion = array());
     $this->log("doRequest url : " . $config['URL']);
     $this->log("doRequest params : " . print_r($params, 1));
     $src = Mage::helper('hcd/payment')->doRequest($config['URL'], $params);
     $this->log("doRequest response : " . print_r($src, 1));
     if ($src['PROCESSING_RESULT'] == "NOK") {
         Mage::throwException('Heidelpay Error: ' . $src['PROCESSING_RETURN']);
         return $this;
     }
     $payment->setTransactionId($src['IDENTIFICATION_UNIQUEID']);
     Mage::getModel('hcd/transaction')->saveTransactionData($src);
     return $this;
 }