Пример #1
0
 function onPaymentNotification(&$statuses)
 {
     $this->pluginParams();
     $configKey = $this->plugin_params->user_id . ':' . $this->plugin_params->project_id . ':' . $this->plugin_params->token;
     require_once dirname(__FILE__) . '/library/sofortLib.php';
     $notification = new SofortLib_Notification();
     $notification->getNotification();
     echo $notification->getTime();
     $transactionId = $notification->getTransactionId();
     //$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order_id.$this->url_itemid;
     // fetch some information for the transaction id retrieved above
     $transactionData = new SofortLib_TransactionData($configKey);
     $transactionData->setTransaction($transactionId);
     $transactionData->sendRequest();
     $method_id = $transactionData->getUserVariable(1);
     $this->pluginParams($method_id);
     $this->payment_params =& $this->plugin_params;
     global $Itemid;
     $this->url_itemid = empty($Itemid) ? '' : '&Itemid=' . $Itemid;
     $cancel_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=order&task=cancel_order' . $this->url_itemid;
     if (empty($this->payment_params)) {
         $this->redirect($cancel_url);
         return false;
     }
     $order_id = $transactionData->getUserVariable(0);
     echo $order_id;
     $dbOrder = $this->getOrder($order_id);
     if (empty($dbOrder)) {
         $this->redirect_url = $cancel_url;
         return false;
     }
     $history = new stdClass();
     $history->history_data = 'TransactionId: ' . $transactionId;
     $history->notified = 0;
     if ($transactionData->getStatus() == 'pending') {
         $email = new stdClass();
         $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Sofort', $transactionData->getStatus(), $dbOrder->order_number);
         $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Sofort', $transactionData->getStatus())) . "\r\n\r\n" . $transactionData->getStatusReason();
         $action = false;
         $order_status = $this->payment_params->pending_status;
         $this->modifyOrder($order_id, $order_status, $history, $email);
         return false;
     }
     if ($transactionData->getStatus() != 'received') {
         $order_status = 'created';
         $email = new stdClass();
         $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Sofort', $order_status)) . ' ' . JText::_('STATUS_NOT_CHANGED') . "\r\n\r\n" . $transactionData->getStatusReason();
         $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Sofort', $order_status, $dbOrder->order_number);
         $this->modifyOrder($order_id, $order_status, $history, $email);
         return false;
     }
     $order_status = $this->payment_params->verified_status;
     $history->history_data = 'TransactionId: ' . $transactionId;
     $history->notified = 1;
     $email = new stdClass();
     $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Sofort', $transactionData->getStatus(), $dbOrder->order_number);
     $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Sofort', $order_status)) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $order_status) . "\r\n\r\n" . $transactionData->getStatusReason();
     $this->modifyOrder($order_id, $order_status, $history, $email);
     return true;
 }
function sofort_ipn()
{
    global $edd_options;
    if (isset($_GET['sofort']) && $_GET['sofort'] == 'ipn') {
        require_once 'library/sofortLib.php';
        $notification = new SofortLib_Notification();
        $notification->getNotification();
        $transactionId = $notification->getTransactionId();
        if ($transactionId) {
            // fetch some information for the transaction id retrieved above
            $transactionData = new SofortLib_TransactionData(trim($edd_options['sofort_config_id']));
            $transactionData->setTransaction($transactionId);
            $transactionData->sendRequest();
            $reason = $transactionData->getReason();
            $payment_id = str_replace('CartId ', '', $reason[0]);
            edd_update_payment_status($payment_id, 'publish');
            edd_insert_payment_note($payment_id, 'Payment Successful. Transaction ID is ' . $transactionId);
        }
        exit;
    }
}
 /**
  * Construct the SofortLib_TransactionData object
  * Collect every order's item and set it accordingly
  * TransactionData is used encapsulated in this class to retrieve information about the order's details
  * @return object SofortLib_TransactionData
  * @private
  */
 private function _setupTransactionData()
 {
     $SofortLib_TransactionData = new SofortLib_TransactionData($this->_configKey, $this->_apiUrl);
     $SofortLib_TransactionData->setTransaction($this->_transactionId);
     $SofortLib_TransactionData->sendRequest();
     if (!$SofortLib_TransactionData->getCount()) {
         return false;
     }
     $this->setStatus($SofortLib_TransactionData->getStatus());
     $this->setStatusReason($SofortLib_TransactionData->getStatusReason());
     $this->setStatusOfInvoice($SofortLib_TransactionData->getInvoiceStatus());
     $this->setInvoiceObjection($SofortLib_TransactionData->getInvoiceObjection());
     $this->setLanguageCode($SofortLib_TransactionData->getLanguageCode());
     $this->setTransaction($this->getTransactionId());
     $this->setTime($SofortLib_TransactionData->getTime());
     $this->setPaymentMethod($SofortLib_TransactionData->getPaymentMethod());
     $this->setInvoiceUrl($SofortLib_TransactionData->getInvoiceUrl());
     $this->setAmount($SofortLib_TransactionData->getAmount());
     $this->setAmountRefunded($SofortLib_TransactionData->getAmountRefunded());
     $itemArray = $SofortLib_TransactionData->getItems();
     // should there be any items, fetch them accordingly
     $this->_items = array();
     if (is_array($itemArray) && !empty($itemArray)) {
         foreach ($itemArray as $item) {
             $this->setItem($item['item_id'], $item['product_number'], $item['product_type'], $item['title'], $item['description'], $item['quantity'], $item['unit_price'], $item['tax']);
             $this->_amount += $item['unit_price'] * $item['quantity'];
         }
     }
     /*
      * set the state according to the state given by transaction information (status, status_reason, invoice_status)
      * @see $statusMask
      */
     $this->setState($this->_calcInvoiceStatusCode());
     return $SofortLib_TransactionData;
 }
 /**
  * generates hash of status
  * 
  * @param SofortLib_TransactionData $transData
  */
 private function _getLastChanged($transData)
 {
     return sha1($transData->getStatus() . $transData->getStatusReason());
 }
