private void ProcessTransaction()
        {
            long userId = Util.UserId;
            long prodId = 0L;
            string country = "NL";
            string currency = "EUR";
            string culture = "nl-NL";
            decimal amount = 0m;
            if (Session["pid"] != null)
                prodId = Convert.ToInt64(Session["pid"]);
            if (Session["amt"] != null)
                amount = Convert.ToDecimal(Session["amt"]);
            if (Session["culture"] != null)
                culture = Session["culture"] as string;
            country = culture.Substring(3);
            currency = Util.GetCurrencyIsoNameByCountryIso2(country);

            Logger.Instance.Write(LogLevel.Info, "Process successful transaction: {0}", Request.RawUrl);

            string res = Request.Params["res"] ?? string.Empty;
            string status = Request.Params["Status"] ?? string.Empty;
            string statusCode = Request.Params["StatusCode"] ?? string.Empty;
            string merchant = Request.Params["Merchant"] ?? string.Empty;
            string orderId = Request.Params["OrderID"] ?? string.Empty;
            string paymentId = Request.Params["PaymentID"] ?? string.Empty;
            string reference = Request.Params["Reference"] ?? string.Empty;
            string transid = Request.Params["TransactionID"] ?? string.Empty;
            string paymentMethod = Request.Params["PaymentMethod"] ?? string.Empty;
            if (!string.IsNullOrEmpty(statusCode))
                statusCode = Uri.UnescapeDataString(statusCode);
            using (Database db = new MySqlDatabase())
            {
                StringBuilder sb = new StringBuilder();
                ProductInfo pi = db.GetProductById(prodId);
                switch (db.UpdateTransaction(orderId, res, status, statusCode, merchant, paymentId, reference,
                                 transid, paymentMethod, amount, pi, currency, country))
                {
                    case TransactionResult.Success:
                        {
                            long Transaction_id = 0;
                            long.TryParse(orderId, out Transaction_id);

                            db.UpdateUserCredits(userId, prodId, pi.Credits);
                            db.AddCreditHistory(userId, prodId, pi.Credits, Transaction_id);

                            sb.Append("<div>");
                            sb.AppendFormat("<p><strong>{0}</strong></p>", Resources.Resource.TransactionSuccessful);
                            sb.AppendFormat(Resources.Resource.HasCreditsNow, Util.GetUserCredits(userId));
                            sb.Append("</div>");
                        }
                        break;

                    case TransactionResult.NotFound:
                        {
                            sb.Append("<div>");
                            sb.AppendFormat("<p><strong>{0}</strong></p>", Resources.Resource.TransactionFailed);
                            sb.AppendFormat(Resources.Resource.HasCreditsNow, Util.GetUserCredits(userId));
                            sb.Append("</div>");
                        }
                        break;

                    case TransactionResult.AlreadyCompleted:
                        {
                            sb.Append("<div>");
                            sb.AppendFormat("<p><strong>{0}</strong></p>", Resources.Resource.TransactionAlreadyCompleted);
                            sb.AppendFormat(Resources.Resource.HasCreditsNow, Util.GetUserCredits(userId));
                            sb.Append("</div>");
                        }
                        break;
                }

                ResultLiteral.Text = sb.ToString();
            }

            sendMail(orderId, Resources.Resource.CreditPurchaseSuccessSubject, Resources.Resource.CreditPurchaseSuccessBody);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Logger logger = Logger.Instance;

            IncludePage(BuyProductInc, Resources.Resource.incBuyProduct);
            IncludePage(RhosMovementInc, Resources.Resource.incRhosMovement2);

            string activeModule = string.Empty;

            using (Database db = new MySqlDatabase())
            {
                UserInfo ui = db.GetUser(Util.UserId);
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                DataSet ds = db.GetRegister(Util.UserId);
                int protectedTracks = ds.Tables[0].Rows.Count;

                LoggedOnTitle.Text = Resources.Resource.LoggedOnTitle;
                LoggedOnUserName.Text = string.Format("<span><b>{0}</b></span>", ci.FirstName);// ci.GetFullName());
                CreditsLiteral.Text = Util.GetUserCredits(Util.UserId).ToString();
                ProtectedLiteral.Text = protectedTracks.ToString();
                string userDocPath = db.GetUserDocumentPath(ui.UserId, Session["access"] as string);
                decimal percentComplete = DetermineCompletion(userDocPath, ui, ci);
                CompletedLiteral.Text = string.Empty;
                if (percentComplete < 100)
                    CompletedLiteral.Text = string.Format(Resources.Resource.PercentComplete, percentComplete / 100m);
                divAccPerCompleted.Visible = ClickToLinkLiteral.Visible = (CompletedLiteral.Text != string.Empty);
            }

            if (!IsPostBack)
            {
                long prodid = -1;
                long transid = -1;
                ParamsDictionary parms = new ParamsDictionary();
                string desc = "???";
                if (Request.Params["pid"] != null /* && Request.Params["tid"] == null */)
                {
                    prodid = Convert.ToInt64(Request.Params["pid"]);
                    if (prodid > -1)
                    {
                        using (Database db = new MySqlDatabase())
                        {
                            ProductInfo pi = db.GetProductById(prodid);
                            ProductPriceInfoList ppil = db.GetProductPrices(prodid);
                            decimal price = 0m;
                            foreach (ProductPriceInfo ppi in ppil)
                            {
                                if (ppi.IsoCurrency == "EUR")
                                {
                                    price = ppi.Price;
                                    break;
                                }
                            }

                            desc = pi.Name;
                            parms.Add("{%product%}", desc);
                            parms.Add("{%credits%}", pi.Credits.ToString());
                            parms.Add("{%price%}", string.Format("{0:C}", price));
                        }

                        string _priceInEuro = parms["{%price%}"];

                        if (_priceInEuro.Contains("$"))
                        {
                            parms.Remove("{%price%}");
                            _priceInEuro = _priceInEuro.Replace("$", "€").Replace(".", ",");
                            parms.Add("{%price%}", _priceInEuro);
                        }
                    }
                }

                if (Request.Params["tid"] != null /* && Request.Params["pid"] != null */)
                {
                    transid = Convert.ToInt64(Request.Params["tid"]);
                    if (transid > -1)
                    {
                        using (Database db = new MySqlDatabase())
                        {
                            Transaction transaction = db.GetQuotation(transid);
                            string statuscode = transaction.StatusCode;
                            string[] parts = statuscode.Split('(', ':', ')');
                            int credits = 0;
                            if (parts.Length >= 3)
                                credits = Convert.ToInt32(parts[2]);
                            desc = string.Format(Resources.Resource.BulkPurchase, credits, transaction.Amount);
                            parms.Add("{%product%}", desc);
                            parms.Add("{%credits%}", credits.ToString());
                        }
                    }
                }

                IncludePage(ProductInc, Resources.Resource.incBuyProductText, parms);

                //ProductLiteral.Text = string.Format(Resources.Resource.Purchase1, desc);
            }

            if (Convert.ToString(Session["culture"]).Contains("nl"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "HighLightLangBtn", "HighLightLangBtn('" + "ctl00_HeadLoginView_LanguageUS" + "');", true);
                ClientScript.RegisterStartupScript(this.GetType(), "UnHighLightLangBtn", "UnHighLightLangBtn('" + "ctl00_HeadLoginView_LanguageNL" + "');", true);
            }
        }
        private void ProcessFailure()
        {
            Logger.Instance.Write(LogLevel.Info, "Process failed transaction: {0}", Request.RawUrl);
            long userId = Util.UserId;
            long prodId = 0L;
            string country = "NL";
            string currency = "EUR";
            string culture = "nl-NL";
            decimal amount = 0m;
            if (Session["pid"] != null)
                prodId = Convert.ToInt64(Session["pid"]);
            if (Session["amt"] != null)
                amount = Convert.ToDecimal(Session["amt"]);
            if (Session["culture"] != null)
                culture = Session["culture"] as string;
            if (string.IsNullOrEmpty(culture))
                culture = "nl-NL";
            if (culture.Length < 4)
            {
                switch (culture)
                {
                    case "nl":
                        culture += "-NL";
                        break;
                    case "nl-":
                        culture += "NL";
                        break;
                    case "NL":
                        culture = "nl-" + culture;
                        break;
                    case "-NL":
                        culture = "nl" + culture;
                        break;
                    case "en":
                        culture = "-US";
                        break;
                    case "en-":
                        culture += "US";
                        break;
                    case "US":
                        culture = "en-" + culture;
                        break;
                    case "-US":
                        culture = "en" + culture;
                        break;
                }
            }
            country = culture.Substring(3);
            currency = Util.GetCurrencyIsoNameByCountryIso2(country);

            string res = Request.Params["res"] ?? string.Empty;
            string status = Request.Params["Status"] ?? string.Empty;
            string statusCode = Request.Params["StatusCode"] ?? string.Empty;
            string merchant = Request.Params["Merchant"] ?? string.Empty;
            string orderId = Request.Params["OrderID"] ?? string.Empty;
            string paymentId = Request.Params["PaymentID"] ?? string.Empty;
            string reference = Request.Params["Reference"] ?? string.Empty;
            string transid = Request.Params["TransactionID"] ?? string.Empty;
            string paymentMethod = Request.Params["PaymentMethod"] ?? string.Empty;
            if (!string.IsNullOrEmpty(statusCode))
                statusCode = Uri.UnescapeDataString(statusCode);
            using (Database db = new MySqlDatabase())
            {
                ProductInfo pi = db.GetProductById(prodId);
                db.UpdateTransaction(orderId, res, status, statusCode, merchant, paymentId, reference,
                                 transid, paymentMethod, amount, pi, currency, country);

                StringBuilder sb = new StringBuilder();
                sb.Append("<div>");
                sb.AppendFormat("<p><strong>{0}</strong></p>", Resources.Resource.TransactionFailed);
                sb.AppendFormat("<p>{0}</p>", statusCode);
                sb.Append("</div>");
                ResultLiteral.Text = sb.ToString();
            }

            sendMail(orderId, Resources.Resource.CreditPurchaseFailureSubject, Resources.Resource.CreditPurchaseFailureBody);
        }
        protected void SubmitButton_Command(object sender, CommandEventArgs e)
        {
            long prodid = -1;
            if (Request.Params["pid"] != null)
                prodid = Convert.ToInt64(Request.Params["pid"]);

            if (prodid > -1)
            {
                long userid = Util.UserId;

                string desc = string.Empty;
                decimal amount = 0m;
                //bool taxed = false;
                using (Database db = new MySqlDatabase())
                {
                    ProductInfo pi = db.GetProductById(prodid);
                    ProductPriceInfoList ppil = db.GetProductPrices(prodid, Request.Params["country"]);
                    desc = pi.Name;
                    amount = ppil[0].Price;
                    //taxed = true;
                }
                Session["pid"] = prodid;
                Session["amt"] = amount;

                PurchaseProduct(prodid, amount, desc);
            }
        }