コード例 #1
0
function add_order()
{
    require 'languages/text_variables.php';
    global $wpdb;
    $tz = get_option('timezone_string');
    if (empty($tz)) {
        $tz = 'UTC';
    }
    date_default_timezone_set($tz);
    $cancel_hook = false;
    if (isset($_POST['btnAddOrder'])) {
        if (isset($_POST['manual-input']) && $_POST['manual-input'] !== "") {
            $price = esc_attr(str_replace(',', '', $_POST['manual-input']));
        } else {
            $price = esc_attr($_POST['prod_price']);
        }
        if (isset($_POST['cancel-hook'])) {
            $cancel_hook = true;
        }
        $sql = "INSERT INTO " . $wpdb->prefix . "ign_pay_info\n\t\t\t\t\t(first_name,last_name,email,address,country,state,city,zip,product_id,product_level,prod_price,status,created_at)\n\t\t\t\tVALUES (\n\t\t\t\t\t\n\t\t\t\t\t'" . esc_attr($_POST['first_name']) . "',\n\t\t\t\t\t'" . esc_attr($_POST['last_name']) . "',\n\t\t\t\t\t'" . esc_attr($_POST['email']) . "',\n\t\t\t\t\t'" . esc_attr($_POST['address']) . "',\n\t\t\t\t\t'" . esc_attr($_POST['country']) . "',\n\t\t\t\t\t'" . esc_attr($_POST['state']) . "',\n\t\t\t\t\t'" . esc_attr($_POST['city']) . "',\n\t\t\t\t\t'" . esc_attr($_POST['zip']) . "',\n\t\t\t\t\t'" . absint($_POST['product_id']) . "',\n\t\t\t\t\t'" . absint($_POST['product_level']) . "',\n\t\t\t\t\t'" . esc_attr($price) . "',\n\t\t\t\t\t'" . esc_attr($_POST['status']) . "',\n\t\t\t\t\t'" . date('Y-m-d H:i:s') . "'\n\t\t\t\t)";
        $wpdb->query($sql);
        $pay_info_id = $wpdb->insert_id;
        if (!$cancel_hook) {
            do_action('id_payment_success', $pay_info_id);
        }
        $product_settings = getProductSettings($_POST['product_id']);
        $mailchip_settings = getMailchimpSettings();
        $aweber_settings = getAweberSettings();
        echo '<script type="text/javascript">window.location = "admin.php?page=order_details";</script>';
        //wp_redirect( "admin.php?page=order_details" );
        exit;
    }
    $products = ID_Project::get_all_projects();
    //print_r($products);
    echo '<div class="wrap">
			' . admin_menu_html();
    include_once 'templates/admin/_orderAdd.php';
    echo '</div>';
}
function IPNHandler($wp)
{
    //if (isset($_GET['ipn_handler'])) {
    global $wpdb;
    $tz = get_option('timezone_string');
    if (empty($tz)) {
        $tz = 'UTC';
    }
    date_default_timezone_set($tz);
    //unlink("log.txt");
    //================================================================================================================
    //		Adaptive Payment IPN for PayPal code
    //================================================================================================================
    //$filetest_handler = fopen("log.txt", 'a+');
    ini_set('post_max_size', '12M');
    //fwrite($filetest_handler, "ini is set so we are increasing post size \n");
    $data_array = array();
    $payment_complete = false;
    $approved = false;
    $status = null;
    $vars = array();
    foreach ($_POST as $key => $val) {
        //fwrite($filetest_handler, $key."=".$val."\n");
        $data1 = explode("=", $key);
        $data2 = explode("=", $val);
        $key = $data1[0];
        $val = $data2[0];
        $vars[$key] = $val;
        if ($data1[0] == "payment_status" && strtoupper($data2[0]) == "COMPLETED") {
            $payment_complete = true;
            //fwrite($filetest_handler, $payment_complete);
        } else {
            if ($data1[0] == "payment_status" && strtoupper($data2[0]) == "PENDING") {
                $payment_complete = true;
                $payment_pending = true;
                //fwrite($filetest_handler, $payment_complete);
            } else {
                if ($data1[0] == "status") {
                    //fwrite($filetest_handler, 'it does equal status');
                    if (strtoupper($data2[0]) == "COMPLETED") {
                        if (isset($vars['preapproval_key'])) {
                            $preauth_key = esc_attr($vars['preapproval_key']);
                            $sender_email = esc_attr($vars['sender_email']);
                            $status = 'C';
                            $txn_id = esc_attr($vars['pay_key']);
                            $sql = $wpdb->prepare('UPDATE ' . $wpdb->prefix . 'ign_pay_info SET status=%s, transaction_id=%s WHERE email = %s AND preapproval_key = %s', $status, $txn_id, $sender_email, $preauth_key);
                            //fwrite($filetest_handler, $sql);
                            $res = $wpdb->query($sql);
                        } else {
                            $payment_complete = true;
                            //fwrite($filetest_handler, $payment_complete);
                        }
                    } else {
                        if (strtoupper($data2[0]) == "ACTIVE") {
                            //fwrite($filetest_handler, 'it should equal active');
                            $status = 'active';
                            //fwrite($filetest_handler, $status);
                        }
                    }
                }
            }
        }
        if ($data1[0] == "approved" && strtoupper($data2[0]) == "TRUE") {
            //fwrite($filetest_handler, 'it should equal true');
            $approved = true;
            //fwrite($filetest_handler, $approved);
        }
        if ($approved == true && $status == 'active') {
            $preauth_complete = true;
            //fwrite($filetest_handler, 'preauthcomplete '. $preauth_complete);
        }
    }
    foreach ($vars as $key => $val) {
        //fwrite($filetest_handler, 'key->'.$key.'='.'val->'.$val);
    }
    if ($payment_complete) {
        //fwrite($filetest_handler, 'payment is complete'."\n");
        if (isset($vars['txn_id'])) {
            $txn_id = esc_attr($vars['txn_id']);
        } else {
            $txn_id = esc_attr($vars['pay_key']);
        }
        $check = $wpdb->prepare('SELECT id FROM ' . $wpdb->prefix . 'ign_pay_info WHERE transaction_id = %s', $txn_id);
        //fwrite($filetest_handler, $check);
        $checkres = $wpdb->get_row($check);
        if (empty($checkres)) {
            $query = "INSERT INTO " . $wpdb->prefix . "ign_pay_info (\r\n\t\t\t\t\t\t\tprod_price,\r\n\t\t\t\t\t\t\tfirst_name,\r\n\t\t\t\t\t\t\tlast_name,\r\n\t\t\t\t\t\t\temail,\r\n\t\t\t\t\t\t\taddress,\r\n\t\t\t\t\t\t\tcountry,\r\n\t\t\t\t\t\t\tstate,\r\n\t\t\t\t\t\t\tcity,\r\n\t\t\t\t\t\t\tzip,\r\n\t\t\t\t\t\t\tproduct_id,\r\n\t\t\t\t\t\t\ttransaction_id,\r\n\t\t\t\t\t\t\tproduct_level,\r\n\t\t\t\t\t\t\tcreated_at\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t\tvalues (\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['prod_price']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['fname']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['lname']) . "',\r\n\t\t\t\t\t\t\t'" . $_GET['email'] . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['address']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['country']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['state']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['city']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['zip']) . "',\r\n\t\t\t\t\t\t\t'" . absint($_GET['product_id']) . "',\r\n\t\t\t\t\t\t\t'" . $txn_id . "',\r\n\t\t\t\t\t\t\t'" . absint($_GET['level']) . "',\r\n\t\t\t\t\t\t\t'" . date('Y-m-d H:i:s') . "'\r\n\t\t\t\t\t\t)";
            //fwrite($filetest_handler, $query);
            //echo $query;exit;
            $res = $wpdb->query($query);
            $pay_info_id = $wpdb->insert_id;
            do_action('id_payment_success', $pay_info_id);
            //fwrite($filetest_handler, "\n".$pay_info_id);
            $_SESSION['ig_payinfo_id_latest'] = $pay_info_id;
            $_SESSION['ig_product_id_latest'] = esc_attr($_GET['product_id']);
            //$product = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix ."ign_products WHERE id = '".absint(esc_attr($_GET['product_id']))."'");
            // set order status
            if (isset($payment_pending) && $payment_pending == true) {
                setOrderStatus('P', $pay_info_id);
            } else {
                setOrderStatus('C', $pay_info_id);
            }
            //store transaction info in session
            $_SESSION['id_order'] = array('id' => $GLOBALS['transactionId'], 'product_id' => esc_attr($_GET['product_id']), 'shared-on-twitter' => false, 'shared-on-facebook' => false);
        } else {
            //fwrite($filetest_handler, $checkres);
        }
    } else {
        if (isset($preauth_complete)) {
            //fwrite($filetest_handler, 'preauth is complete \n');
            $num_payments = absint(esc_attr($_POST['current_number_of_payments']));
            $preauth_key = esc_attr($_POST['preapproval_key']);
            $current_attempts = absint(esc_attr($_POST['current_period_attempts']));
            $check = $wpdb->prepare('SELECT id FROM ' . $wpdb->prefix . 'ign_pay_info WHERE transaction_id = %s', $vars['preapproval_key']);
            $checkres = $wpdb->get_row($check);
            if (empty($checkres)) {
                $query = "INSERT INTO " . $wpdb->prefix . "ign_pay_info (\r\n\t\t\t\t\t\t\tprod_price,\r\n\t\t\t\t\t\t\tfirst_name,\r\n\t\t\t\t\t\t\tlast_name,\r\n\t\t\t\t\t\t\temail,\r\n\t\t\t\t\t\t\taddress,\r\n\t\t\t\t\t\t\tcountry,\r\n\t\t\t\t\t\t\tstate,\r\n\t\t\t\t\t\t\tcity,\r\n\t\t\t\t\t\t\tzip,\r\n\t\t\t\t\t\t\tproduct_id,\r\n\t\t\t\t\t\t\tpreapproval_key,\r\n\t\t\t\t\t\t\tproduct_level,\r\n\t\t\t\t\t\t\tstatus,\r\n\t\t\t\t\t\t\tcreated_at\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t\tvalues (\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['prod_price']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['fname']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['lname']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['email']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['address']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['country']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['state']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['city']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['zip']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['product_id']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($vars['preapproval_key']) . "',\r\n\t\t\t\t\t\t\t'" . esc_attr($_GET['level']) . "',\r\n\t\t\t\t\t\t\t'W',\r\n\t\t\t\t\t\t\t'" . date('Y-m-d H:i:s') . "'\r\n\t\t\t\t\t\t)";
                //fwrite($filetest, $query);
                //echo $query;exit;
                $res = $wpdb->query($query);
                $pay_info_id = $wpdb->insert_id;
                do_action('id_payment_success', $pay_info_id);
            }
        } else {
            // read the post from PayPal system and add 'cmd'
            $req = 'cmd=_notify-validate';
            foreach ($_POST as $key => $value) {
                $value = urlencode(stripslashes($value));
                $req .= "&{$key}={$value}";
            }
            // post back to PayPal system to validate
            $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
            $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
            $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
            $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
            if (!$fp) {
                //fwrite($filetest_handler, 'Paypal errored out');
            } else {
                fputs($fp, $header . $req);
                //fwrite($filetest_handler, 'Paypal was successful');
                while (!feof($fp)) {
                    $res = fgets($fp, 1024);
                    if (strcmp($res, "VERIFIED") == 0) {
                        // check the payment_status is Completed
                        // check that txn_id has not been previously processed
                        // check that receiver_email is your Primary PayPal email
                        // check that payment_amount/payment_currency are correct
                        // process payment
                        //fwrite($filetest_handler, $res."\n");
                        global $wpdb;
                        // Check if a new payment is made using the session variable set before making that payment
                        if (1) {
                            // Deserialize the payment variables and get them to work
                            //$payment_variables = urldecode($_GET['payment_vars']);
                            //$payment_variables = str_replace("\\","",$payment_variables);
                            //fwrite($filetest_handler, "Payment variables: ".$payment_variables."\n");
                            //$payment_variables = unserialize($payment_variables);
                            //fwrite($filetest_handler, "Payment variables array: ".$payment_variables."\n");
                            $query = "INSERT INTO " . $wpdb->prefix . "ign_pay_info (\r\n\t\t\t\t\t\t\t\t\t\tprod_price,\r\n\t\t\t\t\t\t\t\t\t\tfirst_name,\r\n\t\t\t\t\t\t\t\t\t\tlast_name,\r\n\t\t\t\t\t\t\t\t\t\temail,\r\n\t\t\t\t\t\t\t\t\t\taddress,\r\n\t\t\t\t\t\t\t\t\t\tcountry,\r\n\t\t\t\t\t\t\t\t\t\tstate,\r\n\t\t\t\t\t\t\t\t\t\tcity,\r\n\t\t\t\t\t\t\t\t\t\tzip,\r\n\t\t\t\t\t\t\t\t\t\tproduct_id,\r\n\t\t\t\t\t\t\t\t\t\ttransaction_id,\r\n\t\t\t\t\t\t\t\t\t\tproduct_level,\r\n\t\t\t\t\t\t\t\t\t\tcreated_at\r\n\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\tvalues (\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['prod_price']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['fname']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['lname']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['email']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['address']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['country']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['state']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['city']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['zip']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['product_id']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['tx']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . esc_attr($_GET['level']) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . date('Y-m-d H:i:s') . "'\r\n\t\t\t\t\t\t\t\t\t)";
                            //echo $query;exit;
                            $res = $wpdb->query($query);
                            $pay_info_id = $wpdb->insert_id;
                            $_SESSION['ig_payinfo_id_latest'] = $pay_info_id;
                            $_SESSION['ig_product_id_latest'] = esc_attr($_GET['product_id']);
                            $product = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "ign_products WHERE id = '" . $_GET['product_id'] . "'");
                            // set order status
                            setOrderStatus('C', $pay_info_id);
                            // subscribe user to mailchimp
                            $order = getOrderById($pay_info_id);
                            $mailchip_settings = getMailchimpSettings();
                            $aweber_settings = getAweberSettings();
                            $product_settings = getProductSettings($product->id);
                            if ($product_settings != -1 && $product_settings->active_mailtype == "mailchimp") {
                                subscribeToMailchimp($order->email, array('first_name' => $order->first_name, 'last_name' => $order->last_name), $product->id);
                            } else {
                                if ($mailchip_settings->is_active) {
                                    subscribeToMailchimp($order->email, array('first_name' => $order->first_name, 'last_name' => $order->last_name), $product->id);
                                }
                            }
                            if ($product_settings != -1 && $product_settings->active_mailtype == "aweber") {
                                subscribeToAweber($order->email, array('first_name' => $order->first_name, 'last_name' => $order->last_name), $product->id);
                            } else {
                                if ($aweber_settings->is_active) {
                                    subscribeToAweber($order->email, array('first_name' => $order->first_name, 'last_name' => $order->last_name), $product->id);
                                }
                            }
                            //store transaction info in session
                            $_SESSION['id_order'] = array('id' => $GLOBALS['transactionId'], 'product_id' => esc_attr($_GET['product_id']), 'shared-on-twitter' => false, 'shared-on-facebook' => false);
                        }
                    } else {
                        if (strcmp($res, "INVALID") == 0) {
                            // log for manual investigation
                            //fwrite($filetest_handler, $res);
                        }
                    }
                }
                fclose($fp);
            }
        }
    }
    //fclose($filetest_handler);
    return;
    //======================================== code ends here ========================================================
    //}
}
コード例 #3
0
ファイル: functions.php プロジェクト: NYC2015/team-12
/**
This function is now  deprecated -> now pulled from the IgnitionDeck Deck class the_deck method
*/
function the_levels($id)
{
    global $wpdb;
    $project_id = get_post_meta($id, 'ign_project_id', true);
    $level_count = get_post_meta($id, 'ign_product_level_count', true);
    // GETTING product default settings
    $default_prod_settings = getProductDefaultSettings();
    // Getting product settings and if they are not present, set the default settings as product settings
    $prod_settings = getProductSettings($project_id);
    if (empty($prod_settings)) {
        $prod_settings = $default_prod_settings;
    }
    $currency_code = $prod_settings->currency_code;
    //GETTING the currency symbols
    $cCode = setCurrencyCode($currency_code);
    $level_data = array();
    for ($i = 1; $i <= $level_count; $i++) {
        $level_sales = $wpdb->prepare('SELECT COUNT(*) as count FROM ' . $wpdb->prefix . 'ign_pay_info WHERE product_id=%d AND product_level = %d', $project_id, $i);
        $return_sales = $wpdb->get_row($level_sales);
        $level_sales = $return_sales->count;
        if ($i == 1) {
            $level_title = html_entity_decode(get_post_meta($id, 'ign_product_title', true));
            $level_desc = html_entity_decode(get_post_meta($id, 'ign_product_details', true));
            $level_price = get_post_meta($id, 'ign_product_price', true);
            if ($level_price > 0) {
                $level_price = number_format($level_price, 0, '.', ',');
            }
            $level_limit = get_post_meta($id, 'ign_product_limit', true);
            $level_order = get_post_meta($id, 'ign_projectmeta_level_order', true);
            $level_data[] = array('id' => $i, 'title' => $level_title, 'description' => $level_desc, 'price' => $level_price, 'sold' => $level_sales, 'limit' => $level_limit, 'currency_code' => $cCode, 'order' => $level_order);
        } else {
            $level_title = html_entity_decode(get_post_meta($id, 'ign_product_level_' . $i . '_title', true));
            $level_desc = html_entity_decode(get_post_meta($id, 'ign_product_level_' . $i . '_desc', true));
            $level_price = get_post_meta($id, 'ign_product_level_' . $i . '_price', true);
            if ($level_price > 0) {
                $level_price = number_format($level_price, 0, '.', ',');
            }
            $level_limit = get_post_meta($id, 'ign_product_level_' . $i . '_limit', true);
            $level_order = get_post_meta($id, 'ign_product_level_' . $i . '_order', true);
            $level_data[] = array('id' => $i, 'title' => $level_title, 'description' => $level_desc, 'price' => $level_price, 'limit' => $level_limit, 'sold' => $level_sales, 'currency_code' => $cCode, 'order' => $level_order);
        }
    }
    return $level_data;
}
function idpp_process_handler()
{
    global $wpdb;
    $product_id = $_POST['Project'];
    $sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'ign_pay_info WHERE product_id = %s AND status=%s', $product_id, 'W');
    //echo $sql;
    $res = $wpdb->get_results($sql);
    //print_r($res);
    $adaptive_pay_settings = getAdaptivePayPalSettings();
    // GETTING product default settings
    $default_prod_settings = getProductDefaultSettings();
    // Getting product settings and if they are not present, set the default settings as product settings
    $prod_settings = getProductSettings($product_id);
    if (empty($prod_settings)) {
        $prod_settings = $default_prod_settings;
    }
    require_once 'paypal/lib/AdaptivePayments.php';
    # Endpoint: this is the server URL which you have to connect for submitting your API request.
    //Chanege to https://svcs.paypal.com/  to go live */
    if ($adaptive_pay_settings->paypal_mode == "sandbox") {
        define('API_BASE_ENDPOINT', 'https://svcs.sandbox.paypal.com/');
        define('PAYPAL_REDIRECT_URL', 'https://www.sandbox.paypal.com/webscr&cmd=');
        $app_id = "APP-80W284485P519543T";
    } else {
        define('API_BASE_ENDPOINT', 'https://svcs.paypal.com/');
        define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=');
        $app_id = $adaptive_pay_setings->app_id;
    }
    /***** 3token API credentials *****************/
    define('API_AUTHENTICATION_MODE', '3token');
    define('API_USERNAME', $adaptive_pay_settings->api_username);
    define('API_PASSWORD', $adaptive_pay_settings->api_password);
    define('API_SIGNATURE', $adaptive_pay_settings->api_signature);
    require_once 'paypal/lib/Config/paypal_sdk_clientproperties.php';
    $no_success = array();
    $no_failures = array();
    foreach ($res as $payment) {
        if ($payment->preapproval_key !== '') {
            // Setting the necessary variables for the payment
            $returnURL = site_url('/');
            $cancelURL = site_url('/');
            $notifyURL = site_url('/') . '?ipn_handler=1';
            $currencyCode = $prod_settings->currency_code;
            $email = $payment->email;
            $preapprovalKey = $payment->preapproval_key;
            $requested = '';
            $payRequest = new PayRequest();
            $payRequest->actionType = "PAY";
            $payRequest->cancelUrl = $cancelURL;
            $payRequest->returnUrl = $returnURL;
            $payRequest->ipnNotificationUrl = $notifyURL;
            $payRequest->clientDetails = new ClientDetailsType();
            $payRequest->clientDetails->applicationId = $app_id;
            //"APP-1JE4291016473214C";
            //$payRequest->clientDetails->deviceId = DEVICE_ID;
            $payRequest->clientDetails->ipAddress = $_SERVER['REMOTE_ADDR'];
            $payRequest->currencyCode = $currencyCode;
            $payRequest->senderEmail = html_entity_decode($email);
            $payRequest->requestEnvelope = new RequestEnvelope();
            $payRequest->requestEnvelope->errorLanguage = "en_US";
            //$payRequest->preapprovalKey = "PA-16707604HP296522Y";
            //print_r($payRequest);
            if ($preapprovalKey !== "") {
                $payRequest->preapprovalKey = $preapprovalKey;
                //echo $preapprovalKey."keyhere";
            }
            $receiver1 = new receiver();
            $receiver1->email = $adaptive_pay_settings->paypal_email;
            $receiver1->amount = $payment->prod_price;
            $payRequest->receiverList = new ReceiverList();
            $payRequest->receiverList = array($receiver1);
            /* 	Make the call to PayPal to get the Pay token
             *	If the API call succeded, then redirect the buyer to PayPal
             *	to begin to authorize payment.  If an error occured, show the
             *	resulting errors
             */
            $ap = new AdaptivePayments();
            $response = $ap->Pay($payRequest);
            //echo "end of line<br/>";
            if (strtoupper($ap->isSuccess) == 'SUCCESS') {
                $no_success[] = 'success';
            } else {
                if (strtoupper($ap->isSuccess) == 'FAILURE') {
                    $no_failures[] = 'failure';
                    //echo "inside failure<br/>";
                    $fault = $ap->getLastError();
                    $errors_content = $fault->error->message;
                    //echo $errors_content;
                    // For error handling
                    /*if (is_object($fault->error))
                    				{ 
                    
                    					//$errors_content = '<table width =\"450px\" align=\"center\">';
                    					$errors_content;
                    					$errors_content = '';
                    					foreach($fault->error as $err) {
                    
                    						//$errors_content .= '<tr>';
                    						//$errors_content .= '<td>';
                    						//$errors_content .= 'Error ID: ' . $err->errorId . '<br />';
                    						//$errors_content .= 'Domain: ' . $err->domain . '<br />';
                    						//$errors_content .= 'Severity: ' . $err->severity . '<br />';
                    						//$errors_content .= 'Category: ' . $err->category . '<br />';
                    						$errors_content .= $err . "<br />";
                    
                    						if(empty($err->parameter)) {
                    							//$errors_content .= '<br />';
                    						}
                    						else {
                    							//$errors_content .= 'Parameter: ' . $err->parameter . '<br /><br />';
                    						}
                    							
                    						//$errors_content .= '</td>';
                    						//$errors_content .= '</tr>';
                    					}
                    					//$errors_content .= '</table>';
                    				}
                    				else
                    				{
                    
                    					$errors_content = "";
                    					//$errors_content .= 'Error ID: ' . $fault->error->errorId . '<br />';
                    					//$errors_content .= 'Domain: ' . $fault->error->domain . '<br />';
                    					//$errors_content .= 'Severity: ' . $fault->error->severity . '<br />';
                    					//$errors_content .= 'Category: ' . $fault->error->category . '<br />';
                    					$errors_content .= $fault->error->message . '<br />';
                    					if(empty($fault->error->parameter)) {
                    						//$errors_content .= '</br>';
                    					}
                    					else {
                    						//$errors_content .= 'Parameter: ' . $fault->error->parameter . '<br /><br />';
                    					}
                    				}*/
                }
            }
        }
    }
    $response_array['counts'] = array('success' => count($no_success), 'failures' => count($no_failures));
    print_r(json_encode($response_array));
    exit;
}