Пример #5
0
 public function getPdf($invoices = array())
 {
     foreach ($invoices as $invoice) {
         if ($invoice->getOrder()->getPayment()->getMethod() != 'sofortrechnung') {
             return parent::getPdf($invoices);
         }
         break;
     }
     $this->_beforeGetPdf();
     $this->_initRenderer('invoice');
     $pdf = new Zend_Pdf();
     $this->_setPdf($pdf);
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
     foreach ($invoices as $invoice) {
         if ($invoice->getStoreId()) {
             Mage::app()->getLocale()->emulate($invoice->getStoreId());
             Mage::app()->setCurrentStore($invoice->getStoreId());
         }
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
         $pdf->pages[] = $page;
         $order = $invoice->getOrder();
         $tid = $order->getPayment()->getPnSuTransactionId();
         if (!empty($tid)) {
             $sObj = new SofortLib_TransactionData(Mage::getStoreConfig('payment/sofort/configkey'));
             $sObj->setTransaction($tid)->sendRequest();
             if ($sObj->isError()) {
                 Mage::throwException(Mage::helper('sales')->__($sObj->getError()));
                 return;
             } else {
                 $url = $sObj->getInvoiceUrl();
                 $pdf = file_get_contents($url);
                 return Zend_Pdf::parse($pdf);
             }
         }
         /* Add image */
         $this->insertLogo($page, $invoice->getStore());
         /* Add address */
         $this->insertAddress($page, $invoice->getStore());
         /* Add head */
         $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $this->_setFontRegular($page);
         $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');
         /* Add table */
         $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
         $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
         $page->setLineWidth(0.5);
         $page->drawRectangle(25, $this->y, 570, $this->y - 15);
         $this->y -= 10;
         /* Add table head */
         $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
         $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
         $this->y -= 15;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         /* Add body */
         foreach ($invoice->getAllItems() as $item) {
             if ($item->getOrderItem()->getParentItem()) {
                 continue;
             }
             if ($this->y < 15) {
                 $page = $this->newPage(array('table_header' => true));
             }
             /* Draw item */
             $page = $this->_drawItem($item, $page, $order);
         }
         /* Add totals */
         $page = $this->insertTotals($page, $invoice);
         if ($invoice->getStoreId()) {
             Mage::app()->getLocale()->revert();
         }
     }
     $this->_afterGetPdf();
     return $pdf;
 }
 /**
  * edit order if something changed
  * 
  * @param SofortLib_TransactionData $transData
  * @param Mage_Sales_Model_Order $order
  * @return boolean
  */
 public function updateOrderFromTransactionData($transData, $order)
 {
     // total amount without refunded
     $amount = number_format($order->getGrandTotal() - $order->getBaseTotalRefunded(), 2, '.', '');
     // if amount still the same, there was nothing edit
     if ($amount == $transData->getAmount()) {
         return false;
     }
     // transaction was cancel, nothing change, order will cancel full
     if ($transData->isLoss()) {
         return false;
     }
     // store items get from remote
     $checkItems = array();
     foreach ($transData->getItems() as $item) {
         $checkItems[$item['item_id']] = $item;
     }
     // order already invoice => create creditmemo
     if ($order->hasInvoices()) {
         return $this->_createCreditMemo($transData, $order, $checkItems);
     }
     // update total
     $order->setGrandTotal($transData->getAmount());
     $order->setBaseGrandTotal($transData->getAmount());
     $subTotal = 0;
     $taxAmount = array();
     // if discount value change the discount store on each row is broken
     // so we just remove it
     $removeDiscount = false;
     // edit discount amount
     if (empty($checkItems[2])) {
         $order->setDiscountAmount(0);
         $removeDiscount = true;
     } else {
         $order->setDiscountAmount($checkItems[2]['quantity'] * $checkItems[2]['unit_price']);
         $removeDiscount = true;
     }
     // check all items in the current order
     foreach ($order->getAllVisibleItems() as $item) {
         $uid = md5($item->getSku() . "-" . $item->getItemId());
         // if not exist it should removed
         if (empty($checkItems[$uid])) {
             // item was cancel
             $this->_cancelItem($item);
             unset($checkItems[$uid]);
             continue;
         }
         // quantity or price change, new row values will be calculated
         if ($checkItems[$uid]['quantity'] != $item->getQtyOrdered() || $item->getPrice() != $checkItems[$uid]['unit_price']) {
             $item->setQtyCanceled($item->getQtyOrdered() - $checkItems[$uid]['quantity']);
             $singleTax = $checkItems[$uid]['unit_price'] - $checkItems[$uid]['unit_price'] * (100 / ($checkItems[$uid]['tax'] + 100));
             $item->setPrice($checkItems[$uid]['unit_price'] - $singleTax);
             $item->setBasePrice($checkItems[$uid]['unit_price'] - $singleTax);
             $item->setPriceInclTax($checkItems[$uid]['unit_price']);
             $item->setBasePriceInclTax($checkItems[$uid]['unit_price']);
             $rowTotalInclTag = $checkItems[$uid]['quantity'] * $checkItems[$uid]['unit_price'];
             $rowTax = $rowTotalInclTag - $rowTotalInclTag * (100 / ($checkItems[$uid]['tax'] + 100));
             $rowTotal = $rowTotalInclTag - $rowTax;
             $item->setRowTotalInclTax($rowTotalInclTag);
             $item->setBaseRowTotalInclTax($rowTotalInclTag);
             $item->setRowTotal($rowTotal);
             $item->setBaseRowTotal($rowTotal);
             $item->setTaxAmount($rowTax);
             $item->setBaseTaxAmount($rowTax);
         }
         // add to subtotal
         $subTotal += $checkItems[$uid]['quantity'] * $checkItems[$uid]['unit_price'];
         // appent to tax group
         if (empty($taxAmount[$checkItems[$uid]['tax']])) {
             $taxAmount[$checkItems[$uid]['tax']] = 0;
         }
         $taxAmount[$checkItems[$uid]['tax']] += $item->getRowTotalInclTax();
         // remove discount from order row
         if ($removeDiscount) {
             $item->setDiscountPercent(0);
             $item->setDiscountAmount(0);
             $item->setBaseDiscountAmount(0);
         }
         unset($checkItems[$uid]);
     }
     // edit shipment amount if it was removed
     if (empty($checkItems[1]) && $order->getShippingAmount()) {
         $order->setShippingAmount(0);
         $order->setBaseShippingAmount(0);
         $order->setShippingTaxAmount(0);
         $order->setBaseShippingTaxAmount(0);
         $order->setShippingInclTax(0);
         $order->setBaseShippingInclTax(0);
     } else {
         $shippingWithTax = $checkItems[1]['quantity'] * $checkItems[1]['unit_price'];
         $shippingTax = $shippingWithTax - $shippingWithTax * (100 / ($checkItems[1]['tax'] + 100));
         $shippingAmount = $shippingWithTax - $shippingTax;
         $order->setShippingAmount($shippingAmount);
         $order->setBaseShippingAmount($shippingAmount);
         $order->setShippingTaxAmount($shippingTax);
         $order->setBaseShippingTaxAmount($shippingTax);
         $order->setShippingInclTax($shippingWithTax);
         $order->setBaseShippingInclTax($shippingWithTax);
     }
     // fix tax from discount and shipping
     foreach ($checkItems as $item) {
         if (empty($taxAmount[$item['tax']])) {
             $taxAmount[$item['tax']] = 0;
         }
         $taxAmount[$item['tax']] += $item['unit_price'] * $item['quantity'];
     }
     // update subtotal
     $order->setBaseSubtotalInclTax($subTotal);
     $order->setSubtotalInclTax($subTotal);
     // sum for all tax amount
     $totalTaxAmount = 0;
     // update all tax rate items
     $rates = Mage::getModel('tax/sales_order_tax')->getCollection()->loadByOrder($order);
     foreach ($rates as $rate) {
         // format rate
         $tRate = sprintf("%01.2f", $rate->getPercent());
         if (!empty($taxAmount[$tRate])) {
             // calc new tax value
             $tAmount = $taxAmount[$tRate] - $taxAmount[$tRate] * (100 / ($tRate + 100));
             $totalTaxAmount += $tAmount;
             $rate->setAmount($tAmount);
             $rate->setBaseAmount($tAmount);
             $rate->setBaseRealAmount($tAmount);
             $rate->save();
         }
     }
     // update total tax amount
     $order->setTaxAmount($totalTaxAmount);
     $order->setBaseTaxAmount($totalTaxAmount);
     // update subtotal without tax
     $order->setBaseSubtotal($subTotal - $totalTaxAmount + $order->getShippingTaxAmount());
     $order->setSubtotal($subTotal - $totalTaxAmount + $order->getShippingTaxAmount());
     $order->save();
     return true;
 }
