public int topupPostBackGA(int card_id, string phoneNum, string result, int menhGiaThe, int menhGiaDK, int menhGiaThuc, string status, string requestId)
        {
            try
            {
                int stt = -1;
                if (status == "success")
                {
                    stt = 1;
                }
                var his = TransactionDAO.GetTopupHistory(requestId);
                if (his != null)
                {
                    List <CardConfig> data = TransactionDAO.GetCardConfigs().ToList();
                    var d = data.FirstOrDefault(x => x.Type == his.CardType && x.Prize == menhGiaThuc);
                    if (d == null)
                    {
                        d = new CardConfig();
                    }
                    long exchangeValue = menhGiaThuc * d.TopupRate / 100;
                    exchangeValue += (exchangeValue * d.Promotion / 100);
                    //TransactionDAO.UpdatePayResult(id, status, amount);
                    TransactionDAO.RetopupCard(requestId, menhGiaThuc, exchangeValue, stt);
                }

                return(1);
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            return(-99);
        }
        public CashoutModel Cashout(int cardType, int prize)
        {
            try
            {
                List <CardConfig> data = TransactionDAO.GetCardConfigs().ToList();
                var d = data.FirstOrDefault(x => x.Type == cardType && x.Prize == prize);
                if (d == null)
                {
                    return new CashoutModel {
                               Status = -100
                    }
                }
                ;

                return(TransactionDAO.Cashout(AccountSession.AccountID, AccountSession.AccountName, cardType, prize, prize * (d.CashoutRate - d.Promotion) / 100));
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            return(new CashoutModel
            {
                Status = -99
            });
        }
        public string callbackgg([FromBody] PayGooglesCallback pay)
        {
            NLogManager.LogMessage("CALLBACK PAY GG: " + JsonConvert.SerializeObject(pay));
            try
            {
                var his = TransactionDAO.GetTopupHistory(pay.transaction_id);
                if (his != null)
                {
                    List <CardConfig> data = TransactionDAO.GetCardConfigs().ToList();
                    var d = data.FirstOrDefault(x => x.Type == his.CardType && x.Prize == pay.amount);
                    if (d == null)
                    {
                        d = new CardConfig();
                    }
                    long exchangeValue = pay.amount * d.TopupRate / 100;
                    exchangeValue += (exchangeValue * d.Promotion / 100);
                    if (pay.error_code != 1 && pay.error_code > 0)
                    {
                        pay.error_code *= -1;
                    }
                    TransactionDAO.UpdatePayResult(pay.transaction_id, pay.error_code, pay.amount);
                    TransactionDAO.RetopupCard(pay.transaction_id, pay.amount, exchangeValue, pay.error_code);
                }

                return("1|success");
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            return("-1|failed");
        }
        public string callbackbb2d([FromBody] paybb2dCallBack pay)
        {
            NLogManager.LogMessage(JsonConvert.SerializeObject(pay));
            try
            {
                var his = TransactionDAO.GetTopupHistory(pay.RefCode);
                if (his != null)
                {
                    List <CardConfig> data = TransactionDAO.GetCardConfigs().ToList();
                    var d = data.FirstOrDefault(x => x.Type == his.CardType && x.Prize == pay.Amount);
                    if (d == null)
                    {
                        d = new CardConfig();
                    }
                    long exchangeValue = pay.Amount * d.TopupRate / 100;
                    exchangeValue += (exchangeValue * d.Promotion / 100);
                    if (pay.Status != 1 && pay.Status > 0)
                    {
                        pay.Status *= -1;
                    }
                    TransactionDAO.UpdatePayResult(pay.RefCode, pay.Status, pay.Amount);
                    TransactionDAO.RetopupCard(pay.RefCode, pay.Amount, exchangeValue, pay.Status);
                }

                return("1|success");
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            return("-1|failed");
        }
        public int callbackth(int status, string message, int amount, int port, string type, string code, string serial, string tranid, string ext, string receive, string response, string updated)
        {
            try
            {
                NLogManager.LogMessage($"CallBack TIMO: {status}|{message}|{amount}|{port}|{type}|{code}|{serial}|{tranid}|{ext}|{receive}|{response}|{updated}");
                var his = TransactionDAO.GetTopupHistory(tranid);
                if (his != null)
                {
                    List <CardConfig> data = TransactionDAO.GetCardConfigs().ToList();
                    var d = data.FirstOrDefault(x => x.Type == his.CardType && x.Prize == amount);
                    if (d == null)
                    {
                        d = new CardConfig();
                    }
                    long exchangeValue = amount * d.TopupRate / 100;
                    exchangeValue += (exchangeValue * d.Promotion / 100);
                    if (status > 0 && status != 1)
                    {
                        status *= -1;
                    }
                    if (status == 0)
                    {
                        status = -1;
                    }
                    TransactionDAO.UpdatePayResult(tranid, status, amount);
                    TransactionDAO.RetopupCard(tranid, amount, exchangeValue, status);
                }

                return(1);
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }
            return(-99);
        }
        public bool callbackTopupKhan(string id, int status, int amount)
        {
            NLogManager.LogMessage("PayKHAN CALLBACK => " + $"{id}|{status}|{amount}");
            try
            {
                var his = TransactionDAO.GetTopupHistory(id);
                if (his != null)
                {
                    List <CardConfig> data = TransactionDAO.GetCardConfigs().ToList();
                    var d = data.FirstOrDefault(x => x.Type == his.CardType && x.Prize == amount);
                    if (d == null)
                    {
                        d = new CardConfig();
                    }
                    long exchangeValue = amount * d.TopupRate / 100;
                    exchangeValue += (exchangeValue * d.Promotion / 100);
                    if (status > 0)
                    {
                        status *= -1;
                    }
                    if (status == 0)
                    {
                        status = 1;
                    }
                    TransactionDAO.UpdatePayResult(id, status, amount);
                    TransactionDAO.RetopupCard(id, amount, exchangeValue, status);
                }

                return(true);
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }
            return(false);
        }
        public List <CardCheck> CashoutInfo()
        {
            List <CardConfig> data = TransactionDAO.GetCardConfigs().ToList();

            return(GetCashoutInfo(data));
        }
        public async Task <TopupResponse> TopupCard(string serial, string pin, int cardType, int prize, string captcha, string token)
        {
            try
            {
                int captchaVeriryStatus = Utilities.Captcha.Verify(captcha, token);
                if (captchaVeriryStatus < 0)
                {
                    return new TopupResponse {
                               ErrorCode = captchaVeriryStatus, Message = "Mã xác nhận không chính xác hoặc đã hết hạn"
                    }
                }
                ;
                List <CardConfig> data = TransactionDAO.GetCardConfigs().ToList();
                var d = data.FirstOrDefault(x => x.Type == cardType && x.Prize == prize);
                if (d == null)
                {
                    return new TopupResponse {
                               ErrorCode = -100, Message = "Loại thẻ này không hợp lệ"
                    }
                }
                ;
                var dataPay = GetTopupInfo(data);
                if (!dataPay.Exists(x => x.Type == cardType && x.Enable && x.Prizes.Exists(y => y.Prize == prize)))
                {
                    return new TopupResponse {
                               ErrorCode = captchaVeriryStatus, Message = "Thẻ mệnh giá này hiện tại không sử dụng được."
                    }
                }
                ;
                var    idx                    = data.FirstOrDefault(x => x.Type == cardType && x.Enable && x.Prize == prize);
                int    payIndex               = PayIndexCounter.PayIndex(idx.PayOrderConfig, prize, idx.Type);
                long   randomFactor           = DateTime.Now.Ticks + RandomUtil.NextInt(1000) + AccountSession.AccountID;
                string transactionId          = Security.MD5Encrypt(pin + "_" + serial + "_" + cardType + "_" + randomFactor);
                PaymentTopupResponse response = null;
                switch (payIndex)
                {
                //case 1:
                //    int payVzCardType = 1; //the viettel
                //    if (cardType == 4)
                //        payVzCardType = 2; //the zing
                //    response = PayVZ.Topup(serial, pin, payVzCardType, prize, string.Empty);
                //    break;
                //case 2:
                //    var paybb2dCardType = string.Empty;
                //    if (cardType == 1)
                //        paybb2dCardType = "viettel";
                //    else if (cardType == 2)
                //        paybb2dCardType = "vms";
                //    else if (cardType == 3)
                //        paybb2dCardType = "vnp";
                //    response = PayBB2DUwin.Topup(serial, pin, paybb2dCardType, prize, AccountSession.AccountName, transactionId);
                //    break;
                //case 3:
                //    var paytimoCardType = string.Empty;
                //    if (cardType == 1)
                //        paytimoCardType = "VTT";
                //    else if (cardType == 2)
                //        paytimoCardType = "VMS";
                //    else if (cardType == 3)
                //        paytimoCardType = "VNP";
                //    transactionId = transactionId.Substring(0, 20);
                //    response = PayTichHop.Topup(serial, pin, paytimoCardType, prize, AccountSession.AccountName, IPAddressHelper.GetClientIP(), transactionId);
                //    break;
                //case 4:
                //    var payKhanCardType = string.Empty;
                //    if (cardType == 1)
                //        payKhanCardType = "1";
                //    else if (cardType == 2)
                //        payKhanCardType = "3";
                //    else if (cardType == 3)
                //        payKhanCardType = "2";
                //    transactionId = (Thread.CurrentThread.ManagedThreadId + long.Parse(dateTt().Trim()) + RandomUtil.NextInt(1000)).ToString();
                //    response = await PayKHAN.Topup(serial, pin, payKhanCardType, prize, AccountSession.AccountName, transactionId);
                //    break;
                //case 5:
                //    int payMbCardType = cardType;
                //    if (cardType == 4)
                //        payMbCardType = 2;
                //    else if (cardType == 2)
                //        payMbCardType = 221;
                //    response = PayMB.Topup(serial, pin, payMbCardType, prize, AccountSession.AccountName, transactionId);
                //    break;
                default:
                    string cardTypeGA = string.Empty;

                    if (cardType == 1)
                    {
                        cardTypeGA = "vt";
                    }
                    else if (cardType == 2)
                    {
                        cardTypeGA = "mb";
                    }
                    else if (cardType == 3)
                    {
                        cardTypeGA = "vn";
                    }
                    response = PayGA.Topup(serial, pin, cardTypeGA, prize, string.Empty, transactionId);
                    break;
                }


                if (response.ErrorCode == 1)
                {
                    prize = response.Amount;
                    long exchangeValue = prize * d.TopupRate / 100;
                    exchangeValue += (exchangeValue * d.Promotion / 100);
                    var topUpResponse = TransactionDAO.TopupCard(transactionId, AccountSession.AccountID, AccountSession.AccountName,
                                                                 prize, exchangeValue, 1, pin, serial, AccountSession.DeviceID, "Nạp thẻ", cardType);
                    if (topUpResponse >= 0)
                    {
                        return(new TopupResponse
                        {
                            Balance = topUpResponse,
                            ErrorCode = 1,
                            ExchangeValue = exchangeValue
                        });
                    }
                    else
                    {
                        NLogManager.LogMessage("Topup Error: " + AccountSession.AccountID + "|" + serial + "|" + pin + "|" + prize + "|" + topUpResponse);
                    }
                }

                if (response.ErrorCode == -20000000)
                {
                    long exchangeValue = prize * d.TopupRate / 100;
                    exchangeValue += (exchangeValue * d.Promotion / 100);
                    var topUpResponse = TransactionDAO.TopupCard(transactionId, AccountSession.AccountID, AccountSession.AccountName,
                                                                 prize, exchangeValue, 0, pin, serial, AccountSession.DeviceID, "Nạp thẻ", cardType);

                    return(new TopupResponse
                    {
                        ErrorCode = response.ErrorCode,
                        Message = response.Message
                    });
                }

                return(new TopupResponse
                {
                    ErrorCode = response.ErrorCode,
                    Message = response.Message
                });
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            return(new TopupResponse
            {
                ErrorCode = -99,
                Message = "Hệ thống của chúng tôi đang bận, xin bạn vui lòng thử lại sau",
            });
        }