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 getInvoiceItems($order, $storeId, $useBaseCurrency = false)
 {
     $resultItems = array();
     $orderItems = $order->getItemsCollection();
     foreach ($orderItems as $item) {
         if ($item->getParentItemId() != null && $item->getParentItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
             continue;
         }
         if ($item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $item->getParentItemId() == null) {
             continue;
         }
         $productItem = $this->getProductItem($item, $useBaseCurrency);
         if ($productItem) {
             $resultItems[] = $productItem;
         }
         $discountItem = $this->getDiscountItem($item, $useBaseCurrency);
         if ($discountItem) {
             $resultItems[] = $discountItem;
         }
     }
     $surchargeItem = $this->getFoomanSurchargeItem($order, $useBaseCurrency);
     if ($surchargeItem) {
         $resultItems[] = $surchargeItem;
     }
     $shippingItem = $this->getOrderShippingItem($order, $useBaseCurrency);
     if ($shippingItem) {
         $resultItems[] = $shippingItem;
     }
     $resultItems = Customweb_Util_Invoice::ensureUniqueSku($resultItems);
     $event = new StdClass();
     $event->items = array();
     if ($order instanceof Mage_Sales_Model_Order) {
         Mage::dispatchEvent('customweb_collect_order_items', array('order' => $order, 'useBaseCurrency' => $useBaseCurrency, 'result' => $event));
     } elseif ($order instanceof Mage_Sales_Model_Quote) {
         Mage::dispatchEvent('customweb_collect_quote_items', array('quote' => $order, 'useBaseCurrency' => $useBaseCurrency, 'result' => $event));
     }
     foreach ($event->items as $item) {
         $resultItems[] = new Customweb_Payment_Authorization_DefaultInvoiceItem($item['sku'], $item['name'], $item['taxRate'], $item['amountIncludingTax'], $item['quantity'], $item['type']);
     }
     if ($useBaseCurrency) {
         $orderAmountInDecimals = $order->getBaseGrandTotal();
         $currency = Mage::app()->getStore($storeId)->getBaseCurrencyCode();
     } else {
         $orderAmountInDecimals = $order->getGrandTotal();
         $currency = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
     }
     $adjustmentItem = $this->getAdjustmentItem($resultItems, $orderAmountInDecimals, $currency);
     if ($adjustmentItem) {
         $resultItems[] = $adjustmentItem;
     }
     return $resultItems;
 }
 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);
 }
 /**
  * This method returns a list of line items with the residual amount to refund.
  *
  * @return Customweb_Payment_Authorization_IInvoiceItem[]
  */
 public function getNonRefundedLineItems()
 {
     $resultingItems = $this->getCapturedLineItems();
     foreach ($this->getRefunds() as $refund) {
         $items = $refund->getRefundItems();
         if ($items === null) {
             $items = Customweb_Util_Invoice::getItemsByReductionAmount($resultingItems, $refund->getAmount(), $this->getCurrencyCode());
         }
         $resultingItems = Customweb_Util_Invoice::substractLineItems($resultingItems, $items);
     }
     return $resultingItems;
 }
 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);
 }
示例#7
0
 protected function getInvoiceItems($invoice)
 {
     /* @var $invoice Mage_Sales_Model_Order_Invoice */
     $resultItems = array();
     $items = $invoice->getAllItems();
     $invoiceItems = Mage::getModel('saferpaycw/invoiceItems');
     foreach ($items as $item) {
         $orderItem = $item->getOrderItem();
         if ($orderItem->getParentItemId() != null && $orderItem->getParentItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
             continue;
         }
         if ($orderItem->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $orderItem->getParentItemId() == null) {
             continue;
         }
         $productItem = $invoiceItems->getProductItem($item);
         if ($productItem) {
             $resultItems[] = $productItem;
         }
         $discountItem = $invoiceItems->getDiscountItem($item);
         if ($discountItem) {
             $resultItems[] = $discountItem;
         }
     }
     $surchargeItem = $invoiceItems->getFoomanSurchargeItem($invoice->getOrder());
     if ($surchargeItem) {
         $resultItems[] = $surchargeItem;
     }
     $shippingItem = $invoiceItems->getShippingItem($invoice);
     if ($shippingItem) {
         $resultItems[] = $shippingItem;
     }
     $resultItems = Customweb_Util_Invoice::ensureUniqueSku($resultItems);
     $event = new StdClass();
     $event->items = array();
     Mage::dispatchEvent('customweb_collect_invoice_items', array('invoice' => $invoice, 'result' => $event));
     foreach ($event->items as $item) {
         $resultItems[] = new Customweb_Payment_Authorization_DefaultInvoiceItem($item['sku'], $item['name'], $item['taxRate'], $item['amountIncludingTax'], $item['quantity'], $item['type']);
     }
     $currencyCode = $invoice->getOrder()->getOrderCurrency()->getCode();
     $adjustmentItem = $invoiceItems->getAdjustmentItem($resultItems, $invoice->getGrandTotal(), $currencyCode);
     if ($adjustmentItem) {
         $resultItems[] = $adjustmentItem;
     }
     return $resultItems;
 }
 public function addInvoiceItem(Customweb_Payment_Authorization_IInvoiceItem $item)
 {
     $this->invoiceItems[] = $item;
     $this->orderAmountInDecimals = Customweb_Util_Invoice::getTotalAmountIncludingTax($this->invoiceItems);
     return $this;
 }