Пример #7
0
 * @author SOFORT AG (integration@sofort.com)
 * @link http://www.sofort.com/
 *
 * Copyright (c) 2012 SOFORT AG
 *
 * $Id: testAuth.php 3751 2012-10-10 08:36:20Z gtb-modified $
 */
chdir('../../../../');
require_once 'includes/application_top.php';
require_once DIR_FS_CATALOG . 'callback/sofort/helperFunctions.php';
$language = HelperFunctions::getSofortLanguage($_SESSION['language']);
include_once DIR_FS_CATALOG . 'lang/' . $language . '/modules/payment/sofort_general.php';
if ($_SESSION['customers_status']['customers_status_id'] == '0') {
    ob_start();
    require_once dirname(__FILE__) . '/../../library/sofortLib.php';
    preg_match('#([0-9]{5,6}\\:[0-9]{5,6}\\:[a-z0-9]{32})#', $_POST['k'], $matches);
    $configKey = $matches[1];
    $SofortLib_TransactionData = new SofortLib_TransactionData($configKey);
    $SofortLib_TransactionData->setTransaction('00000')->sendRequest();
    if ($SofortLib_TransactionData->isError()) {
        xtc_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = '" . MODULE_PAYMENT_SOFORT_KEYTEST_ERROR_DESC . "' WHERE configuration_key = 'MODULE_PAYMENT_SOFORT_MULTIPAY_AUTH'");
        xtc_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = '' WHERE configuration_key = 'MODULE_PAYMENT_SOFORT_MULTIPAY_APIKEY'");
        ob_end_clean();
        echo "f" . MODULE_PAYMENT_SOFORT_KEYTEST_ERROR;
    } else {
        xtc_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = '" . MODULE_PAYMENT_SOFORT_KEYTEST_SUCCESS_DESC . " " . date("d.m.Y") . "' WHERE configuration_key = 'MODULE_PAYMENT_SOFORT_MULTIPAY_AUTH'");
        xtc_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = '" . $configKey . "' WHERE configuration_key = 'MODULE_PAYMENT_SOFORT_MULTIPAY_APIKEY'");
        ob_end_clean();
        echo "t" . MODULE_PAYMENT_SOFORT_KEYTEST_SUCCESS;
    }
}
Пример #8
0
 /**
  * This action handles the asynchronous callbacks
  * The sofortLib is used to obtain data about
  */
 public function notifyAction()
 {
     Shopware()->Plugins()->Controller()->ViewRenderer()->setNoRender();
     $helper = new Shopware_Plugins_Frontend_SofortPayment_Components_Helpers_Helper();
     $configKey = $helper->option()->getConfigKey("sofortbanking");
     //Step 3: Handling Notifications about status changes
     $notification = $helper->library()->getNotificationInstance();
     $notification->setLogger(new Shopware_Plugins_Frontend_SofortPayment_Components_Services_Logger());
     $notification->setLogEnabled();
     $notification->getNotification();
     $transactionId = $notification->getTransactionId();
     //Step 4: Inquire changed Transactiondata
     $transactionData = new SofortLib_TransactionData($configKey);
     $transactionData->setTransaction($transactionId);
     $transactionData->sendRequest();
     //Step 5: Handling the Response to the Inquiry for changed Transaction Data
     $orderId = $helper->database()->getOrderByTransactionId($transactionId);
     $state = $this->convertLibState($transactionData->getStatus(), $transactionData->getStatusReason());
     $order = Shopware()->Modules()->Order();
     if ($state != 0) {
         $order->setPaymentStatus($orderId, $state, false);
         $order->setOrderStatus($orderId, 0, false);
     }
 }
 public function getLastTransactions($limit = null)
 {
     $from = date(FORMAT_DB_DATE, time() - DAY);
     $to = date(FORMAT_DB_DATE);
     //die(returns($this->settings));
     $transactionDataObj = new SofortLib_TransactionData($this->_configKey());
     $transactionDataObj->setTime($from, $to);
     if ($limit) {
         $transactionDataObj->setNumber($limit);
     }
     $res = $transactionDataObj->sendRequest();
     if (!empty($res->errors)) {
         trigger_error(returns($this->errors));
         return false;
     }
     return $transactionDataObj->getTransaction(0);
 }
