Ejemplo n.º 1
0
 /**
  * Pay-Event
  * we will confirm the invoice with this method
  * 
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function sales_order_invoice_pay($observer)
 {
     // dont trigger if we are notifyed
     if (!empty($GLOBALS['isNotificationAction'])) {
         return $this;
     }
     // get invoice
     $invoice = $observer->getEvent()->getInvoice();
     $order = $invoice->getOrder();
     $payment = $order->getPayment();
     $addinfo = $payment->getAdditionalInformation();
     $invoices = $invoice->getOrder()->hasInvoices();
     $method = $payment->getMethod();
     if ($method != 'sofortrechnung') {
         return $this;
     }
     $transactionId = $payment->getAdditionalInformation('sofort_transaction');
     if (!empty($transactionId)) {
         $PnagInvoice = new PnagInvoice(Mage::getStoreConfig('payment/sofort/configkey'), $transactionId);
         $entity_type_model = Mage::getSingleton('eav/config')->getEntityType('invoice');
         $newInvoiceNumber = $entity_type_model->fetchNewIncrementId($invoice->getOrder()->getStoreId());
         $invoice->setIncrementId($newInvoiceNumber);
         $PnagInvoice->confirmInvoice($transactionId, $newInvoiceNumber);
         if ($PnagInvoice->isError()) {
             Mage::throwException($PnagInvoice->getError());
         } else {
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('pnsofortueberweisung')->__('Successfully confirmed invoice: %s', $transactionId));
             $invoice->setTransactionId($transactionId);
             $payment->setAdditionalInformation("sofortrechnung_invoice_url", $PnagInvoice->getInvoiceUrl());
             $payment->save();
             return $this;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('pnsofortueberweisung')->__('Could not confirm invoice.'));
     return $this;
 }