/**
 * Proccess Product buyout
 */
function productBuyout()
{
    require 'languages/text_variables.php';
    if (isset($_POST['submitPaymentPopup'])) {
        $first_name = '';
        $last_name = '';
        $email = '';
        $address = '';
        $country = '';
        $state = '';
        $city = '';
        $zip = '';
        $product_id = 0;
        $level = 0;
        $price = '0.00';
        // Store all the required variables in SESSION to get them later
        session_start();
        if (isset($_POST['first_name'])) {
            $first_name = esc_attr($_POST['first_name']);
        }
        if (isset($_POST['last_name'])) {
            $last_name = esc_attr($_POST['last_name']);
        }
        if (isset($_POST['email'])) {
            $email = esc_attr($_POST['email']);
        }
        if (isset($_POST['address'])) {
            $address = esc_attr($_POST['address']);
        }
        if (isset($_POST['country'])) {
            $country = esc_attr($_POST['country']);
        }
        if (isset($_POST['state'])) {
            $state = esc_attr($_POST['state']);
        }
        if (isset($_POST['city'])) {
            $city = esc_attr($_POST['city']);
        }
        if (isset($_POST['zip'])) {
            $zip = esc_attr($_POST['zip']);
        }
        if (isset($_POST['project_id'])) {
            $product_id = absint($_POST['project_id']);
        }
        if (isset($_POST['level'])) {
            $level = absint($_POST['level']);
        }
        if (isset($_POST['price'])) {
            $price = esc_attr(str_replace(',', '', $_POST['price']));
        }
        $payment_variables = array("first_name" => $first_name, "last_name" => $last_name, "email" => $email, "address" => $address, "country" => $country, "state" => $state, "city" => $city, "zip" => $zip, "product_id" => $product_id, "level_select" => $level, "price" => $price);
        $_SESSION['ig_payment_variables'] = serialize($payment_variables);
        $project_id = $_POST['project_id'];
        $project = new ID_Project($project_id);
        $post_id = $project->get_project_postid();
        $paymentSettings = getPaymentSettings();
        // use this for default
        $paypal_email = $paymentSettings->paypal_email;
        $productDetails = $project->the_project();
        //GETTING product default settings
        $default_prod_settings = getProductDefaultSettings();
        $prod_settings = $default_prod_settings;
        // see if we have custom settings
        $custom_settings = $project->get_project_settings();
        if (!empty($custom_settings)) {
            $prod_settings = $custom_settings;
            if (!empty($custom_settings->paypal_email)) {
                $paypal_email = $custom_settings->paypal_email;
            }
        }
        if ($paymentSettings->paypal_mode == "sandbox") {
            $url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
        } else {
            $url = "https://www.paypal.com/cgi-bin/webscr";
        }
        $notifyURL = site_url() . "/?ipn_handler=1&payment_vars=" . urlencode($_SESSION['ig_payment_variables']);
        include_once 'templates/_paypalForm.php';
    }
}
/**
 * isPaypalTransactionValid
 * Checks if paypal payment is valid
 * @param string $GLOBALS['transactionId']
 * @return bool
 */
function isPaypalTransactionValid($transactionid)
{
    return true;
    $paypalOptions = getPaymentSettings();
    $h = curl_init();
    curl_setopt($h, CURLOPT_URL, "https://" . $paypalOptions->url . "/cgi-bin/webscr");
    curl_setopt($h, CURLOPT_POST, true);
    curl_setopt($h, CURLOPT_POSTFIELDS, array('cmd' => '_notify-synch', 'tx' => $transactionid, 'at' => $paypalOptions->identity_token, 'submit' => 'PDT'));
    curl_setopt($h, CURLOPT_HEADER, false);
    curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($h);
    $lines = explode("\n", $result);
    //    var_dump($lines);
    $keyarray = array();
    if (strcmp($lines[0], "SUCCESS") == 0) {
        for ($i = 1; $i < count($lines); $i++) {
            list($key, $val) = explode("=", $lines[$i]);
            $keyarray[urldecode($key)] = urldecode($val);
        }
        // process payment
        $firstname = $keyarray['first_name'];
        $lastname = $keyarray['last_name'];
        $itemname = $keyarray['num_cart_items'];
        $amount = $keyarray['mc_gross'];
        return true;
    } else {
        if (strcmp($lines[0], "FAIL") == 0) {
            // log for manual investigation
            return false;
        }
    }
}