Пример #10
0
 private function _setupTransactionData()
 {
     $SofortLib_TransactionData = new SofortLib_TransactionData($this->_configKey, $this->_apiUrl);
     $SofortLib_TransactionData->setTransaction($this->_transactionId);
     $SofortLib_TransactionData->sendRequest();
     if (!$SofortLib_TransactionData->getCount()) {
         return false;
     }
     $this->setStatus($SofortLib_TransactionData->getStatus());
     $this->setStatusReason($SofortLib_TransactionData->getStatusReason());
     $this->setStatusOfInvoice($SofortLib_TransactionData->getInvoiceStatus());
     $this->setInvoiceObjection($SofortLib_TransactionData->getInvoiceObjection());
     $this->setLanguageCode($SofortLib_TransactionData->getLanguageCode());
     $this->setTransaction($this->getTransactionId());
     $this->setTime($SofortLib_TransactionData->getTime());
     $this->setPaymentMethod($SofortLib_TransactionData->getPaymentMethod());
     $this->setInvoiceUrl($SofortLib_TransactionData->getInvoiceUrl());
     $this->setAmount($SofortLib_TransactionData->getAmount());
     $this->setAmountRefunded($SofortLib_TransactionData->getAmountRefunded());
     $itemArray = $SofortLib_TransactionData->getItems();
     $this->_items = array();
     if (is_array($itemArray) && !empty($itemArray)) {
         foreach ($itemArray as $item) {
             $this->setItem($item['item_id'], $item['product_number'], $item['product_type'], $item['title'], $item['description'], $item['quantity'], $item['unit_price'], $item['tax']);
             $this->_amount += $item['unit_price'] * $item['quantity'];
         }
     }
     $this->setState($this->_calcInvoiceStatusCode());
     return $SofortLib_TransactionData;
 }
