public function partialRefund(Customweb_Payment_Authorization_ITransaction $transaction, $items, $close)
 {
     if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) {
         throw new Exception("The given transaction is not instanceof Customweb_Saferpay_Authorization_Transaction.");
     }
     $amount = Customweb_Util_Invoice::getTotalAmountIncludingTax($items);
     // Check the transaction state
     $transaction->refundByLineItemsDry($items, $close);
     $builder = new Customweb_Saferpay_BackendOperation_Adapter_Refund_ParameterBuilder($transaction, $this->getConfiguration(), $this->container);
     $sendParameters = $builder->buildParameters($amount);
     $requestUrl = Customweb_Saferpay_Util::addParametersToUrl($this->getExecuteUrl(), $sendParameters);
     $response = Customweb_Saferpay_Util::sendRequest($requestUrl);
     $parameters = $this->getXmlParameters($response);
     if ($parameters['RESULT'] == 0) {
         $id = $parameters['ID'];
         $this->capture($transaction, $amount, $id);
         $refundItem = $transaction->refundByLineItems($items, $close, Customweb_I18n_Translation::__("The total amount of the transaction was refunded. Refund transaction ID: '!paymentId' .", array('!paymentId' => $id)));
         $refundItem->setRefundId($id);
     } else {
         if ($parameters['RESULT'] == '75') {
             throw new Exception(Customweb_I18n_Translation::__('Refund of !amount failed because no card reference id was provided. This most likely because you try to refund a transaction authorized over the payment page. (Code: !result).', array('!amount' => $amount, '!result' => $parameters['RESULT'])));
         } else {
             throw new Exception(Customweb_I18n_Translation::__('Refund of !amount failed with code: !result.', array('!amount' => $amount, '!result' => $parameters['RESULT'])));
         }
     }
 }
 public function partialCapture(Customweb_Payment_Authorization_ITransaction $transaction, $items, $close)
 {
     if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) {
         throw new Exception("The given transaction is not instanceof Customweb_Saferpay_Authorization_Transaction.");
     }
     $amount = Customweb_Util_Invoice::getTotalAmountIncludingTax($items);
     // Check the transaction state
     $transaction->partialCaptureByLineItemsDry($items, true);
     $builder = new Customweb_Saferpay_BackendOperation_Adapter_Capture_ParameterBuilder($transaction, $this->getConfiguration(), $this->container);
     $builder->setAmount($amount);
     $parameters = $builder->buildParameters();
     $this->performPayCompleteAction($parameters, Customweb_I18n_Translation::__('The transaction could not be captured.'));
     $transaction->partialCaptureByLineItems($items, true);
 }
 public function refundByLineItems($items, $close = false, $additionalMessage = '')
 {
     $this->refundByLineItemsDry($items, $close, $additionalMessage);
     $amount = Customweb_Util_Invoice::getTotalAmountIncludingTax($items);
     $historyMessage = Customweb_I18n_Translation::__("A refund was added over !amount.", array('!amount' => Customweb_Util_Currency::formatAmount($amount, $this->getCurrencyCode())));
     if (!empty($additionalMessage)) {
         $historyMessage .= ' (' . $additionalMessage . ')';
     }
     $refundItem = $this->createRefundItem($amount);
     $refundItem->setRefundItems($items);
     $this->createHistoryItem($historyMessage, Customweb_Payment_Authorization_ITransactionHistoryItem::ACTION_REFUND);
     if (Customweb_Util_Currency::compareAmount($this->getRefundedTotalAmount(), $this->getCapturedAmount(), $this->getCurrencyCode()) >= 0) {
         $close = true;
     }
     $this->refundClosed = $close;
     return $refundItem;
 }
 public function addInvoiceItem(Customweb_Payment_Authorization_IInvoiceItem $item)
 {
     $this->invoiceItems[] = $item;
     $this->setData('order_amount_in_decimals', Customweb_Util_Invoice::getTotalAmountIncludingTax($this->invoiceItems));
     return $this;
 }
 public function partialRefund(Customweb_Payment_Authorization_ITransaction $transaction, $items, $close)
 {
     $amount = Customweb_Util_Invoice::getTotalAmountIncludingTax($items);
     return $this->getAmountRefundAdapter()->partialRefund($transaction, $amount, $close);
 }
 public function addInvoiceItem(Customweb_Payment_Authorization_IInvoiceItem $item)
 {
     $this->invoiceItems[] = $item;
     $this->orderAmountInDecimals = Customweb_Util_Invoice::getTotalAmountIncludingTax($this->invoiceItems);
     return $this;
 }