Beispiel #1
0
 /**
  * Collect shipping amount to be invoiced based on already invoiced amount
  *
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @return $this
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $previousInvoices = $invoice->getOrder()->getInvoiceCollection();
     if ($invoice->getShippingAmount() > 0) {
         return $this;
     }
     $order = $invoice->getOrder();
     $shippingAmount = $order->getShippingAmount() - $order->getShippingInvoiced() - $order->getShippingRefunded();
     $baseShippingAmount = $order->getBaseShippingAmount() - $order->getBaseShippingInvoiced() - $order->getBaseShippingRefunded();
     $invoice->setShippingAmount($shippingAmount);
     $invoice->setBaseShippingAmount($baseShippingAmount);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $shippingAmount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseShippingAmount);
     return $this;
 }
 /**
  * Cancel specified invoice: update self totals from it
  *
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @return Mage_Sales_Model_Order_Payment
  */
 public function cancelInvoice($invoice)
 {
     $this->_updateTotals(array('amount_paid' => -1 * $invoice->getGrandTotal(), 'base_amount_paid' => -1 * $invoice->getBaseGrandTotal(), 'shipping_captured' => -1 * $invoice->getShippingAmount(), 'base_shipping_captured' => -1 * $invoice->getBaseShippingAmount()));
     Mage::dispatchEvent('sales_order_payment_cancel_invoice', array('payment' => $this, 'invoice' => $invoice));
     return $this;
 }
Beispiel #3
0
 /**
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @return array
  */
 public function sendConfirmInvoiceRequest($invoice, $paymentMethod, $delayInDays, $useHTMLFormat)
 {
     $order = $invoice->getOrder();
     $shippingPriceGross = $this->currencyToSmallerUnit($invoice->getShippingAmount() + $invoice->getShippingTaxAmount());
     $cartTotalPriceGross = $this->calculateCartTotalGross($invoice);
     // add trusted shops amount
     if ($this->getConfigData('settings/use_trusted_shops_buyer_protection', $order->getStore()->getId())) {
         $trustedShopsAmount = $invoice->getTrustedShopsAmount();
         if (!empty($trustedShopsAmount)) {
             $cartTotalPriceGross += $this->currencyToSmallerUnit($trustedShopsAmount);
         }
     }
     $storeId = $order->getStore()->getStoreId();
     $req = $this->createRequestObject('invoiceCreated', $paymentMethod, $storeId);
     $req->set_invoice_params($cartTotalPriceGross, $order->getOrderCurrencyCode(), $order->getOriginalIncrementId() ? $order->getOriginalIncrementId() : $order->getIncrementId(), $delayInDays);
     try {
         $req->send();
         $this->getLog()->logDebug('InvoiceCreated request xml:');
         $this->getLog()->logDebug($req->get_request_xml());
         $this->getLog()->logDebug('InvoiceCreated response xml:');
         $this->getLog()->logDebug($req->get_response_xml());
     } catch (Exception $e) {
         $this->getLog()->logError('Error sending InvoiceCreated request:');
         $this->getLog()->logException($e);
         // This will be caught by calling Mage_Adminhtml_Sales_OrderController controller
         throw new Mage_Core_Exception(Mage::helper('sales')->__('billpay_connection_failed_invoice'));
     }
     if ($req->has_error()) {
         $this->getLog()->logError('InvoiceCreated request error code: ' . $req->get_error_code());
         throw new Mage_Core_Exception($req->get_merchant_error_message() . ' (Error code: ' . $req->get_error_code() . ')');
     }
     $result = array();
     $result['account_holder'] = $req->get_account_holder();
     $result['account_number'] = $req->get_account_number();
     $result['bank_code'] = $req->get_bank_code();
     $result['bank_name'] = $req->get_bank_name();
     $result['invoice_duedate'] = $req->get_invoice_duedate();
     $result['invoice_reference'] = $req->get_invoice_reference();
     $result['dues'] = $req->get_dues();
     return $result;
 }