/**
 * Copyright (c) 2012 SOFORT AG
 * 
 * Released under the GNU General Public License (Version 2)
 * [http://www.gnu.org/licenses/gpl-2.0.html]
 *
 * $Date$
 * @version SofortLib 1.5.0rc  $Id$
 * @author SOFORT AG http://www.sofort.com (integration@sofort.com)
 *
 */
// read the notification from php://input  (http://php.net/manual/en/wrappers.php.php)
// this class should be used as a callback function
require_once '../../library/sofortLib.php';
$notification = new SofortLib_Notification();
$notification->getNotification();
echo $notification->getTime();
$transactionId = $notification->getTransactionId();
// fetch some information for the transaction id retrieved above
$transactionData = new SofortLib_TransactionData();
$transactionData->setTransaction($transactionId);
$transactionData->sendRequest();
echo '<table border="1">';
echo '<tr><td>transaction was: </td><td align="right">' . $transactionData->getTransaction() . '</td></tr>';
echo '<tr><td>start date is: </td><td align="right">' . $transactionData->getSofortaboStartDate() . '</td></tr>';
echo '<tr><td>amount is: </td><td align="right">' . $transactionData->getAmount() . ' ' . $transactionData->getCurrency() . '</td></tr>';
echo '<tr><td>interval is: </td><td align="right">' . $transactionData->getSofortaboInterval() . '</td></tr>';
echo '<tr><td>minimum payments: </td><td align="right">' . $transactionData->getSofortaboMinimumPayments() . '</td></tr>';
echo '<tr><td>status is: </td><td align="right">' . $transactionData->getStatus() . ' - ' . $transactionData->getStatusReason() . '</td></tr>';
echo '</table>';
 /**
  * handle request to update invoice items and send request to remote service
  * 
  */
 public function postAction()
 {
     $order = $this->_initOrder();
     $params = $this->getRequest()->getParams();
     $session = Mage::getSingleton('adminhtml/session');
     $sofortRechnung = Mage::getModel('pnsofortueberweisung/sofortrechnung');
     // if everythink empty, cancel invoice
     if (!empty($params['line']) && array_sum($params['line']) == 0) {
         if ($order->canUnhold()) {
             $order->unhold();
             $order->save();
         }
         if ($order->canCancel()) {
             $order->cancel();
             $order->save();
         }
         $payment = $order->getPayment();
         $invoice = Mage::getModel('pnsofortueberweisung/sofortrechnung');
         $invoice->refund($payment, null);
     } else {
         if (!empty($params['line'])) {
             // generate old send parameters
             $invoice = $sofortRechnung->createPaymentFromOrder($order);
             // get old items
             $items = $invoice->getSofortrechnungItems();
             // new item array
             $newItems = array();
             // mark change
             $change = false;
             // check all old items
             foreach ($items['item'] as $line) {
                 // increase quantity not allowed
                 if ($line['quantity'] < $params['line'][$line['item_id']]) {
                     $this->_getSession()->addError($this->__('quantity increase is not allowed'));
                     $this->_redirect('*/*/edit', array('order_id' => $order->getId()));
                     return false;
                 }
                 // only quantity change
                 if (array_key_exists($line['item_id'], $params['line']) && $line['quantity'] != $params['line'][$line['item_id']]) {
                     $change = true;
                     $line['quantity'] = $params['line'][$line['item_id']];
                 }
                 if (!empty($params['price'][$line['item_id']])) {
                     // increase price not allowed
                     if ($line['unit_price'] < $params['price'][$line['item_id']]) {
                         $this->_getSession()->addError($this->__('price increase is not allowed'));
                         $this->_redirect('*/*/edit', array('order_id' => $order->getId()));
                         return false;
                     }
                     $change = true;
                     $line['unit_price'] = $params['price'][$line['item_id']];
                 }
                 // if quantity is greater as null
                 if (!empty($line['quantity'])) {
                     $newItems[] = $line;
                 }
             }
             // if something change we send the request
             if ($change) {
                 try {
                     $sofortRechnung->updateInvoice($order->getPayment(), $newItems, $params['comment']);
                 } catch (Exception $e) {
                     Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                     $this->_redirect('*/*/edit', array('order_id' => $order->getId()));
                     return false;
                 }
             }
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('pnsofortueberweisung')->__('Item was successfully saved'));
         }
     }
     // ****** start edit local order ***************
     $payment = $order->getPayment();
     $transaction = $payment->getAdditionalInformation('sofort_transaction');
     $transData = new SofortLib_TransactionData(Mage::getStoreConfig('payment/sofort/configkey'));
     // loaded updatet data from remote host
     $transData->setTransaction($transaction)->sendRequest();
     if ($transData->isError()) {
         Mage::log('Update invalid: ' . __CLASS__ . ' ' . __LINE__ . $transData->getError());
         Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('pnsofortueberweisung')->__('Item was successfully saved, order can not change'));
         $this->_redirect('*/*');
         return;
     }
     // update local order
     $sofortRechnung->updateOrderFromTransactionData($transData, $order);
     // ****** end edit local order ***************
     $this->_redirect('adminhtml/sales_order/view', array('order_id' => $order->getId()));
     return false;
 }
