/**
  * 1st job: send order-data to SOFORT and in case of no errors save $_SESSION in sofort_orders and redirect to SOFORT-payment-url
  * 2nd job: manage orderInsertion, cleanup the module an other things while buyer came back from SOFORT after successful payment
  * @return redirect to errorPage OR redirect to paymentUrl OR redirect to successURL
  */
 function before_process()
 {
     global $order, $smarty;
     // if paymentSecret and transId are set, the customer has just successfully finished the SOFORT-wizard
     if (isset($_SESSION['sofort']['sofort_paymentSecret']) && $_SESSION['sofort']['sofort_paymentSecret'] && isset($_SESSION['sofort']['sofort_transactionId']) && $_SESSION['sofort']['sofort_transactionId'] && isset($_SESSION['sofort']['checkout_process']) && $_SESSION['sofort']['checkout_process'] == false) {
         $transactionId = $_SESSION['sofort']['sofort_transactionId'];
         $paymentSecret = $_SESSION['sofort']['sofort_paymentSecret'];
         unset($_SESSION['sofort']['sofort_transactionId']);
         unset($_SESSION['sofort']['sofort_paymentSecret']);
         $this->_finalizeOrderprocessAfterSuccessfulPayment($transactionId, $paymentSecret);
     }
     if ($this->code == "sofort_sofortrechnung") {
         if ($this->_orderHasVirtualProducts($order) || $this->_deliveryAddressDoesNotExist($order)) {
             $errors = array(0 => array('code' => '10003'));
             xtc_redirect(HelperFunctions::getCancelUrl($this->code, $errors));
         }
     }
     $apiCallResult = $this->_makeSofortApiCall();
     $apiCallErrors = $apiCallResult['apiCallErrors'];
     $paymentUrl = $apiCallResult['paymentUrl'];
     $transactionId = $apiCallResult['transactionId'];
     $paymentSecret = $apiCallResult['paymentSecret'];
     $orderTotalModules = $apiCallResult['orderTotalModules'];
     $orderTotals = $apiCallResult['orderTotals'];
     if ($apiCallErrors) {
         xtc_redirect(HelperFunctions::getCancelUrl($this->code, $apiCallErrors));
     }
     $sessionDataToSave = array();
     $sessionDataToSave['smarty'] = $smarty;
     $sessionDataToSave['order'] = $order;
     $sessionDataToSave['orderTotalModules'] = $orderTotalModules;
     $sessionDataToSave['orderTotals'] = $orderTotals;
     $sessionDataToSave['session'] = $_SESSION;
     $sessionDataToSave['globals'] = $GLOBALS;
     $sofortOrdersId = HelperFunctions::insertSofortOrder(0, $paymentSecret, $transactionId, $this->paymentMethod, $sessionDataToSave);
     if (!$sofortOrdersId) {
         $errors = array(0 => array('code' => '10004'));
         //saving in sofort_orders failed
         xtc_redirect(HelperFunctions::getCancelUrl($this->code, $errors));
     }
     $_SESSION['sofort']['sofort_transactionId'] = $transactionId;
     $_SESSION['sofort']['sofort_paymentSecret'] = $paymentSecret;
     $_SESSION['sofort']['sofort_payment_url'] = $paymentUrl;
     $_SESSION['sofort']['sofort_payment_method'] = $this->code;
     /*
     if (ENABLE_SSL == true) {
     	xtc_redirect(HTTPS_SERVER.DIR_WS_CATALOG.'callback/sofort/ressources/scripts/processSofortPayment.php');
     } else {
     	xtc_redirect(HTTP_SERVER.DIR_WS_CATALOG.'callback/sofort/ressources/scripts/processSofortPayment.php');
     }
     */
     xtc_redirect(xtc_href_link('callback/sofort/ressources/scripts/processSofortPayment.php', '', 'SSL'));
 }