function before_process()
 {
     global $order, $xtPrice;
     $currency = $_SESSION['currency'];
     $customer_id = $_SESSION['customer_id'];
     if (sizeof($order->delivery) != sizeof($order->billing)) {
         $display = null;
     } else {
         if (is_array($order->billing)) {
             foreach ($order->billing as $key => $val) {
                 if ($order->billing[$key] != $order->delivery[$key]) {
                     xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error_message=' . stripslashes(urlencode(html_entity_decode(MODULE_PAYMENT_BILLSAFE_2HP_ERROR_MESSAGE_ADDRESS))), 'SSL'));
                 }
             }
         }
     }
     //    if ($order->billing['company'] != '') xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error_message='.stripslashes(html_entity_decode(MODULE_PAYMENT_BILLSAFE_2HP_ERROR_MESSAGE_COMPANY)), 'SSL'));
     if (empty($_GET['token'])) {
         require_once DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/billsafe_2.php';
         //DokuMan - 2012-06-19 - move billsafe to external directory
         $bs = new Billsafe_Sdk(DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/ini.php');
         //DokuMan - 2012-06-19 - move billsafe to external directory
         if (MODULE_PAYMENT_BILLSAFE_2HP_LOG == 'true') {
             if (MODULE_PAYMENT_BILLSAFE_2HP_LOG_TYPE == 'Echo') {
                 require_once DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/LoggerEcho.php';
                 //DokuMan - 2012-06-19 - move billsafe to external directory
                 $bs->setLogger(new Billsafe_LoggerEcho());
             } elseif (MODULE_PAYMENT_BILLSAFE_2HP_LOG_TYPE == 'Mail') {
                 require_once DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/LoggerMail.php';
                 //DokuMan - 2012-06-19 - move billsafe to external directory
                 $bs->setLogger(new Billsafe_LoggerMail(MODULE_PAYMENT_BILLSAFE_2HP_LOG_ADDR));
             } elseif (MODULE_PAYMENT_BILLSAFE_2HP_LOG_TYPE == 'File') {
                 require_once DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/LoggerFile.php';
                 //DokuMan - 2012-06-19 - move billsafe to external directory
                 $bs->setLogger(new Billsafe_LoggerFile(DIR_FS_CATALOG . 'export/BillSAFE_' . date('YmdHis') . '.log'));
             }
         }
         if ($_SESSION['language_charset'] == 'iso-8859-1' || $_SESSION['language_charset'] == 'iso-8859-15') {
             $bs->setUtf8Mode(false);
         } else {
             $bs->setUtf8Mode(true);
         }
         if (MODULE_PAYMENT_BILLSAFE_2HP_SERVER == 'Live') {
             $bs->setMode('LIVE');
         } else {
             $bs->setMode('SANDBOX');
         }
         $bs->setCredentials(array('merchantId' => MODULE_PAYMENT_BILLSAFE_2HP_MERCHANT_ID, 'merchantLicenseSandbox' => MODULE_PAYMENT_BILLSAFE_2HP_MERCHANT_LICENSE, 'merchantLicenseLive' => MODULE_PAYMENT_BILLSAFE_2HP_MERCHANT_LICENSE, 'applicationSignature' => $this->applicationSignature, 'applicationVersion' => $this->application_version));
         $schg_tax = 0;
         $article = array();
         for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
             if (is_array($order->products[$i]['attributes'])) {
                 for ($ia = 0, $na = sizeof($order->products[$i]['attributes']); $ia < $na; $ia++) {
                     for ($iao = 0, $nao = sizeof($order->products[$i]['attributes'][$ia]['option']); $iao < $nao; $iao++) {
                         $att .= '-' . $order->products[$i]['attributes'][$ia]['value'];
                     }
                 }
             }
             $article[$i]['number'] = $order->products[$i]['model'] . $att;
             $article[$i]['name'] = $order->products[$i]['name'];
             $article[$i]['type'] = 'goods';
             $article[$i]['quantity'] = intval($order->products[$i]['qty']);
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
                 $article[$i]['netPrice'] = number_format($order->products[$i]['price'], 2, '.', '');
             } else {
                 $article[$i]['grossPrice'] = number_format($order->products[$i]['price'], 2, '.', '');
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0) {
                 $article[$i]['tax'] = number_format(0, 2, '.', '');
             } else {
                 $article[$i]['tax'] = number_format($order->products[$i]['tax'], 2, '.', '');
             }
             unset($att);
         }
         $shipping_cost = $order->info['shipping_cost'];
         if ($shipping_cost > 0) {
             $shipping_id = explode('_', $order->info['shipping_class']);
             $shipping_id = $shipping_id[0];
             $shipping_tax_rate = $this->get_shipping_tax_rate($shipping_id);
             $article[$i]['number'] = 'Versand';
             $article[$i]['name'] = $order->info['shipping_method'];
             $article[$i]['type'] = 'shipment';
             $article[$i]['quantity'] = 1;
             $shipping_cost = round($order->info['shipping_cost'] * $xtPrice->currencies[$currency]['value'], $xtPrice->get_decimal_places($currency));
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
                 $article[$i]['netPrice'] = number_format($shipping_cost, 2, '.', '');
             } else {
                 $shipping_cost = xtc_add_tax($shipping_cost, $shipping_tax_rate);
                 $article[$i]['grossPrice'] = number_format($shipping_cost, 2, '.', '');
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0) {
                 $article[$i]['tax'] = number_format(0, 2, '.', '');
             } else {
                 $article[$i]['tax'] = number_format($shipping_tax_rate, 2, '.', '');
             }
         } else {
             $i = $i - 1;
         }
         if ($_SESSION['discount_value'] != 0) {
             $discount_tax_rate = xtc_get_tax_rate('1');
             $i = $i + 1;
             $article[$i]['number'] = 'discount';
             $article[$i]['name'] = $_SESSION['discount_name'];
             $article[$i]['type'] = 'voucher';
             $article[$i]['quantity'] = 1;
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
                 $article[$i]['netPrice'] = number_format($_SESSION['discount_value'], 2, '.', '');
             } else {
                 $article[$i]['grossPrice'] = number_format($_SESSION['discount_value'], 2, '.', '');
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0) {
                 $article[$i]['tax'] = number_format(0, 2, '.', '');
             } else {
                 $article[$i]['tax'] = number_format($discount_tax_rate, 2, '.', '');
             }
         }
         if ($_SESSION['voucher_value'] != 0) {
             $i = $i + 1;
             $article[$i]['number'] = 'voucher';
             $article[$i]['name'] = $_SESSION['voucher_name'];
             $article[$i]['type'] = 'voucher';
             $article[$i]['quantity'] = 1;
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
                 $article[$i]['netPrice'] = number_format($_SESSION['voucher_value'], 2, '.', '');
             } else {
                 $article[$i]['grossPrice'] = number_format($_SESSION['voucher_value'], 2, '.', '');
             }
             $article[$i]['tax'] = number_format(0, 2, '.', '');
         }
         if ($_SESSION['coupon_value'] != 0) {
             if (MODULE_ORDER_TOTAL_COUPON_TAX_CLASS) {
                 $coupon_tax_rate = xtc_get_tax_rate(MODULE_ORDER_TOTAL_COUPON_TAX_CLASS);
             } else {
                 $coupon_tax_rate = xtc_get_tax_rate('1');
             }
             $i = $i + 1;
             $article[$i]['number'] = 'coupon';
             $article[$i]['name'] = $_SESSION['coupon_name'];
             $article[$i]['type'] = 'voucher';
             $article[$i]['quantity'] = 1;
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
                 $article[$i]['netPrice'] = number_format($_SESSION['coupon_value'], 2, '.', '');
             } else {
                 $article[$i]['grossPrice'] = number_format($_SESSION['coupon_value'], 2, '.', '');
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $article[$i]['tax'] = number_format($coupon_tax_rate, 2, '.', '');
                 $coupon_tax = $_SESSION['coupon_value'] * $coupon_tax_rate / 100;
             } elseif ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0) {
                 $article[$i]['tax'] = number_format(0, 2, '.', '');
                 $coupon_tax = 0;
             } else {
                 $article[$i]['tax'] = number_format($coupon_tax_rate, 2, '.', '');
                 $coupon_tax = $_SESSION['coupon_value'] - $_SESSION['coupon_value'] / (1 + $coupon_tax_rate / 100);
             }
         }
         if ($_SESSION['lofee_value'] != 0) {
             $lofee_tax_rate = xtc_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS);
             $i = $i + 1;
             $article[$i]['number'] = 'surcharge';
             $article[$i]['name'] = $_SESSION['lofee_name'];
             $article[$i]['type'] = 'goods';
             $article[$i]['quantity'] = 1;
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
                 $article[$i]['netPrice'] = number_format($_SESSION['lofee_value'], 2, '.', '');
             } else {
                 $article[$i]['grossPrice'] = number_format($_SESSION['lofee_value'], 2, '.', '');
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0) {
                 $article[$i]['tax'] = number_format(0, 2, '.', '');
                 $lofee_tax = 0;
             } else {
                 $article[$i]['tax'] = number_format($lofee_tax_rate, 2, '.', '');
                 $lofee_tax = $_SESSION['lofee_value'] - $_SESSION['lofee_value'] / (1 + $lofee_tax_rate / 100);
             }
         }
         $customer_query = xtc_db_query('SELECT customers_gender, DATE_FORMAT(customers_dob, "%Y-%m-%d") AS customers_dob, customers_email_address, customers_telephone from ' . TABLE_CUSTOMERS . ' WHERE customers_id = "' . xtc_db_input($customer_id) . '"');
         if (xtc_db_num_rows($customer_query)) {
             $customer = xtc_db_fetch_array($customer_query);
         }
         $shipping_tax = round($order->info['shipping_cost'] / 100 * $shipping_tax_rate, 2);
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
             $total = $order->info['subtotal'] + $order->info['tax'] + $shipping_tax + $_SESSION['discount_value'] + $_SESSION['voucher_value'] + $_SESSION['coupon_value'] + $coupon_tax + $_SESSION['lofee_value'];
         } else {
             $total = $order->info['subtotal'] + $_SESSION['discount_value'] + $_SESSION['voucher_value'] + $_SESSION['coupon_value'] + $_SESSION['lofee_value'];
         }
         $total = round($xtPrice->xtcCalculateCurrEx($total, $_SESSION['currency']), $xtPrice->get_decimal_places($_SESSION['currency']));
         $info_tax = $order->info['tax'];
         $total = number_format(round($total + $shipping_cost, $xtPrice->get_decimal_places($currency)), 2, '.', '');
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0) {
             $info_tax = number_format(0, 2, '.', '');
         } else {
             $info_tax = number_format(round($info_tax + $shipping_tax + $coupon_tax + $lofee_tax, $xtPrice->get_decimal_places($currency)), 2, '.', '');
         }
         $url_image = $this->checkLogoURL(MODULE_PAYMENT_BILLSAFE_2HP_SHOP_LOGO_URL);
         if ($customer['customers_gender'] != '') {
             $params = array('order_amount' => round($total, $xtPrice->get_decimal_places($currency)), 'order_taxAmount' => number_format($info_tax, 2, '.', ''), 'order_currencyCode' => $currency, 'customer' => array('id' => $customer_id, 'gender' => $customer['customers_gender'], 'company' => $order->delivery['company'], 'firstname' => $order->delivery['firstname'], 'lastname' => $order->delivery['lastname'], 'street' => $order->delivery['street_address'], 'postcode' => $order->delivery['postcode'], 'city' => $order->delivery['city'], 'country' => $order->delivery['country']['iso_code_2'], 'email' => $customer['customers_email_address'], 'phone' => $customer['customers_telephone']), 'product' => 'installment', 'url_return' => xtc_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL'), 'url_cancel' => xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'billsafe_close=true', 'SSL'), 'url_image' => $url_image, 'articleList' => $article);
         } else {
             $params = array('order_amount' => round($total, $xtPrice->get_decimal_places($currency)), 'order_taxAmount' => number_format($info_tax, 2, '.', ''), 'order_currencyCode' => $currency, 'customer' => array('id' => $customer_id, 'company' => $order->delivery['company'], 'firstname' => $order->delivery['firstname'], 'lastname' => $order->delivery['lastname'], 'street' => $order->delivery['street_address'], 'postcode' => $order->delivery['postcode'], 'city' => $order->delivery['city'], 'country' => $order->delivery['country']['iso_code_2'], 'email' => $customer['customers_email_address'], 'phone' => $customer['customers_telephone']), 'product' => 'installment', 'url_return' => xtc_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL'), 'url_cancel' => xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'billsafe_close=true', 'SSL'), 'url_image' => $url_image, 'articleList' => $article);
         }
         //      $_SESSION['bs_article'] = $article;
         if (!empty($customer['customers_dob']) && $customer['customers_dob'] != '0000-00-00') {
             $params['customer']['dateOfBirth'] = $customer['customers_dob'];
         }
         $response = $bs->callMethod('prepareOrder', $params);
         if ($response->ack == 'OK') {
             if (MODULE_PAYMENT_BILLSAFE_2HP_LAYER == 'true') {
                 $bs->callPaymentLayer($response->token);
             } else {
                 $bs->redirectToPaymentGateway($response->token);
             }
         } else {
             $message = $this->get_error_message($response);
             xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error_message=' . stripslashes(urlencode(html_entity_decode($message))), 'SSL'));
         }
     } else {
         $token = $_GET['token'];
         $check_query = xtc_db_query('SELECT token FROM billsafe_orders_2 WHERE token = "' . $token . '"');
         $check_token = xtc_db_num_rows($check_query);
         if ($check_token == 1) {
             xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error_message=' . stripslashes(urlencode(html_entity_decode(MODULE_PAYMENT_BILLSAFE_2HP_ERROR_MESSAGE_COMMON))), 'SSL'));
         }
         require_once DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/billsafe_2.php';
         //DokuMan - 2012-06-19 - move billsafe to external directory
         $bs = new Billsafe_Sdk(DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/ini.php');
         //DokuMan - 2012-06-19 - move billsafe to external directory
         if ($_SESSION['language_charset'] == 'iso-8859-1' || $_SESSION['language_charset'] == 'iso-8859-15') {
             $bs->setUtf8Mode(false);
         } else {
             $bs->setUtf8Mode(true);
         }
         if (MODULE_PAYMENT_BILLSAFE_2HP_SERVER == 'Live') {
             $bs->setMode("LIVE");
         } else {
             $bs->setMode("SANDBOX");
         }
         $bs->setCredentials(array('merchantId' => MODULE_PAYMENT_BILLSAFE_2HP_MERCHANT_ID, 'merchantLicenseSandbox' => MODULE_PAYMENT_BILLSAFE_2HP_MERCHANT_LICENSE, 'merchantLicenseLive' => MODULE_PAYMENT_BILLSAFE_2HP_MERCHANT_LICENSE, 'applicationSignature' => $this->applicationSignature, 'applicationVersion' => $this->application_version));
         $params = array('token' => $token);
         $this->response = $bs->callMethod('getTransactionResult', $params);
         if ($this->response->ack == 'OK' && $this->response->status == 'ACCEPTED') {
         } else {
             $_SESSION['billsafe_status'] = 'declined';
             xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error_message=' . stripslashes(urlencode(html_entity_decode(MODULE_PAYMENT_BILLSAFE_2HP_ERROR_MESSAGE_COMMON))), 'SSL'));
         }
     }
     return true;
 }
//DokuMan - 2012-06-19 - move billsafe to external directory
if ($_SESSION['language_charset'] == 'iso-8859-1' || $_SESSION['language_charset'] == 'iso-8859-15') {
    $bs->setUtf8Mode(false);
} else {
    $bs->setUtf8Mode(true);
}
if (MODULE_PAYMENT_BILLSAFE_2_SERVER == 'Live') {
    $bs->setMode('LIVE');
} else {
    $bs->setMode('SANDBOX');
}
if (MODULE_PAYMENT_BILLSAFE_2_LOG == 'True') {
    if (MODULE_PAYMENT_BILLSAFE_2_LOG_TYPE == 'Echo') {
        require_once DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/LoggerEcho.php';
        //DokuMan - 2012-06-19 - move billsafe to external directory
        $bs->setLogger(new Billsafe_LoggerEcho());
    } elseif (MODULE_PAYMENT_BILLSAFE_2_LOG_TYPE == 'Mail') {
        require_once DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/LoggerMail.php';
        //DokuMan - 2012-06-19 - move billsafe to external directory
        $bs->setLogger(new Billsafe_LoggerMail(MODULE_PAYMENT_BILLSAFE_2_LOG_ADDR));
    } elseif (MODULE_PAYMENT_BILLSAFE_2_LOG_TYPE == 'File') {
        require_once DIR_FS_CATALOG . 'includes/external/billsafe/classes/billsafe_2/LoggerFile.php';
        //DokuMan - 2012-06-19 - move billsafe to external directory
        $bs->setLogger(new Billsafe_LoggerFile(DIR_FS_CATALOG . 'export/BillSAFE_' . date('YmdHis') . '.log'));
    }
}
$bs->setCredentials(array('merchantId' => MODULE_PAYMENT_BILLSAFE_2_MERCHANT_ID, 'merchantLicenseSandbox' => MODULE_PAYMENT_BILLSAFE_2_MERCHANT_LICENSE, 'merchantLicenseLive' => MODULE_PAYMENT_BILLSAFE_2_MERCHANT_LICENSE, 'applicationSignature' => $ini['applicationSignature'], 'applicationVersion' => $ini['applicationVersion']));
$orders_query = xtc_db_query('SELECT id, transactionid, billsafeStatus FROM billsafe_orders_2 WHERE orderid = "' . xtc_db_input($order_id) . '"');
if (xtc_db_num_rows($orders_query) == 0) {
    $messageBox = 'ERROR';
    $message = MODULE_PAYMENT_BILLSAFE_2_NO_ORDERID;