<?php

/**
 * 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.0rc  $Id: example_transactionData.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', '12345:67890:123456789abcdef123456abcdef12345');
//your configkey or userid:projektid:apikey
$sofort = new SofortLib_TransactionData(CONFIGKEY);
// use an array of transactionIDs (or set a single transactionID if you like, just pass a string to setTransaction)
$transactionIds[] = '16263-99178-4E019D4F-5E12';
$transactionIds[] = '16263-99178-4E01B143-5E25';
$sofort->setTransaction($transactionIds);
// or simply add a single transactionID, using addTransaction (you could easily add an array of transactionIDs as well!)
$singleTransactionId = '16263-99178-4E01B5E0-1ACD';
$sofort->addTransaction($singleTransactionId);
$sofort->sendRequest();
// get the information you need, depends on what transaction you where looking for...
echo 'Amount: ' . $sofort->getAmount(0) . "<br />";
echo 'Status: ' . $sofort->getStatus(0);
 /**
  * validate given api-key against SOFORT and return result
  * @return bool
  */
 function apiKeyIsValid($apiKey)
 {
     preg_match('#([a-zA-Z0-9:]+)#', $apiKey, $matches);
     $configKey = $matches[1];
     $SofortLib_TransactionData = new SofortLib_TransactionData($configKey);
     $SofortLib_TransactionData->setTransaction('00000')->sendRequest();
     if ($SofortLib_TransactionData->isError()) {
         return false;
     } else {
         return true;
     }
 }
