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"], "-");
        emptyCart($_SESSION["sess_userid"]);
 // 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());
 }