$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"]);
     $_SESSION["sess_addresses_collected"] = false;
     $_SESSION["sess_stock_adjusted"] = false;
     $_SESSION["sess_addresses_collected"] = false;
     $_SESSION["sess_stock_adjusted"] = false;
     $_SESSION['couponCode_det'] = '';
     if (isset($_SESSION['guest_login']) && $_SESSION['guest_login'] != '') {
         session_unregister($_SESSION['guest_login']);
            // 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());
            }
            adjustStock($userid, "-");
            emptyCart($userid);
        }
    }
} else {
    //exit('DoDirectPayment failed: <br>' . print_r($httpParsedResponseAr, true));