/**
  * Tests Services_Paymill_Refunds->delete()
  */
 public function testDelete()
 {
     try {
         $this->_refunds->delete();
     } catch (Exception $e) {
         $this->assertInstanceOf('Services_Paymill_Exception', $e);
         $this->assertEquals(404, $e->getCode());
     }
 }
示例#2
0
 /**
  * Creates a refund from the ordernumber passed as an argument
  * @param Mage_Sales_Model_Order_Refund $creditmemo
  * @return boolean Indicator of success
  */
 public function createRefund($creditmemo, $payment)
 {
     //Gather Data
     try {
         $refundsObject = new Services_Paymill_Refunds(Mage::helper('paymill/optionHelper')->getPrivateKey(), Mage::helper('paymill')->getApiUrl());
     } catch (Exception $ex) {
         Mage::helper('paymill/loggingHelper')->log("No Refund created due to illegal parameters.", $ex->getMessage());
         return false;
     }
     //Create Refund
     $params = array('transactionId' => $payment->getAdditionalInformation('paymillTransactionId'), 'source' => Mage::helper('paymill')->getSourceString(), 'params' => array('amount' => (int) Mage::helper("paymill/paymentHelper")->getAmount($creditmemo)));
     Mage::helper('paymill/loggingHelper')->log("Try to refund.", var_export($params, true));
     try {
         $refund = $refundsObject->create($params);
     } catch (Exception $ex) {
         Mage::helper('paymill/loggingHelper')->log("No Refund created.", $ex->getMessage(), var_export($params, true));
         return false;
     }
     //Validate Refund and return feedback
     return $this->validateRefund($refund);
 }
 /**
  * Refund the selected paymill transaction
  */
 public function refundTransaction()
 {
     $oxOrder = $this->getEditObject();
     $transaction = oxNew('paymill_transaction');
     $transaction->load($this->getEditObjectId());
     //Create Refund
     $params = array('transactionId' => $transaction->paymill_transaction__transaction_id->rawValue, 'params' => array('amount' => (int) ($this->_getRefundAmount() * 100)));
     $refundsObject = new Services_Paymill_Refunds(trim(oxRegistry::getConfig()->getShopConfVar('PAYMILL_PRIVATEKEY')), paymill_util::API_ENDPOINT);
     oxRegistry::getSession()->setVariable('refund', true);
     try {
         $refund = $refundsObject->create($params);
     } catch (Exception $ex) {
     }
     if (isset($refund['response_code']) && $refund['response_code'] == 20000) {
         $oxOrder->assign(array('oxorder__oxdiscount' => $this->_getRefundAmount()));
         $oxOrder->reloadDiscount(false);
         $oxOrder->recalculateOrder();
         oxRegistry::getSession()->setVariable('success', true);
     } else {
         oxRegistry::getSession()->setVariable('error', true);
     }
 }
 private function proceedRefund($transactionId)
 {
     $result = false;
     $this->init();
     $this->load->model('sale/order');
     $orderId = $this->getPost('orderId', 0);
     $transaction = $this->paymillTransaction->getOne($transactionId);
     $this->log('Transaction used for Refund', var_export($transaction, true));
     if (is_array($transaction)) {
         try {
             $result = $this->paymillRefund->create(array('transactionId' => $transactionId, 'params' => array('amount' => $transaction['origin_amount'])));
             $this->log('Refund resulted in', var_export($result, true));
             $this->log('Refund successfully', $transaction['id']);
             $orderStatusId = $this->db->query('SELECT `order_status_id` FROM `' . DB_PREFIX . 'order_status` WHERE `name`= "Refunded"')->row['order_status_id'];
             $this->model_sale_order->addOrderHistory($orderId, array('order_status_id' => $orderStatusId, 'notify' => true, 'comment' => ''));
         } catch (Exception $ex) {
             $result = false;
         }
     }
     return $result;
 }
<?php

