public function refundAmountAction() {

		Shopware()->Plugins()->Controller()->ViewRenderer()->setNoRender();


		$return = new stdClass();
        
		$amount = $this->checkAmmount ($this->Request()->getParam('amount'));
		if (is_object ($amount)) {
			echo json_encode($amount);
			exit (0);
		}

		$order_number = (int) $this->Request()->getParam('oID');
		$row = Shopware()->Db()->fetchRow('select transactionID,userID from s_order where ordernumber="' . $order_number . '"');
		$txid = $row['transactionID'];


		//$uid = Shopware()->Session()->sUserId = $row['userID'];

		try {
            require_once dirname(__FILE__).'/../Frontend/PaymentBuiswPaymentPayone.php';
			$translog = new payone_TransactionLogs();
			$s = $translog->select()->columns(array ('id','api_log_id','amount','currency', 'mode', 'data_array'));
			$s->where('transaction_no=?', $txid);
			$transLogEntry = $translog->fetchRow($s);


			$mode = $transLogEntry['mode'];

			$captureAndRefund = new payone_CaptureAndRefund();

			$nextSequenceNumber = $captureAndRefund->nextSequenceNumber($txid);

			$params = Shopware_Controllers_Frontend_PaymentBuiswPaymentPayone::createFundamentalParams($mode == 'l' ? 'live' : 'test');
			// $params['request'] = 'refund';
			$params['request'] = 'debit';

			$params['txid'] = $txid;
			$amount = -1 * $amount;
			$params['amount'] =  $amount;
			$params['sequencenumber'] = $nextSequenceNumber;
			$params['currency'] = $transLogEntry['currency'];


			$err = false;
			$apilogid = null;
  		$response = Shopware_Controllers_Frontend_PaymentBuiswPaymentPayone::curlCallAndApiLog($params, $err, $apilogid);

			if ($err) {
				$return->error = 'technical problems: ' . $response[0];
				echo json_encode ($return);
				exit (0);
			}
			if ($response['status'] == 'ERROR') {
				$return->error = 'error (' . $response['errorcode'] . ') ' . $response['errormessage'];
				echo json_encode ($return);
				exit (0);
			}
			// erst ab hier ist alles erstmal ok.
			$captureAndRefund->log ($txid, $nextSequenceNumber, $amount,$apilogid);

		} catch (Exception $e) {
			$return->error = 'technical problems: ' . $e->getMessage();
				echo json_encode ($return);
				exit (0);
		}

		echo json_encode($return);
	}
Exemple #2
0
	static public function assignOrderNumberToTransactionLog ($transactionLogId, $orderNumber) {
		$log = new payone_TransactionLogs();
		$log->update(array ('order_number' => $orderNumber), 'id=' . $transactionLogId);
	}