/** * only SR: Fill table sofort_orders_notification, e.g. in case of status-changes * @see updateTimeline() * @param int $sofortOrdersId - key from table sofort_orders * @param object $invoice with complete transactiondata * @param string $customerComment (optional) * @param string $sellerComment (optional) * @return last insert_id */ function insertSofortOrdersNotification($sofortOrdersId, PnagInvoice $PnagInvoice, $customerComment = '', $sellerComment = '') { if (!$sofortOrdersId || !is_object($PnagInvoice->getTransactionData()) || $PnagInvoice->getTransactionData()->getPaymentMethod() != 'sr') { return false; } $sqlDataArray = array('sofort_orders_id' => $sofortOrdersId, 'items' => serialize($PnagInvoice->getItems()), 'amount' => $PnagInvoice->getAmount(), 'customer_comment' => $customerComment, 'seller_comment' => $sellerComment, 'status_id' => $PnagInvoice->getState(), 'status' => $PnagInvoice->getStatus(), 'status_reason' => $PnagInvoice->getStatusReason(), 'invoice_status' => $PnagInvoice->getStatusOfInvoice(), 'invoice_objection' => $PnagInvoice->getInvoiceObjection()); xtc_db_query(HelperFunctions::getEscapedInsertInto('sofort_orders_notification', $sqlDataArray)); return xtc_db_insert_id(); // fetch and return the last insert id }
/** * 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; }
$paymentMethod = $SofortLib_TransactionData->getPaymentMethod(); $paymentSecret = $_REQUEST['paymentSecret']; $statusReason = $SofortLib_TransactionData->getStatusReason(); $status = $SofortLib_TransactionData->getStatus(); $xCustomerId = $SofortLib_TransactionData->getUserVariable(1); //insert the serialized order into shop-db if it doesnt exist $xOrderId = handleOrderInsertion($transactionId, $paymentSecret, $paymentMethod, $xCustomerId); if (!$xOrderId) { exit('Error: No orderId found.'); } } $configuration = getPaymentModuleConfiguration(); if ($paymentMethod == 'sr') { // Rechnung by Sofort $srOrderStatusArr = array('unconfirmed' => getStatusId($configuration['MODULE_PAYMENT_SOFORT_SR_UNCONFIRMED_STATUS_ID']), 'confirmed' => getStatusId($configuration['MODULE_PAYMENT_SOFORT_SR_ORDER_STATUS_ID']), 'cancelled' => getStatusId($configuration['MODULE_PAYMENT_SOFORT_SR_CANCEL_STATUS_ID']), 'check' => getStatusId($configuration['MODULE_PAYMENT_SOFORT_MULTIPAY_CHECK_STATUS_ID'])); $PnagInvoice = new PnagInvoice(MODULE_PAYMENT_SOFORT_MULTIPAY_APIKEY, $transactionId); if ($PnagInvoice->isError()) { $errors = $PnagInvoice->getErrors(); echo MODULE_PAYMENT_SOFORT_ERROR_TERMINATED . ' - ' . print_r($errors, true); exit; } $orderId = getOrderId($transactionId); $lastOrderStatus = getLastOrderStatus($orderId); $completeInvoiceStatus = $PnagInvoice->getState(); $newTotal = checkIfNewTotal($PnagInvoice, $orderId); $newComments = ''; // Update the order-status switch ($completeInvoiceStatus) { case PnagInvoice::PENDING_CONFIRM_INVOICE: updateShopAdresses($SofortLib_TransactionData->getInvoiceAddress(), $SofortLib_TransactionData->getShippingAddress(), $orderId); $historyComments = getHistoryComments($completeInvoiceStatus, $transactionId);
$PnagInvoice->setReason('Invoice', 'Invoice'); $PnagInvoice->setEmailCustomer('*****@*****.**'); $PnagInvoice->addItemToInvoice(md5('unique'), 'Art01', 'a simple title', 1.2, 0, 'a simple description', 6, 19); $PnagInvoice->setAbortUrl('http://127.0.0.1'); $PnagInvoice->setSuccessUrl('http://127.0.0.1'); $PnagInvoice->setTimeoutUrl('http://127.0.0.1'); $PnagInvoice->setNotificationUrl('http://127.0.0.1'); try { $err = $PnagInvoice->checkout(); getWebPage($PnagInvoice->getPaymentUrl()); } catch (XmlToArrayException $e) { } $transactionId = $PnagInvoice->getTransactionId(); $articles = array(array('articleId' => md5('unique'), 'articleNumber' => 'Art01', 'articleTitle' => 'a simple title', 'articlePrice' => 1.2, 'articleType' => 0, 'articleDescription' => 'a simple description', 'articleQuantity' => 2, 'articleTax' => 19)); $PnagInvoice = null; $PnagInvoice = new PnagInvoice(CONFIGKEY, $transactionId); $PnagInvoice->setTransactionId($transactionId); $pnagArticles = array(); foreach ($articles as $article) { array_push($pnagArticles, array('itemId' => $article['articleId'], 'productNumber' => $article['articleNumber'], 'title' => $article['articleTitle'], 'description' => $article['articleDescription'], 'quantity' => $article['articleQuantity'], 'unitPrice' => number_format($article['articlePrice'], 2, '.', ''), 'tax' => number_format($article['articleTax'], 2, '.', ''))); } $invoiceNumber = "10234"; $customerNumber = "10234"; $orderNumber = "10234"; try { $comment = 'must not be left empty for confirmed invoices, editing an invoice will result in refunded items'; $PnagInvoice->updateInvoice($transactionId, $pnagArticles, $comment, $invoiceNumber, $customerNumber, $orderNumber); } catch (XmlToArrayException $e) { } /** * Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an
/** * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2012-11-21 12:02:12 +0100 (Wed, 21 Nov 2012) $ * @version SofortLib 1.5.0 $Id: example_sofortrechnung.php 5724 2012-11-21 11:02:12Z rotsch $ * @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->addInvoiceAddress('success', 'Doe', 'Street', '15', '35578', 'City', 2, 'DE', 'Company Name'); $PnagInvoice->addShippingAddress('success', 'Doe', 'Street', '15', '35578', 'City', 2, 'DE', 'Company Name'); $PnagInvoice->setReason('Invoice', 'Invoice'); $PnagInvoice->setEmailCustomer('*****@*****.**'); $PnagInvoice->addItemToInvoice(md5('unique'), 'Art01', 'a simple title', 1.2, 0, 'a simple description', 6, 19); $PnagInvoice->setAbortUrl('http://127.0.0.1'); $PnagInvoice->setSuccessUrl('http://127.0.0.1'); $PnagInvoice->setTimeoutUrl('http://127.0.0.1'); $PnagInvoice->setNotificationUrl('http://127.0.0.1'); try { $err = $PnagInvoice->checkout(); getWebPage($PnagInvoice->getPaymentUrl()); } catch (XmlToArrayException $e) { } $transactionId = $PnagInvoice->getTransactionId(); $PnagInvoice = new PnagInvoice(CONFIGKEY, $transactionId); $creditNoteNumber = '13214'; $PnagInvoice->cancelInvoice($transactionId, $creditNoteNumber); /** * Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an * array containing the HTTP server response header fields and content. */ function getWebPage($url) { $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_USERAGENT => "sofort example", CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false); $ch = curl_init($url); curl_setopt_array($ch, $options); $content = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $header = curl_getinfo($ch);
$successCodes = false; $errorCodes = false; $lang = $_SESSION['languages_id']; $ordersStatuses = array(); $ordersStatusArray = array(); $ordersStatusQuery = shopDbQuery('SELECT orders_status_id, orders_status_name FROM ' . TABLE_ORDERS_STATUS . ' WHERE language_id = \'' . (int) $lang . '\''); $action = isset($_GET['action']) ? $_GET['action'] : ''; while ($ordersStatus = shopDbFetchArray($ordersStatusQuery)) { $ordersStatuses[] = array('id' => $ordersStatus['orders_status_id'], 'text' => $ordersStatus['orders_status_name']); $ordersStatusArray[$ordersStatus['orders_status_id']] = $ordersStatus['orders_status_name']; } $getLng = $_SESSION['language']; require shopGetLanguageFile($getLng, $paymentMethodShort); require shopGetLanguageFile($getLng, 'general'); $logo = shopGetLogo($paymentMethodShort); $PnagInvoice = new PnagInvoice(shopGetConfigKey(), $tId); if ($_POST['sofort_action'] == 'sofort_comment') { shopSofortComment($_GET['oID'], $order, $_POST['status'], $_POST['comments'], $_POST['notify'], $_POST['notify_comments']); } if ($_POST['sofort_action'] == 'sofort_save' && $_POST['sofort_delete_all'] == '1') { $_POST['sofort_action'] = 'sofort_buttons'; $_POST['sofort_button'] = 'cancel'; } if ($_POST['sofort_action'] == 'sofort_buttons') { switch ($_POST['sofort_button']) { case 'invoice': case 'preview': case 'credit': $PnagInvoice->getInvoice(); break; case 'confirm':
$PnagInvoice->setSuccessUrl('http://127.0.0.1'); $PnagInvoice->setTimeoutUrl('http://127.0.0.1'); $PnagInvoice->setNotificationUrl('http://127.0.0.1'); try { $err = $PnagInvoice->checkout(); getWebPage($PnagInvoice->getPaymentUrl()); // call sofort.com to 'activate' payment } catch (XmlToArrayException $e) { } $transactionId = $PnagInvoice->getTransactionId(); $articles = array(array('articleId' => md5('unique'), 'articleNumber' => 'Art01', 'articleTitle' => 'a simple title', 'articlePrice' => 1.2, 'articleType' => 0, 'articleDescription' => 'a simple description', 'articleQuantity' => 2, 'articleTax' => 19)); $PnagInvoice = null; $PnagInvoice = new PnagInvoice(CONFIGKEY, $transactionId); $PnagInvoice->confirmInvoice(); $PnagInvoice = null; $PnagInvoice = new PnagInvoice(CONFIGKEY, $transactionId); $PnagInvoice->setTransactionId($transactionId); $pnagArticles = array(); foreach ($articles as $article) { array_push($pnagArticles, array('itemId' => $article['articleId'], 'productNumber' => $article['articleNumber'], 'title' => $article['articleTitle'], 'description' => $article['articleDescription'], 'quantity' => $article['articleQuantity'], 'unitPrice' => number_format($article['articlePrice'], 2, '.', ''), 'tax' => number_format($article['articleTax'], 2, '.', ''))); } try { $comment = 'must not be left empty for confirmed invoices, editing an invoice will result in refunded items'; $PnagInvoice->updateInvoice($transactionId, $pnagArticles, $comment); } catch (XmlToArrayException $e) { } /** * Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an * array containing the HTTP server response header fields and content. */ function getWebPage($url)
/** * 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; }
/** * inserts a "new total" comment into shop order status history * @param int $orderId * @param string $status * @param date $time * @param PnagInvoice $PnagInvoice * @param float $lastShopTotal */ protected function _insertNewTotalCommentToHistory($orderId, $status, $time, PnagInvoice $PnagInvoice, $lastShopTotal) { $newTotal = $PnagInvoice->getAmount(); if ($newTotal > $lastShopTotal) { $comment = MODULE_PAYMENT_SOFORT_SR_TRANSLATE_CART_RESET . ' ' . MODULE_PAYMENT_SOFORT_SR_TRANSLATE_CURRENT_TOTAL . ' ' . $newTotal . ' Euro ' . MODULE_PAYMENT_SOFORT_SR_TRANSLATE_TIME . ': ' . $time; } else { $comment = MODULE_PAYMENT_SOFORT_SR_TRANSLATE_CART_EDITED . ' ' . MODULE_PAYMENT_SOFORT_SR_TRANSLATE_CURRENT_TOTAL . ' ' . $newTotal . ' Euro ' . MODULE_PAYMENT_SOFORT_SR_TRANSLATE_TIME . ': ' . $time; } $sqlDataArray = array('orders_id' => (int) $orderId, 'orders_status_id' => $status, 'date_added' => 'now()', 'customer_notified' => 0, 'comments' => $comment); shopDbPerform(TABLE_ORDERS_STATUS_HISTORY, $sqlDataArray); $sofortOrdersId = shopDbFetchArray(shopDbQuery('SELECT id FROM sofort_orders WHERE orders_id = "' . $orderId . '"')); HelperFunctions::insertSofortOrdersNotification($sofortOrdersId['id'], $PnagInvoice, $comment, $comment); }