// Google Checkout Payment Mails
if (isset($_SESSION['google_order_id']) && $_SESSION['google_order_id'] != '') {
    $orderid = $_SESSION['google_order_id'];
    if (isset($_SESSION["sess_guest_username"]) && $_SESSION["sess_guest_username"] != '') {
        $usertype = 'guest';
    } else {
        $usertype = 'user';
    }
    $sql_order = "SELECT * FROM " . $tableprefix . "orders where order_id='" . $orderid . "' AND vpayment_status='C' ";
    $rs_order = mysql_query($sql_order) or die(mysql_error());
    if (mysql_num_rows($rs_order) > 0) {
        $gift_coupon_flag = $_SESSION['gift_coupon_flag'];
        $product_download_flag = $_SESSION['product_download_flag'];
        // Send Giftcertificate Mails
        if ($gift_coupon_flag == 1) {
            sendgiftCertificateMail_Buyer($orderid, $_SESSION["sess_userid"], $usertype);
            sendgiftCertificateMail_Seller($orderid, $_SESSION["sess_userid"]);
            sendgiftCertificateMail_Admin($orderid, $_SESSION["sess_userid"]);
        }
        //Send Digital Certificate Mails
        if ($product_download_flag == 1) {
            sendDigitalCertificateMail_Buyer($orderid, $_SESSION["sess_userid"], $usertype);
            sendDigitalCertificateMail_Seller($orderid, $_SESSION["sess_userid"]);
            sendDigitalCertificateMail_Admin($orderid, $_SESSION["sess_userid"]);
        }
        if ($product_download_flag != 1 && $gift_coupon_flag != 1) {
            sendBuyerEmail($orderid, $_SESSION["sess_userid"], $usertype);
            sendSellerEmail($orderid, $_SESSION["sess_userid"]);
            sendAdminEmail($orderid, $_SESSION["sess_userid"]);
        }
        adjustStock($_SESSION["sess_userid"], "-");
            $txtEmailDownload = $user_email_row['email'];
            $subjectDownload = "Digital Product Order placed at " . SITE_NAME;
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
            $headers .= "From: " . SITE_EMAIL . "<" . SITE_EMAIL . ">" . "\r\n";
            /*-------Email Template reading function call------------*/
            $mailcontent_digital_product = readEmailTemplate('digital_product');
            $product_download_details .= "\n\n*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*\r\n";
            $product_download_details .= "<font color='#FF0000'>Note: If you do not have pop-ups enabled on your browser, the product download many not work properly.So please enable pop-ups before downloading !!</font>";
            $mailcontent_digital_product = str_replace('[product_details]', $product_download_details, $mailcontent_digital_product);
            $mailcontent_digital_product = nl2br($mailcontent_digital_product);
            $mail_send_details = "<html><head><link href='" . SITE_URL . "/style/template1-admin.css' rel='stylesheet' type='text/css'></head><body><center><div align='left' id='layout'><div align='left' class='header'><div align='left' class='logo'><img src=" . $logofolder . "/" . $logoimage . " width='125' height='39'/></div></div><div>" . $mailcontent_digital_product . "</div></div><div align='left' class='clear_float'><img src=" . $imagefolder . "/clear.gif width=1 height=1/></div></div></div></center></body></html>";
            //$mailsent = mail($txtEmailDownload,$subjectDownload,$mail_send_details,$headers);
        }
        /*-----------------Digital Product Mail Sending Ends----------------*/
        // Send Giftcertificate Mails
        if ($gift_coupon_flag == 1) {
            sendgiftCertificateMail_Buyer($orderid, $CustomArray[0]);
        } else {
            sendBuyerEmail($orderid, $CustomArray[0]);
            sendSellerEmail($orderid, $CustomArray[0]);
            sendAdminEmail($orderid, $CustomArray[0]);
        }
        //Send Mail To Buyer
    }
    // end if paypal check
}
//end ipn check if
emptyCart($CustomArray[0]);
$_SESSION["sess_addresses_collected"] = false;
$_SESSION["sess_stock_adjusted"] = false;
 // end for artist
 // Update Order Table
 $sql_update = "UPDATE " . $tableprefix . "orders SET vpayment_status='C' where order_id=" . $orderid . " ";
 $sql_qr = mysql_query($sql_update) or die(mysql_error());
 // Update Artists Payemt Table
 $sql_update_payment = "UPDATE " . $tableprefix . "artist_payments SET payment_status='C' where order_id=" . $orderid . " ";
 $re_up = mysql_query($sql_update_payment) or die(mysql_error());
 // Settle seller , Admin Amounts
 // End
 $sql_select_pay = "SELECT payment_completed_status  FROM  " . $tableprefix . "orders where order_id=" . $orderid . " ";
 $rs_select_pay = mysql_query($sql_select_pay) or die(mysql_error());
 $rowPay = mysql_fetch_array($rs_select_pay);
 $paymentComplete_Status = $rowPay['payment_completed_status'];
 if ($paymentComplete_Status == 'N') {
     if ($gift_flag == 1) {
         sendgiftCertificateMail_Buyer($orderid, $userid);
         sendgiftCertificateMail_Seller($orderid, $userid);
         sendgiftCertificateMail_Admin($orderid, $userid);
     } else {
         if ($digital_flag == 1) {
             sendDigitalCertificateMail_Buyer($orderid, $userid, $usertype);
             sendDigitalCertificateMail_Seller($orderid, $userid);
             sendDigitalCertificateMail_Admin($orderid, $userid);
         } else {
             sendBuyerEmail($orderid, $userid, $usertype);
             sendSellerEmail($orderid, $userid);
             sendAdminEmail($orderid, $userid);
         }
     }
     $sql_update_order_payment = "UPDATE " . $tableprefix . "orders SET payment_completed_status='Y' where order_id=" . $orderid . " ";
     $res_update = mysql_query($sql_update_order_payment) or die(mysql_error());