* @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ require_once '../../../library/sofortLib.php'; define('CONFIGKEY', '1111:2222:6f3d938b65eb833e695393985e1r13z79c'); //your configkey or userid:projektid:apikey $PnagInvoice = new PnagInvoice(CONFIGKEY); $PnagInvoice->setVersion('MY_VERSION'); $PnagInvoice->addInvoiceAddress('John', 'Doe', 'Street', '15', '35578', 'City', 2, 'Max Mustermann', '3 Stock', 'Firma ABC'); //try firstname 'success' or 'decline' as firstname $PnagInvoice->addShippingAddress('John', 'Doe', 'Street', '15', '35578', 'City', 2); $PnagInvoice->setReason('Invoice', 'Invoice'); $PnagInvoice->setOrderId('213124'); $PnagInvoice->setCustomerId('213124'); $PnagInvoice->setDebitorVatNumber('DE325236'); $PnagInvoice->setEmailCustomer('*****@*****.**'); $PnagInvoice->addItemToInvoice(md5('unique'), 'Art01', 'a simple title', 1.2, 0, 'a simple description', 6, 19); $PnagInvoice->setSuccessUrl('https://{website}/'); $PnagInvoice->setAbortUrl('https://{website}/'); $PnagInvoice->setTimeoutUrl('https://{website}/'); $PnagInvoice->setNotificationUrl('https://{website}/'); $err = $PnagInvoice->checkout(); $PnagInvoice->confirmInvoice($PnagInvoice->transactionId); if ($PnagInvoice->isError()) { //PNAG-API didn't accept the data echo $PnagInvoice->getError(); } else { //buyer must be redirected to $paymentUrl else payment cannot be successfully completed! $paymentUrl = $PnagInvoice->getPaymentUrl(); header('Location: ' . $paymentUrl); }
/** * update invoice items to sofortueberweisung * * @param Varien_Object $payment object of the order * @param array $items of the the invoice * @param string $comment to add * @param string $invoiceNumber * @param string $customerNumber * @param string $orderNumber * @return Paymentnetwork_Pnsofortueberweisung_Model_Sofortrechnung * @throws Exception */ public function updateInvoice(Varien_Object $payment, $items, $comment, $invoiceNumber = '', $customerNumber = '', $orderNumber = '') { // load current transaction id $transactionId = $payment->getAdditionalInformation('sofort_transaction'); $order = $payment->getOrder(); if (!empty($transactionId)) { // create articles $pnagArticles = array(); foreach ($items as $item) { array_push($pnagArticles, array('itemId' => $item['item_id'], 'productNumber' => $item['product_number'], 'productType' => $item['product_type'], 'title' => $item['title'], 'description' => $item['description'], 'quantity' => $item['quantity'], 'unitPrice' => $item['unit_price'], 'tax' => $item['tax'])); } // create connection class $PnagInvoice = new PnagInvoice(Mage::getStoreConfig('payment/sofort/configkey'), $transactionId); $PnagInvoice->setTransactionId($transactionId); $PnagInvoice->updateInvoice($transactionId, $pnagArticles, $comment, $invoiceNumber, $customerNumber, $orderNumber); // add error if ($PnagInvoice->isError()) { Mage::throwException($PnagInvoice->getError()); } else { // update history $order->addStatusHistoryComment(Mage::helper('pnsofortueberweisung')->__('The invoice has been edit.') . "\n\n\"" . $comment . '"'); $order->save(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('pnsofortueberweisung')->__('Successfully edit invoice.')); return $this; } } // no transaction id exist Mage::getSingleton('adminhtml/session')->addError(Mage::helper('pnsofortueberweisung')->__('Could not edit invoice.')); return $this; }
/** * cancel PNAG invoice * * @param Varien_Event_Observer $observer * @return $this */ public function sales_order_payment_cancel($observer) { // dont trigger if we are notifyed if (!empty($GLOBALS['isNotificationAction'])) { return $this; } //get payment $payment = $observer->getEvent()->getPayment(); $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); if ($PnagInvoice->getStatus() != 'loss') { $PnagInvoice->cancelInvoice($transactionId); } if ($PnagInvoice->isError()) { Mage::throwException($PnagInvoice->getError()); } else { Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('pnsofortueberweisung')->__('Successfully canceled invoice: %s', $transactionId)); return $this; } } Mage::getSingleton('adminhtml/session')->addError(Mage::helper('pnsofortueberweisung')->__('Could not cancel invoice.')); return $this; }