Пример #15
0
 /**
  * @return bool|null
  */
 function plgVmOnPaymentNotification()
 {
     //$this->_debug = true;
     if (!class_exists('VirtueMartModelOrders')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php';
     }
     $order_number = JRequest::getString('on', '');
     if (empty($order_number)) {
         $this->logInfo('plgVmOnPaymentNotification EMPTY order number' . $order_number, 'message');
         return FALSE;
     }
     if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) {
         $this->logInfo('plgVmOnPaymentNotification NO getOrderIdByOrderNumber ' . $order_number, 'message');
         return FALSE;
     }
     if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) {
         $this->logInfo('plgVmOnPaymentNotification NO getDatasByOrderId ' . $virtuemart_order_id, 'message');
         return FALSE;
     }
     $this->logInfo('plgVmOnPaymentNotification OK ', 'message');
     $method = $this->getVmPluginMethod($payments[0]->virtuemart_paymentmethod_id);
     if (!$this->selectedThisElement($method->payment_element)) {
         return FALSE;
     }
     if (!class_exists('SofortLib')) {
         require JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'sofort' . DS . 'sofort' . DS . 'library' . DS . 'sofortLib.php';
     }
     $sofortLib_Notification = new SofortLib_Notification();
     $transactionId = $sofortLib_Notification->getNotification();
     //no valid parameters/xml
     if (empty($transactionId) || $sofortLib_Notification->isError()) {
         $this->logInfo('plgVmOnPaymentNotification NO transaaction or $sofortLib_Notification is error \\n', 'message');
         return FALSE;
     }
     $this->logInfo('plgVmOnPaymentNotification transaction ' . $transactionId, 'message');
     $sofortLib_TransactionData = new SofortLib_TransactionData($method->configuration_key);
     $sofortLib_TransactionData->setTransaction($transactionId)->sendRequest();
     $this->logInfo('plgVmOnPaymentNotification setTransaction OK', 'message');
     // check that secret , and order are identical
     $security = JRequest::getString('security', '');
     if ($security != $payments[0]->security) {
         $this->logInfo('plgVmOnPaymentNotification SECURITY not the one expected GOT: ' . $security . ' stored: ' . $payments[0]->security, 'message');
         $emailBody = "Hello,\n\nerror while receiving a SOFORT NOTIFICATION" . "\n";
         $emailBody .= "for order number: " . $order_number . "\n";
         $emailBody .= "security token received: " . $security . "\n";
         $emailBody .= "security token expected: " . $payments[0]->security . "\n";
         $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_SOFORT_ERROR_NOTIFICATION'), $emailBody);
         return false;
     }
     $paymentMethod = $sofortLib_TransactionData->getPaymentMethod();
     if ($paymentMethod != self::SU_SOFORTBANKING) {
         // answer not expected
         $this->logInfo('plgVmOnPaymentNotification not the one one expected?' . $paymentMethod . ' ' . self::SU_SOFORTBANKING, 'message');
         $emailBody = "Hello,\n\nerror while receiving a SOFORT NOTIFICATION" . "\n";
         $emailBody .= "Payment method is " . $paymentMethod . " Should be SU \n";
         $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_SOFORT_ERROR_NOTIFICATION'), $emailBody);
         return false;
     }
     $this->logInfo('plgVmOnPaymentNotification so', 'message');
     $sofort_data['sofort_response_amount'] = $sofortLib_TransactionData->getAmount();
     $sofort_data['sofort_response_currency'] = $sofortLib_TransactionData->getCurrency();
     // check that the amount is the same
     if (!$this->_checkAmountAndCurrency($sofort_data, $payments)) {
         return false;
     }
     $modelOrder = VmModel::getModel('orders');
     $order = array();
     $status = 'status_' . $sofortLib_TransactionData->getStatus();
     //$this->logInfo('plgVmOnPaymentNotification getStatus:' .$status. ' '.var_export($method, true) , 'message');
     $order['customer_notified'] = true;
     $order['order_status'] = $method->{$status};
     $order['comments'] = JText::_('VMPAYMENT_SOFORT_RESPONSE_STATUS_REASON_' . $sofortLib_TransactionData->getStatusReason());
     $sofort_data['sofort_response_status_reason'] = $sofortLib_TransactionData->getStatusReason();
     $sofort_data['sofort_response_transaction'] = $sofortLib_TransactionData->getTransaction();
     $sofort_data['payment_name'] = str_replace(array('\\t', '\\n'), '', $this->renderPluginName($method));
     $sofort_data['virtuemart_order_id'] = $payments[0]->virtuemart_order_id;
     $sofort_data['order_number'] = $payments[0]->order_number;
     $sofort_data['virtuemart_paymentmethod_id'] = $payments[0]->virtuemart_paymentmethod_id;
     $sofort_data['sofort_response_status'] = $sofortLib_TransactionData->getStatus();
     $sofort_data['sofort_response_status_reason'] = $sofortLib_TransactionData->getStatusReason();
     $this->logInfo('storePSPluginInternalData before storePSPluginInternalData ' . var_export($sofort_data, true), 'message');
     $this->storePSPluginInternalData($sofort_data);
     $modelOrder->updateStatusForOneOrder($payments[0]->virtuemart_order_id, $order, TRUE);
 }
