if (!$user_id) {
    header('Location: ' . $baseurl . '#login');
    exit;
}
$cpid = isset($_POST['cpid']) ? $_POST['cpid'] : 0;
$cc_id = isset($_POST['cc_id']) ? $_POST['cc_id'] : 0;
$bill_id = isset($_POST['bill_id']) ? $_POST['bill_id'] : 0;
$cc_cvc = isset($_POST['cc_cvc']) ? $_POST['cc_cvc'] : 0;
$ret = false;
if (!$cc_id or !$cc_id or !$bill_id) {
    header('Location: ' . $baseurl . '/balance.php');
    exit;
}
$cp = getCoinPackage($cpid);
$cc = getCreditCard($cc_id);
$bi = getBillAddress($bill_id);
$tax = $cp['cpamount'] * ($config['sale_tax'] / 100);
$order_total = $cp['cpamount'] - $tax;
$coin_amount = $cp['cpcoin'];
$tx_method = 'cc';
$ret = buyCoin($user_id, $cc_id, $bill_id, $cpid, $tx_method, $order_total, $coin_amount, $cc_cvc);
if ($ret['status'] == 'error') {
    // redirect to error page
    exit;
}
$homemenu = 'active';
?>
<!DOCTYPE HTML>
<html>
<?php 
include $basedir . '/common/header.php';
function getPaymentInfo($user_id = 0, $cc_id = 0)
{
    $data = array();
    if ($user_id) {
        $q = "SELECT * FROM users_cc WHERE user_id = '{$user_id}'";
        $result = mysql_query($q);
        $numrows = mysql_num_rows($result);
        if ($numrows) {
            $i = 0;
            while ($row = mysql_fetch_array($result)) {
                $bill_id = $row['bill_id'];
                $data[$i] = $row;
                $data[$i]['ba'] = getBillAddress($bill_id);
                $i++;
            }
        }
    }
    if ($cc_id) {
        $q = "SELECT * FROM users_cc WHERE cc_id = '{$cc_id}' LIMIT 0, 1";
        $result = mysql_query($q);
        $numrows = mysql_num_rows($result);
        if ($numrows) {
            while ($row = mysql_fetch_array($result)) {
                $bill_id = $row['bill_id'];
                $data = $row;
                $data['ba'] = getBillAddress($bill_id);
            }
        }
    }
    return $data;
}