/** * if cart is edited at shop, send new data to SOFORT * @param string $transactionId * @param array $articles * @param string $comment */ public function editArticlesSofort($transactionId, $articles, $comment = '') { $PnagInvoice = new PnagInvoice(shopGetConfigKey(), $transactionId); $sofortArticles = array(); $orderId = ''; $taxLow = 0; $taxHigh = 0; $subtotal = 0; $shipping = 0; $discount = array(); $agio = array(); foreach ($articles as $article) { if ($orderId == '') { $orderId = (int) $article['articleOrdersId']; } if ($article['articleQuantity'] != 'delete') { array_push($sofortArticles, array('itemId' => $article['articleId'], 'productNumber' => $article['articleNumber'], 'title' => HelperFunctions::convertEncoding($article['articleTitle'], 3), 'description' => HelperFunctions::convertEncoding($article['articleDescription'], 3), 'quantity' => $article['articleQuantity'], 'unitPrice' => number_format($article['articlePrice'], 2, '.', ''), 'tax' => number_format($article['articleTax'], 2, '.', ''))); } switch ($article['articleType']) { case 'shipping': $shipping = $article['articlePrice']; break; case 'discount': $splitItemId = explode('|', $article['articleId']); $discountClass = $splitItemId[1]; array_push($discount, array('class' => $discountClass, 'value' => $article['articlePrice'])); break; case 'agio': $splitItemId = explode('|', $article['articleId']); $agioClass = $splitItemId[1]; array_push($agio, array('class' => $agioClass, 'value' => $article['articlePrice'])); break; case 'product': $subtotal += $article['articleQuantity'] * $article['articlePrice']; break; } switch ($article['articleTax']) { case 7: $taxLow += $article['articleQuantity'] * $article['articlePrice']; break; case 19: $taxHigh += $article['articleQuantity'] * $article['articlePrice']; break; } } $lastShopTotal = HelperFunctions::getLastFieldValueFromSofortTable($orderId, 'amount'); $time = strftime('%Y-%m-%d %H:%M:%S', time()); $errors = $PnagInvoice->updateInvoice($transactionId, $sofortArticles, $comment); $warnings = $PnagInvoice->getWarnings(); if ($errors) { return array('errors' => $errors, 'warnings' => $warnings); } $PnagInvoice->refreshTransactionData(); $orderStatus = shopDbQuery('SELECT orders_status FROM ' . TABLE_ORDERS . ' WHERE orders_id = "' . $orderId . '"'); $orderStatus = shopDbFetchArray($orderStatus); $this->_insertNewTotalCommentToHistory($orderId, $orderStatus['orders_status'], $time, $PnagInvoice, $lastShopTotal); $this->editArticlesShop($PnagInvoice, $orderId); return false; }
/** * 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; }
} $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 * 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);
} $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) { $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);