Пример #16
0
 /**
  * @return bool|null
  */
 function plgVmOnPaymentNotification()
 {
     //$this->_debug = true;
     if (!class_exists('VirtueMartModelOrders')) {
         require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php';
     }
     $order_number = vRequest::getString('on', '');
     if (empty($order_number)) {
         return FALSE;
     }
     if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) {
         return FALSE;
     }
     if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) {
         return FALSE;
     }
     $this->debugLog('OK', 'plgVmOnPaymentNotification', 'debug');
     $this->_currentMethod = $this->getVmPluginMethod($payments[0]->virtuemart_paymentmethod_id);
     if (!$this->selectedThisElement($this->_currentMethod->payment_element)) {
         return FALSE;
     }
     if (!class_exists('SofortLib')) {
         require VMPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'sofort' . DS . 'sofort' . DS . 'library' . DS . 'sofortLib.php';
     }
     $sofortLib_Notification = new SofortLib_Notification();
     $transactionId = $sofortLib_Notification->getNotification();
     //no valid parameters/xml
     if (empty($transactionId) || $sofortLib_Notification->isError()) {
         $this->debugLog('no transaction ID for order number' . $order_number, 'plgVmOnPaymentNotification', 'error');
         return FALSE;
     }
     $this->debugLog($transactionId, 'plgVmOnPaymentNotification Transaction ID ', 'debug');
     $sofortLib_TransactionData = new SofortLib_TransactionData(trim($this->_currentMethod->configuration_key));
     $sofortLib_TransactionData->setTransaction($transactionId)->sendRequest();
     // check that secret , and order are identical
     $security = vRequest::getString('security', '');
     if ($security != $payments[0]->security) {
         $this->debugLog("security token received: " . $security . " security token expected: " . $payments[0]->security, 'plgVmOnPaymentNotification', 'error');
         return false;
     }
     $paymentMethod = $sofortLib_TransactionData->getPaymentMethod();
     if ($paymentMethod != self::SU_SOFORTBANKING) {
         $this->debugLog("Payment method is " . $paymentMethod . " Should be SU" . 'plgVmOnPaymentNotification', 'error');
         return false;
     }
     $sofort_data['sofort_response_amount'] = $sofortLib_TransactionData->getAmount();
     $sofort_data['sofort_response_currency'] = $sofortLib_TransactionData->getCurrency();
     // check that the amount is the same
     if (!$this->_checkAmountAndCurrency($sofort_data, $payments)) {
         return false;
     }
     $modelOrder = VmModel::getModel('orders');
     $order_history = array();
     $status = 'status_' . $sofortLib_TransactionData->getStatus();
     //$this->debugLog('plgVmOnPaymentNotification getStatus:' .$status. ' '.var_export($method, true) , 'message');
     $order_history['customer_notified'] = true;
     $order_history['order_status'] = $this->_currentMethod->{$status};
     $order_history['comments'] = vmText::_('VMPAYMENT_SOFORT_RESPONSE_STATUS_REASON_' . $sofortLib_TransactionData->getStatusReason());
     $sofort_data['sofort_response_status_reason'] = $sofortLib_TransactionData->getStatusReason();
     $sofort_data['sofort_response_transaction'] = $sofortLib_TransactionData->getTransaction();
     $sofort_data['payment_name'] = str_replace(array('\\t', '\\n'), '', $this->renderPluginName($this->_currentMethod));
     $sofort_data['virtuemart_order_id'] = $payments[0]->virtuemart_order_id;
     $sofort_data['order_number'] = $payments[0]->order_number;
     $sofort_data['virtuemart_paymentmethod_id'] = $payments[0]->virtuemart_paymentmethod_id;
     $sofort_data['sofort_response_status'] = $sofortLib_TransactionData->getStatus();
     $sofort_data['sofort_response_status_reason'] = $sofortLib_TransactionData->getStatusReason();
     $this->debugLog(var_export($sofort_data, true), 'plgVmOnPaymentNotification storePSPluginInternalData ', 'debug');
     $this->storePSPluginInternalData($sofort_data);
     $modelOrder->updateStatusForOneOrder($payments[0]->virtuemart_order_id, $order_history, false);
 }
 /**
  * Construct the SofortLib_TransactionData object
  * Collect every order's item and set it accordingly
  * TransactionData is used encapsulated in this class to retrieve information about the order's details
  * @return object SofortLib_TransactionData
  * @private
  */
 function _setupTransactionData()
 {
     $obj = new SofortLib_TransactionData($this->apiKey, $this->apiUrl);
     $this->_deleteLocalPnagArticles();
     //delete "old" pnag-articles before updating them
     $response = $obj->setTransaction($this->transactionId);
     $response->sendRequest();
     if (!isset($obj->response[0])) {
         return false;
     } else {
         $transactionData = $obj->response[0];
     }
     $this->setStatus($transactionData['status']);
     $this->setStatusReason($transactionData['status_reason']);
     $this->setTransaction($this->transactionId);
     $this->setTime($transactionData['time']);
     $this->setPaymentMethod($transactionData['payment_method']);
     $this->setInvoiceUrl($transactionData['invoice_url']);
     if (isset($transactionData['item'])) {
         $itemArray = $transactionData['item'];
     } else {
         $itemArray = array();
     }
     // should there be any items, fetch them accordingly
     if (is_array($itemArray) && !empty($itemArray)) {
         foreach ($itemArray as $item) {
             $this->setPnagArticle($item['item_id'], $item['product_number'], $item['product_type'], $item['title'], $item['description'], $item['quantity'], $item['unit_price'], $item['tax']);
         }
     }
     return $obj;
 }