$sign = strtoupper(md5($sign_string));
        $bill_output['code'] = $_POST['VPSSignature'] == $sign ? 1 : 3;
        $bill_output['billmes'] = ($_POST['VPSSignature'] == $sign ? '' : 'VPSSignature is incorrect! ') . 'AuthNo: ' . $_POST['TxAuthNo'];
    } else {
        $bill_output['code'] = 2;
        $bill_output['billmes'] = 'Status: ' . $_POST['StatusDetail'] . ' (' . $_POST['Status'] . ') ';
    }
    $arr = array('TxID' => 'VPSTxID', 'AVS/CVV2' => 'AVSCV2', 'AddressResult' => 'AddressResult', 'PostCodeResult' => 'PostCodeResult', 'CV2Result' => 'CV2Result', '3DSecureStatus' => '3DSecureStatus', 'CAVV' => 'CAVV', 'PayerStatus' => 'PayerStatus', 'CardType' => 'CardType', 'Last4Digits' => 'Last4Digits');
    foreach ($arr as $k => $v) {
        if (!empty($_POST[$v])) {
            $bill_output['billmes'] .= "\n\r" . $k . ': ' . $_POST[$v];
        }
    }
} else {
    $bill_output["billmes"] = "Wrong request method or empty data.";
    $bill_output['code'] = 2;
}
$return = cw_call('cw_payment_check_results', array($bill_output));
$cart =& cw_session_register('cart', array());
$top_message =& cw_session_register('top_message');
if ($return['bill_error']) {
    $top_message = array('type' => 'E', 'content' => $return['bill_error'] . ' ' . $return['reason']);
    $request = $app_catalogs['customer'] . '/index.php?target=cart&mode=checkout';
} else {
    $_doc_ids = cw_get_urlencoded_doc_ids($return['doc_ids']);
    $request = $current_location . "/index.php?target=order-message&doc_ids=" . $_doc_ids;
    $cart = array();
    cw_session_save();
}
echo "Status=OK\r\n" . "RedirectURL=" . $request . "\r\n" . "StatusDetail=\r\n";
exit;
function cw_payment_stop($payment_data)
{
    global $app_catalogs, $customer_id;
    cw_load('cart_process');
    $cart =& cw_session_register('cart', array());
    $top_message =& cw_session_register('top_message');
    if ($payment_data['bill_error']) {
        $top_message = array('type' => 'E', 'content' => $payment_data['bill_error'] . ' ' . $payment_data['reason']);
        $request = $app_catalogs['customer'] . '/index.php?target=cart&mode=checkout';
    } else {
        $_doc_ids = cw_get_urlencoded_doc_ids($payment_data['doc_ids']);
        $request = $app_catalogs['customer'] . "/index.php?target=order-message&doc_ids=" . $_doc_ids;
        $cart = array();
        cw_session_save();
        cw_save_customer_cart($customer_id, $cart);
    }
    cw_header_location($request);
}