require_once 'includes/application_top.php';
require_once DIR_WS_CLASSES . 'order.php';
require_once dirname(__FILE__) . '/../ext/modules/payment/paymill/lib/Services/Paymill/Refunds.php';
if (isset($_GET['oID']) && !empty($_GET['oID'])) {
    $order = new order($_GET['oID']);
    $transaction = tep_db_fetch_array(tep_db_query("SELECT * FROM pi_paymill_transaction WHERE order_id = '" . $_GET['oID'] . "'"));
    require_once dirname(__FILE__) . '/../includes/modules/payment/' . $transaction['payment_code'] . '.php';
    include dirname(__FILE__) . '/../includes/languages/' . $_SESSION['language'] . '/modules/payment/' . $transaction['payment_code'] . '.php';
    $payment = new $transaction['payment_code']();
    //Create Refund
    $params = array('transactionId' => $transaction['transaction_id'], 'source' => $payment->version . '_' . str_replace(' ', '_', PROJECT_VERSION), 'params' => array('amount' => $transaction['amount']));
    $refundsObject = new Services_Paymill_Refunds($payment->privateKey, $payment->apiUrl);
    $error = '';
    try {
        $refund = $refundsObject->create($params);
    } catch (Exception $ex) {
        $error = $ex->getMessage();
    }
    if (isset($refund['response_code']) && $refund['response_code'] == 20000) {
        $statusArray = tep_db_fetch_array(tep_db_query("select orders_status_id from " . TABLE_ORDERS_STATUS . " where orders_status_name = 'Paymill [Refund]' limit 1"));
        tep_db_query("UPDATE " . TABLE_ORDERS . " SET orders_status='" . $statusArray['orders_status_id'] . "' WHERE orders_id='" . $_GET['oID'] . "'");
        $messageStack->add_session(PAYMILL_REFUND_SUCCESS, 'success');
    } else {
        $messageStack->add_session(PAYMILL_REFUND_ERROR, 'error');
    }
}
tep_redirect(tep_href_link(FILENAME_ORDERS, 'oID=' . $_GET['oID'] . '&action=edit', true, false));
 /**
  * Eventhandler for refund actions
  */
 public function refundAction()
 {
     $type = $this->_request['type'];
     $refundId = $this->_request['event_resource']['id'];
     $this->requireRefunds();
     $refunds = new Services_Paymill_Refunds($this->_privateKey, $this->_apiUrl);
     $refund = $refunds->getOne($refundId);
     if ($this->getWebhookState($type) && isset($refund['id'])) {
         $this->_request['action'] = 'Refund';
         $this->updateOrderStatus();
     } else {
         $this->successAction();
     }
 }
 /**
  * Action Listener to execute the capture for applicable transactions
  *
  */
 public function refundAction()
 {
     $result = false;
     $code = null;
     require_once dirname(__FILE__) . '/../../lib/Services/Paymill/Transactions.php';
     require_once dirname(__FILE__) . '/../../lib/Services/Paymill/Refunds.php';
     $swConfig = Shopware()->Plugins()->Frontend()->PaymPaymentCreditcard()->Config();
     $refund = new Services_Paymill_Refunds(trim($swConfig->get("privateKey")), 'https://api.paymill.com/v2/');
     $transactionObject = new Services_Paymill_Transactions(trim($swConfig->get("privateKey")), 'https://api.paymill.com/v2/');
     $modelHelper = new Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_ModelHelper();
     $orderNumber = $modelHelper->getOrderNumberById($this->Request()->getParam("orderId"));
     $transactionId = $modelHelper->getPaymillTransactionId($orderNumber);
     $transactionResult = $transactionObject->getOne($transactionId);
     //Create Transaction
     $parameter = array('transactionId' => $transactionId, 'params' => array('amount' => $transactionResult['amount'], 'description' => $transactionResult['client']['email'] . " " . Shopware()->Config()->get('shopname')));
     $response = $refund->create($parameter);
     if (isset($response['response_code'])) {
         $code = $response['response_code'];
     }
     //Validate result and prepare feedback
     if ($this->_validateRefundResponse($response)) {
         $result = true;
         $modelHelper->setPaymillRefund($orderNumber, $response['id']);
         $this->_updatePaymentStatus(20, $this->Request()->getParam("orderId"));
     }
     $this->View()->assign(array('success' => $result, 'code' => $code));
 }