/** * Insert serialized orderdata into shop-db, if it was not inserted by successUrl-call before * @return int orderId or die() in case of failures */ function handleOrderInsertion($transactionId, $paymentSecret, $paymentMethod, $customerId) { require_once HelperFunctions::getSofortOrderhandlingLink(); $SofortOrderhandling = new SofortOrderhandling(); //get serialized sessiondata $savedSession = $SofortOrderhandling->getSavedSessionData($transactionId, $paymentSecret); //Order was already saved if (!$savedSession) { usleep(10000); //avoid race-conditions between success-url and notification and needless error-mails $orderId = $SofortOrderhandling->getOrderId($transactionId, $paymentSecret); if (!$orderId) { //saved sessiondata was not found and no order-id exists xtc_db_query('UPDATE sofort_orders SET data_acquired = "0" WHERE payment_secret = "' . HelperFunctions::escapeSql($paymentSecret) . '" AND transaction_id = "' . HelperFunctions::escapeSql($transactionId) . '"'); $errors = array('description' => 'Order could not be saved in shop-DB and orderdata could not be found.', 'transactionId' => $transactionId, 'customerId' => $customerId, 'paymentmethod' => $paymentMethod); HelperFunctions::sendAdminErrorMail($errors); exit('Error: Order could not be saved.'); } else { return $orderId; } } else { //restore $_SESSION and $GLOBALS from saved serialized data $SofortOrderhandling->restoreGivenSessionDataToSession($savedSession); $insertData = $SofortOrderhandling->insertOrderIntoShop(); $orderId = $insertData['orderId']; $sofortData = $insertData['sofortData']; if (!$orderId) { xtc_db_query('UPDATE sofort_orders SET data_acquired = "0" WHERE payment_secret = "' . HelperFunctions::escapeSql($paymentSecret) . '" AND transaction_id = "' . HelperFunctions::escapeSql($transactionId) . '"'); $errors = array('description' => 'Order was MAYBE not successfully saved in shop-DB or Order-ID is unknown. Please check the order for completeness!', 'transactionId' => $transactionId, 'paymentmethod' => $paymentMethod, 'customerId' => $customerId, 'orderdata' => $savedSession); HelperFunctions::sendAdminErrorMail($errors); exit('Error: MAYBE order could not be saved. Please check!'); } else { // order was successfully saved, delete serialized session from db and send email to seller/customer $SofortOrderhandling->insertOrderIdInSofortTables($transactionId, $paymentSecret, $orderId); //save articleattributes (required for order-sync with SR) if ($paymentMethod == 'sr') { $SofortOrderhandling->insertOrderAttributesInSofortTables($orderId, $sofortData); } $SofortOrderhandling->deleteSavedSessionFromDb($transactionId, $paymentSecret); $SofortOrderhandling->insertTransIdInTableOrders($transactionId, $orderId); if ($paymentMethod == 'sr') { HelperFunctions::sendOrderIdToSofort(MODULE_PAYMENT_SOFORT_MULTIPAY_APIKEY, $transactionId, $orderId); } $SofortOrderhandling->sendOrderEmails($orderId); $SofortOrderhandling->doSpecialThingsAfterSuccessfulInsertion(); return $orderId; } } }
<?php /** * @version SOFORT Gateway 5.2.0 - $Date: 2012-09-13 11:51:22 +0200 (Thu, 13 Sep 2012) $ * @author SOFORT AG (integration@sofort.com) * @link http://www.sofort.com/ * * Copyright (c) 2012 SOFORT AG * * $Id: sofort.php 3770 2012-10-10 14:44:41Z gtb-modified $ */ require_once DIR_FS_CATALOG . 'callback/sofort/helperFunctions.php'; require_once HelperFunctions::getSofortOrderhandlingLink(); $language = HelperFunctions::getSofortLanguage($_SESSION['language']); require_once DIR_FS_CATALOG . 'lang/' . $language . '/modules/payment/sofort_general.php'; /** * helper function to mask given array items * @param mixed $item */ function maskSpecialChars(&$item) { HelperFunctions::htmlMaskArray($item); } /** * Superclass of xt-commerce modules */ class sofort { function sofort() { if (!isset($_SESSION['sofort'])) {