$row = mysql_fetch_array($result);
         complete_order($row['user_id'], $invoice_id);
         debit_transaction($invoice_id, $mc_gross, $mc_currency, $txn_id, $reason_code, 'PayPal');
         break;
     case "Denied":
         // denied by merchant
         break;
     case "Failed":
         // only happens when payment is from customers' bank account
         //insert_transaction ($employer_id, $payment_status, $pending_reason, $reason_code, $payment_date, $txn_id, $parent_txn_id, $txn_type, $payment_type, $mc_gross, $mc_currency, $item_name, $item_number, $invoice_id);
         break;
     case "Pending":
         $sql = "select user_id FROM orders where order_id='" . $invoice_id . "'";
         $result = mysql_query($sql) or pp_mail_error(mysql_error() . $sql);
         $row = mysql_fetch_array($result);
         pend_order($row['user_id'], $invoice_id);
         // pending_reason : 'address', 'echeck', 'intl', 'multi_currency', 'unilateral', 'upgrade', 'verify', 'other'
         break;
     case "Refunded":
         // reason_code : 'buyer_complaint', 'chargeback', 'guarantee', 'refund', 'other'
         cancel_order($invoice_id);
         credit_transaction($invoice_id, $mc_gross, $mc_currency, $txn_id, $reason_code, 'PayPal');
         break;
     case "Reversed":
         // reason_code : 'buyer_complaint', 'chargeback', 'guarantee', 'refund', 'other'
         cancel_order($invoice_id);
         credit_transaction($invoice_id, $mc_gross, $mc_currency, $txn_id, $reason_code, 'PayPal');
         break;
     default:
         break;
 }
    function process_payment_return()
    {
        global $label;
        if ($_POST['Merchant_Id'] != '') {
            $sql = "SELECT * FROM orders where order_id='" . $_POST['Order_Id'] . "'";
            $result = mysql_query($sql) or die(mysql_error() . $sql);
            $order_row = mysql_fetch_array($result);
            //$WorkingKey = "" ; //put in the 32 bit working key in the quotes provided here
            $Checksum = cc_verifychecksum($_POST['Merchant_Id'], $_POST['Order_Id'], $_POST['Amount'], $_POST['AuthDesc'], $_POST['Checksum'], CCAVENUE_WORKING_KEY);
            if ($Checksum == "true" && $_POST['AuthDesc'] == "Y") {
                debit_transaction($_POST['Order_Id'], $_POST['Amount'], CCAVENUE_CURRENCY, "ccAve" . $_POST['Order_Id'], $reason_code, 'CCAvenue');
                complete_order($order_row['user_id'], $_POST['Order_Id']);
                ?>

					<center>

				<?php 
                echo $label['payment_ccave_note_y'];
                ?>
 ?>

				</center>
					
					<h3><?php 
                echo $label['payment_ccave_go_back'];
                ?>
</h3>

				<?php 
                echo "<br>Thank you for shopping with us. Your credit card has been charged and your transaction is successful. You can continue and upload your pixels.";
                //Here you need to put in the routines for a successful
                //transaction such as sending an email to customer,
                //setting database status, informing logistics etc etc
            } else {
                if ($Checksum == "true" && $_POST['AuthDesc'] == "B") {
                    pend_order($order_row['user_id'], $_POST['Order_Id']);
                    ?>

				<center>

				<?php 
                    echo $label['payment_ccave_note_b'];
                    ?>
 ?>

				</center>
					
					

					?>
				<br>

				<?php 
                    //Here you need to put in the routines/e-mail for a  "Batch Processing" order
                    //This is only if payment for this transaction has been made by an American Express Card
                    //since American Express authorisation status is available only after 5-6 hours by mail from ccavenue and at the "View Pending Orders"
                } else {
                    if ($Checksum == "true" && $_POST['AuthDesc'] == "N") {
                        echo "<br>Thank you for shopping with us. However, the transaction has been declined.";
                        //Here you need to put in the routines for a failed
                        //transaction such as sending an email to customer
                        //setting database status etc etc
                        ?>

				<h3><?php 
                        echo $label['payment_ccave_go_back'];
                        ?>
</h3>

				<?php 
                    } else {
                        echo "<br>Security Error. Illegal access detected";
                        //Here you need to simply ignore this and dont need
                        //to perform any operation in this condition
                    }
                }
            }
        }
    }
    function process_payment_return()
    {
        global $label;
        if ($_REQUEST['key'] != '') {
            $order_number = $_REQUEST['order_number'];
            //$order_number = _2CO_SID."-".$order_number;
            if (_2CO_DEMO == 'Y') {
                $order_number = 1;
            }
            $card_holder_name = $_REQUEST['card_holder_name'];
            $street_address = $_REQUEST['street_address'];
            $city = $_REQUEST['city'];
            $state = $_REQUEST['state'];
            $zip = $_REQUEST['zip'];
            $country = $_REQUEST['country'];
            $email = $_REQUEST['email'];
            $phone = $_REQUEST['phone'];
            $credit_card_processed = $_REQUEST['credit_card_processed'];
            // Y = successfull. K = pending
            $total = $_REQUEST['total'];
            $product_id = $_REQUEST['product_id'];
            // c2o product id
            $quantity = $_REQUEST['quantity'];
            // quantity
            $merchant_product_id = $_REQUEST['merchant_product_id'];
            //
            $cart_order_id = $_REQUEST['cart_order_id'];
            $product_description = $_REQUEST['product_description'];
            $x_MD5_Hash = strtolower($_REQUEST['key']);
            // md5 (secret word + vendor number + order number + total)
            //.Demo mode:The order number used to create the Hash is forced to equal 1. This designates that the order is a demo order.
            //$x_MD5_Hash = $_REQUEST['x_MD5_Hash']; // md5 (secret word + vendor number + order number + total)
            //.Demo mode:The order number used to create the Hash is forced to equal 1. This designates that the order is a demo order.
            //include ("header.php");
            //print_r ($_REQUEST);
            foreach ($_REQUEST as $key => $val) {
                $req .= "&" . $key . "=" . $val;
            }
            _2co_log_entry($req);
            // process order
            $_2CO = new _2CO();
            // load in the constants..
            // get customer's order
            $sql = "SELECT * FROM orders where order_id='" . $cart_order_id . "'";
            $result = mysql_query($sql) or die(mysql_error() . $sql);
            $order_row = mysql_fetch_array($result);
            // md5 (secret word + vendor number + order number + total)
            $md5_str = _2CO_SECRET_WORD . _2CO_SID . $order_number . format_number($order_row['price']);
            $hash = md5($md5_str);
            if (strcmp($hash, $x_MD5_Hash) == 0) {
                if ($credit_card_processed == 'Y') {
                    # Credit card processed OK
                    complete_order($order_row['user_id'], $cart_order_id);
                    debit_transaction($cart_order_id, $total, 'USD', $order_number, $reason, '_2CO');
                    ?>
					<center>

					<img src="<?php 
                    echo SITE_LOGO_URL;
                    ?>
">
					<h3>Thank you. Your order was sucessfully completed. You may <a href="<?php 
                    echo BASE_HTTP_PATH;
                    ?>
users/publish.php">manage your pixels</a> now.</h3>

					</center>
					<?php 
                } elseif ($credit_card_processed == 'K') {
                    # credit card pending
                    pend_order($order_row['user_id'], $cart_order_id);
                    ?>
					<center>
					<img src="<?php 
                    echo SITE_LOGO_URL;
                    ?>
">
					<h3>Thank you. Your order is pending while the funds are cleared by 2Checkout. Go to the <a href="<?php 
                    echo BASE_HTTP_PATH;
                    ?>
users/index.php">Main Menu.</a></h3>
					</center>
					<?php 
                }
            } else {
                echo "Invalid.";
                echo "Invalid. Was this a demo transaction?" . "Has does not match...: [{$hash}] != [{$x_MD5_Hash}] (original string: " . $md5_str . ") ";
                _2co_mail_error("Has does not match...: [{$hash}] != [{$x_MD5_Hash}] (original string: " . $md5_str . ") ");
            }
        }
    }