예제 #1
0
        /// <summary>
        /// Generates 'Denied Topup Request' notification content to be pushed to consumer
        /// </summary>
        /// <param name="pRequestData">Topup request data</param>
        /// <returns>Dictionary with notification content</returns>
        private Dictionary <String, String> CreateTopupDeniedContent(TopupRequestEN pRequestData)
        {
            Dictionary <string, string> notification = new Dictionary <string, string>();

            try
            {
                string amount     = Convert.ToString(pRequestData.Amount);
                string vendorCode = Convert.ToString(pRequestData.VendorCode);

                string Title   = "¡Recarga denegada!";
                string Message = String.Format(@"¡Hola! Lamentamos comunicarte que tu recarga de ${0} de {1} ha sido denegada por el vendedor con código {2}. ¡No dejes de solicitar recargas con YoComproRecarga!",
                                               amount,
                                               pRequestData.OperatorName.ToUpper(),
                                               vendorCode);

                notification.Add("title", Title);
                notification.Add("message", Message);
            }
            catch (Exception ex)
            {
                notification = null;
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("CreateTopupDeniedContent: " + ex.Message);
            }

            return(notification);
        }
예제 #2
0
        private List <UserBagHistoryEN> RegisterInitialUserBagState(List <PersonBagOperatorEN> pUserBags, int pProductID)
        {
            List <UserBagHistoryEN> userbagStates = new List <UserBagHistoryEN>();

            try
            {
                foreach (var bag in pUserBags)
                {
                    UserBagHistoryEN userbagState = new UserBagHistoryEN();
                    userbagState.BagID           = bag.BagID;
                    userbagState.ProductID       = pProductID;
                    userbagState.InitialBagValue = bag.UserBalanceAmount;
                    userbagState.InsertedAt      = DateTime.Now;
                    userbagState.UpdatedAt       = DateTime.Now;

                    int statusID = topupDAL.InsertUserBagHistory(userbagState);

                    if (statusID > 0)
                    {
                        userbagState.ID = statusID;
                        userbagStates.Add(userbagState);
                    }
                }
            }
            catch (Exception ex)
            {
                userbagStates = null;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("RegisterInitialUserBagState: " + ex.Message);
            }

            return(userbagStates);
        }
예제 #3
0
        private bool UpdateUserBagsRefund(ProductEN pProduct, List <PersonBagOperatorEN> pPersonBags, int pPersonID)
        {
            bool finished = false;
            int  counter  = 0;
            var  Operator = "";

            try
            {
                var empty = pPersonBags.SingleOrDefault(e => e.MobileOperatorID <= 0);
                pPersonBags.Remove(empty);

                counter = pPersonBags.Count;
                var contador = 0;
                foreach (var item in pPersonBags)
                {
                    if (contador == 0)
                    {
                        Operator = item.MobileOperatorID.ToString();
                    }
                    else
                    {
                        Operator = Operator + "," + item.MobileOperatorID.ToString();
                    }
                    contador++;

                    #region Logs
                    EventViewerLogger.LogInformation(String.Format("UpdateUserBags: Current User Bag: {0}, Operator: {1}, PersonID: {2}", item.UserBalance, item.MobileOperatorName, Convert.ToString(pPersonID)));
                    #endregion
                }


                // Decimal newAmount = (!pIsRefund) ? item.UserBalanceAmount - pProduct.PersonDiscount : item.UserBalanceAmount + pProduct.PersonDiscount;
                int result = topupDAL.UpdateUserBagRefund(pProduct.PersonDiscount, pPersonID, Operator, counter);

                if (result > 1)
                {
                    finished = true;
                }
                else
                {
                    finished = false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("UpdateUserBags: " + ex.Message);
            }

            return(finished);
        }
예제 #4
0
        /// <summary>
        /// Inserts topup request into TopupRequests of a specific vendor and pushes notification to vendor
        /// </summary>
        /// <param name="pConsumerID">YCR user (consumer) ID as in database</param>
        /// <param name="pTargetPhone">Phone number where topup must be made</param>
        /// <param name="pVendorCode">Vendor code as in database</param>
        /// <param name="pAmount">Topup transaction amount</param>
        /// <param name="pOperatorID">Operator ID as in database</param>
        /// <returns>Boolean: Success or not</returns>
        public async Task <bool> RequestTopup(int pConsumerID, string pNickname, string pTargetPhone, int pVendorCode, decimal pAmount, int pOperatorID, int pCategoryID)
        {
            bool requested = false;

            try
            {
                PersonEN vendor = topupDAL.GetPersonByVendorCode(pVendorCode);

                if (vendor != null)
                {
                    //Completes topup request data
                    TopupRequestEN request = new TopupRequestEN();
                    request.ConsumerID       = pConsumerID;
                    request.ConsumerNickname = pNickname;
                    request.TargetPhone      = pTargetPhone;
                    request.VendorCode       = vendor.VendorCode;
                    request.OperatorID       = pOperatorID;
                    request.Amount           = pAmount;
                    request.StatusCode       = 0;
                    request.RequestDate      = DateTime.Now;
                    request.ModDate          = DateTime.Now;
                    request.CategoryID       = pCategoryID;

                    //Inserts topup request
                    int insertedRequest = topupDAL.InsertTopupRequest(request);

                    if (insertedRequest > 0)
                    {
                        string phone = pTargetPhone.Insert(7, "-");
                        phone = phone.Substring(3);
                        string nickname = pNickname;

                        string amount = pAmount.ToString("C", new CultureInfo("en-US"));

                        //Sends notification to Vendor
                        var notificationResults = await campaignBL.SendTopupRequest(vendor.Email, nickname, phone, amount, vendor.Firstname);

                        requested = notificationResults.Where(n => n.Result).FirstOrDefault().Result;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("RequestTopup: " + ex.Message);
            }

            return(requested);
        }
예제 #5
0
        public int UpdateTopupRequest(TopupRequestEN pTopupRequest)
        {
            int update = default(int);

            try
            {
                update = connection.Cnn.Update(pTopupRequest);
            }
            catch (Exception ex)
            {
                update = 0;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("UpdateTopupRequest: " + ex.Message);
            }

            return(update);
        }
예제 #6
0
        public int InsertTopupRequest(TopupRequestEN pRequest)
        {
            int request = default(int);

            try
            {
                request = connection.Cnn.Insert(pRequest) ?? default(int);
            }
            catch (Exception ex)
            {
                request = 0;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("InsertTopupRequest: " + ex.Message);
            }

            return(request);
        }
예제 #7
0
        /// <summary>
        /// Returns all topup requests made to a specific vendor (by vendor code)
        /// </summary>
        /// <param name="pVendorCode">Vendor code as in database</param>
        /// <returns>List: All topup requests</returns>
        public List <TopupRequestEN> GetTopupRequestsByVendor(int pVendorCode)
        {
            List <TopupRequestEN> requests = new List <TopupRequestEN>();

            try
            {
                requests = topupDAL.GetTopupRequestsByVendorCode(pVendorCode);
            }
            catch (Exception ex)
            {
                requests = null;
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError(ex.Message);
            }

            return(requests);
        }
예제 #8
0
        public TopupRequestEN GetTopupRequestData(int pTopupRequestID)
        {
            TopupRequestEN request = new TopupRequestEN();

            try
            {
                request = connection.Cnn.Query <TopupRequestEN>("SpGetOperatorTopupRequest", new { topupRequestID = pTopupRequestID },
                                                                commandType: CommandType.StoredProcedure).FirstOrDefault();
            }
            catch (Exception ex)
            {
                request = null;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("GetTopupRequestByID: " + ex.Message);
            }

            return(request);
        }
예제 #9
0
        private Dictionary <String, String> CreateEarnedCoinContent()
        {
            Dictionary <string, string> notification = new Dictionary <string, string>();

            try
            {
                string Title   = "¡Has ganado una moneda!";
                string Message = "Gracias a tu recarga solicitada a través de RecarGO! has ganado una moneda. ¡Sigue adelante en la aventura!";

                notification.Add("title", Title);
                notification.Add("message", Message);
            }
            catch (Exception ex)
            {
                notification = null;
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("CreateEarnedCoinContent: " + ex.Message);
            }

            return(notification);
        }
예제 #10
0
        private void RegisterFinalUserBagState(List <UserBagHistoryEN> pInsertedStates, int pPersonID)
        {
            try
            {
                var actualUserBags = topupDAL.GetUserOperatorBags(pPersonID);

                foreach (var state in pInsertedStates)
                {
                    state.FinalBagValue = actualUserBags.Where(b => b.BagID == state.BagID).FirstOrDefault().UserBalanceAmount;
                    state.UpdatedAt     = DateTime.Now;

                    //Updates history item with new Balance
                    topupDAL.UpdateUserBagHistory(state);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("RegisterFinalUserBagState: " + ex.Message);
            }
        }
예제 #11
0
        public int InsertUserBagHistory(UserBagHistoryEN pBagHistory)
        {
            int userBagHistoryID = default(int);

            try
            {
                connection.Cnn.Open();
                userBagHistoryID = connection.Cnn.Insert(pBagHistory) ?? default(int);
            }
            catch (Exception ex)
            {
                userBagHistoryID = 0;
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("InsertUserBagHistory: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(userBagHistoryID);
        }
예제 #12
0
        public int UpdateUserBagHistory(UserBagHistoryEN pBagHistory)
        {
            int updated = default(int);

            try
            {
                connection.Cnn.Open();
                updated = connection.Cnn.Update(pBagHistory);
            }
            catch (Exception ex)
            {
                updated = 0;
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("UpdateUserBagHistory: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(updated);
        }
예제 #13
0
        public PersonEN GetPersonByVendorCode(int pVendorCode)
        {
            PersonEN person = new PersonEN();

            try
            {
                connection.Cnn.Open();
                person = connection.Cnn.Query <PersonEN>("SpGetPersonByVendorCode", new { vendorCode = pVendorCode },
                                                         commandType: CommandType.StoredProcedure).FirstOrDefault();
            }
            catch (Exception ex)
            {
                person = null;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("GetPersonByVendorCode: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(person);
        }
예제 #14
0
        public OperatorEN GetOperatorByBrand(int pCountryID, string pOperatorBrand)
        {
            OperatorEN oprtr;

            try
            {
                connection.Cnn.Open();
                oprtr = connection.Cnn.Query <OperatorEN>("SpGetCountryByBrand", new { @countryID = pCountryID, @brand = pOperatorBrand },
                                                          commandType: CommandType.StoredProcedure).FirstOrDefault();
            }
            catch (Exception ex)
            {
                oprtr = null;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("GetOperatorByBrand: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(oprtr);
        }
예제 #15
0
        public List <TopupRequestEN> GetTopupRequestsByVendorCode(int pVendorCode)
        {
            List <TopupRequestEN> requests = new List <TopupRequestEN>();

            try
            {
                connection.Cnn.Open();
                requests = connection.Cnn.Query <TopupRequestEN>("SpGetTopupRequests", new { @vendorID = pVendorCode },
                                                                 commandType: CommandType.StoredProcedure).AsList();
            }
            catch (Exception ex)
            {
                requests = null;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("GetTopupRequestsByVendorCode: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(requests);
        }
예제 #16
0
        public List <PersonBagOperatorEN> GetUserOperatorBags(int pPersonID)
        {
            List <PersonBagOperatorEN> personBags = new List <PersonBagOperatorEN>();

            try
            {
                connection.Cnn.Open();
                personBags = connection.Cnn.Query <PersonBagOperatorEN>("SpGetUserOperatorBags", new { @personID = pPersonID },
                                                                        commandType: CommandType.StoredProcedure).ToList();
            }
            catch (Exception ex)
            {
                personBags = null;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("GetUserOperatorBag: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(personBags);
        }
예제 #17
0
        public Decimal GetPersonAvailableAmount(int pPersonID, int pCountryID, string pOperatorName)
        {
            Decimal avaiable;

            try
            {
                connection.Cnn.Open();
                avaiable = connection.Cnn.Query <Decimal>("SpGetUserAvailableAmmount", new { @operatorName = pOperatorName, @countryID = pCountryID, @personID = pPersonID },
                                                          commandType: CommandType.StoredProcedure).FirstOrDefault();
            }
            catch (Exception ex)
            {
                avaiable = 0;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("GetPersonAvailableAmount: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(avaiable);
        }
예제 #18
0
        public ProductEN GetAvailableTopupProduct(string pOperatorName, int pCountryID, decimal pAmount, int pPackCode)
        {
            ProductEN topupProduct = new ProductEN();

            try
            {
                connection.Cnn.Open();
                topupProduct = connection.Cnn.Query <ProductEN>("SpGetAvailableOperatorProduct",
                                                                new { @operatorName = pOperatorName, @countryID = pCountryID, @amount = pAmount, @packCode = pPackCode },
                                                                commandType: CommandType.StoredProcedure).FirstOrDefault();
            }
            catch (Exception ex)
            {
                topupProduct = null;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("GetAvailableTopupProduct: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(topupProduct);
        }
예제 #19
0
        public CountryEN GetCountryByID(int pCountryID)
        {
            CountryEN country = new CountryEN();

            try
            {
                connection.Cnn.Open();
                country = connection.Cnn.Query <CountryEN>(@" SELECT Name AS Name
                                                                FROM core.Country
                                                                WHERE Id = @countryID", new { countryID = pCountryID }).FirstOrDefault();
            }
            catch (Exception ex)
            {
                country = null;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("GetCountryByID: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(country);
        }
예제 #20
0
        /// <summary>
        /// Logs topup transaction data
        /// </summary>
        /// <param name="pTransaction">Transaction entity</param>
        /// <param name="pPersonID">Vendor ID</param>
        /// <param name="pCountryID">Country ID</param>
        /// <param name="pOperatorName">Operator name</param>
        /// <param name="pInventoryDisc">Inventory discount amount</param>
        /// <param name="pPersonDisc">Person discount amount</param>
        public void LogTopupTransaction(GatsTransactionEN pTransaction, int pPersonID, int pCountryID, string pOperatorName, decimal pInventoryDisc, decimal pPersonDisc)
        {
            TopupTransactionEN topup = new TopupTransactionEN();

            try
            {
                connection.Cnn.Open();
                Byte status = 0;
                //if (pTransaction.ResponseCode == "Success" || pTransaction.ResponseCode == "02")
                //{
                //    status = 1;
                //}
                //var resultInsert = connection.Cnn.Insert<Int64>(pTransaction);

                //topup.AmountRequested = pTransaction.Amount.ToString();
                //topup.InventoryDiscount = pInventoryDisc;
                //topup.PersonDiscount = pPersonDisc;
                //topup.GATSTransactionID = resultInsert;
                //topup.PersonID = pPersonID.ToString();
                //topup.Status = status;
                //topup.RegDate = DateTime.Now;
                //topup.CountryID = pCountryID;
                //topup.Operator = pOperatorName;
                //connection.Cnn.Insert(topup);
                connection.Cnn.Query("SP_Inser_Logs", new { CountryID = pCountryID, PhoneNumber = pTransaction.PhoneNumber, Amount = pTransaction.Amount, Request = pTransaction.Request, Response = pTransaction.Response, ResponseCode = pTransaction.ResponseCode, TransactionID = pTransaction.TransactionID, ProviderTransactionID = pTransaction.ProviderTransactionID, personid = pPersonID, persondiscount = pPersonDisc, operatordiscount = pInventoryDisc, operador = pOperatorName }, commandType: CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("LogTopupTransaction: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }
        }
예제 #21
0
        public int UpdateUserBag(Decimal Amount, int pPersonID, string pOperator, int Total, int Producto = 0)
        {
            int update = 0;

            try
            {
                connection.Cnn.Open();
                update = connection.Cnn.Execute("SpUpdateUserBagFull",
                                                new { @Amount = Amount, @personID = pPersonID, @operators = pOperator, @totaloperator = Total, @product = Producto },
                                                commandType: CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                update = 0;
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("UpdateUserBag: " + ex.Message);
            }
            finally
            {
                connection.Cnn.Close();
            }

            return(update);
        }
예제 #22
0
        public bool AddCoinByTopup(int pConsumerID)
        {
            bool addedCoin = false;

            try
            {
                PlayersTrackingEN tracking = new PlayersTrackingEN();

                int coins = int.Parse(ConfigurationManager.AppSettings["CoinsByTopupSuccess"].ToString());

                var currentTracking = gameDAL.GetProgressGame(pConsumerID);

                if (currentTracking != null)
                {
                    tracking = currentTracking;
                    tracking.CurrentCoinsProgress = currentTracking.CurrentCoinsProgress + coins;
                    tracking.CurrentCoinsProgress = (tracking.CurrentCoinsProgress >= 20) ? 20 : tracking.CurrentCoinsProgress;
                    tracking.ModDate           = DateTime.Now;
                    tracking.ConsumerID        = pConsumerID;
                    tracking.PlayersTrackingID = currentTracking.PlayersTrackingID;

                    tracking.TotalWinCoins = currentTracking.TotalWinCoins + coins;

                    int UpdateResult = gameDAL.UpdatePlayerTracking(tracking);

                    //Updates current progress
                    if (UpdateResult > 0)
                    {
                        WinCoinEN winCoin = new WinCoinEN();

                        winCoin.ConsumerID    = pConsumerID;
                        winCoin.ExchangeCoins = coins;
                        winCoin.RegDate       = DateTime.Now;
                        winCoin.Longitude     = 0;
                        winCoin.Latitude      = 0;
                        winCoin.LocationID    = "0";
                        winCoin.ChestType     = 1;

                        var ResultInsert = gameDAL.InsertWinCoin(winCoin);

                        if (ResultInsert > 0)
                        {
                            addedCoin = true;
                        }
                    }
                }
                else
                {
                    tracking.CurrentCoinsProgress = coins;
                    tracking.CurrentCoinsProgress = (tracking.CurrentCoinsProgress >= 20) ? 20 : coins;
                    tracking.TotalWinCoins        = coins;
                    tracking.TotalWinPrizes       = 0;

                    int ResltInsert = gameDAL.InsertPlayerTracking(tracking.TotalWinCoins, tracking.CurrentCoinsProgress, pConsumerID, DateTime.Now);

                    //Inserts current progress
                    if (ResltInsert > 0)
                    {
                        WinCoinEN winCoin = new WinCoinEN();

                        winCoin.ConsumerID    = pConsumerID;
                        winCoin.ExchangeCoins = coins;
                        winCoin.RegDate       = DateTime.Now;
                        winCoin.Longitude     = 0;
                        winCoin.Latitude      = 0;
                        winCoin.LocationID    = "0";
                        winCoin.ChestType     = 0;

                        int InsertWinCoin = gameDAL.InsertWinCoin(winCoin);


                        if (InsertWinCoin > 0)
                        {
                            addedCoin = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                EventViewerLogger.LogError("" + ex.Message);
            }

            return(addedCoin);
        }
예제 #23
0
        public TopupTransactionEN AttemptSendTopup(string pPhone, decimal pAmount, int pPackCode, int MNOId, int CategoryId)
        {
            TopupTransactionEN topupResult = new TopupTransactionEN();
            string             amount;
            string             topupUrl;
            string             textResult;

            amount = String.Format("{0:0.##}", pAmount);
            //topupUrl = values.TopupUrl() + pPhone + "/" + amount + "/" + pPackCode;
            topupUrl = values.TopupUrl() + pPhone + "/" + amount + "/" + MNOId + "/" + CategoryId;

            try
            {
                var request = (HttpWebRequest)WebRequest.Create(topupUrl);
                request.Timeout = Int32.Parse(ConfigurationManager.AppSettings["SocketTimeout"].ToString());

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                EventViewerLogger.LogInformation("SendTopup GATS Response: " + response.ToString());

                Stream       stream       = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream);

                textResult = streamReader.ReadToEnd();
                var serializer       = new JavaScriptSerializer();
                var serializedResult = serializer.Deserialize <ApiResponse>(textResult);

                topupResult.Code = serializedResult.resultCode;
                topupResult.ServiceTransactionID = serializedResult.serviceTransactionId;
                topupResult.Message    = serializedResult.errorMessage;
                topupResult.RequestURL = topupUrl;
                topupResult.Response   = textResult;

                if (serializedResult.ExtraParameters == null)
                {
                    topupResult.Msisdn = pPhone;
                    topupResult.Mno    = "";
                }
                else
                {
                    topupResult.Msisdn = pPhone;
                    topupResult.Mno    = serializedResult.ExtraParameters[0].value;
                }
            }
            catch (WebException ex)
            {
                if (ex.Response != null)
                {
                    textResult = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                    var serializer = new JavaScriptSerializer();

                    var serializedResult = serializer.Deserialize <ApiResponse>(textResult);
                    topupResult.Code = serializedResult.resultCode;
                    topupResult.ServiceTransactionID = serializedResult.serviceTransactionId;
                    topupResult.Message    = serializedResult.errorMessage;
                    topupResult.RequestURL = topupUrl;
                    topupResult.Response   = textResult;

                    EventViewerLogger.LogError("SendTopup WebException: " + ex.ToString());
                    EventViewerLogger.LogInformation("SendTopup serializedResult: " + serializedResult.errorMessage);
                }
                else
                {
                    topupResult.Code       = "NoServerResponse";
                    topupResult.Message    = "";
                    topupResult.RequestURL = topupUrl;
                    topupResult.Response   = "";
                }
            }
            catch (Exception ex)
            {
                topupResult.Code       = "Error";
                topupResult.Message    = ex.Message;
                topupResult.RequestURL = topupUrl;
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("AttemptSendTopup: " + ex.Message);
            }

            return(topupResult);
        }
예제 #24
0
        public TopupTransactionEN SendTopup(PersonEN pPerson, string pOperatorName, decimal pAmount, string pPhone, int pPackCode)
        {
            TopupTransactionEN topupResult = new TopupTransactionEN();
            TopupEN            topup       = new TopupEN();

            ProductEN product = new ProductEN();

            topup.Operator    = pOperatorName;
            topup.Amount      = pAmount;
            topup.Phone       = pPhone;
            topup.PackageCode = pPackCode;

            try
            {
                var topupData = ValidateTopupData(pPerson, topup, ref product);

                if (topupData.IsValid)
                {
                    List <PersonBagOperatorEN> operatorUserBags = topupDAL.GetUserOperatorBags(pPerson.PersonID);

                    //Register initial bags state
                    // var states = RegisterInitialUserBagState(operatorUserBags, product.ProductID);

                    try
                    {
                        //Discounts product amount from user's bag
                        if (UpdateUserBags(product, operatorUserBags, pPerson.PersonID))
                        {
                            #region AzureSearch
                            //if (!azureSearch.CheckExistingEntry(topupData.Phone))
                            //    azureSearch.InsertEntry(pPerson.PersonID, pOperatorName, pPhone, pPerson.CountryID);
                            //else
                            //    azureSearch.ComparePhoneNumber(pPhone, pOperatorName, pPerson.PersonID, pPerson.CountryID);
                            #endregion

                            //Gets response from Topup Service
                            topupResult = topupClient.AttemptSendTopup(pPhone, pAmount, pPackCode, topupData.OperatorID, topupData.CategoryID);

                            GatsTransactionEN transaction = new GatsTransactionEN();
                            transaction.Request               = topupResult.RequestURL;
                            transaction.Response              = topupResult.Response;
                            transaction.TransactionID         = topupResult.ServiceTransactionID;
                            transaction.ProviderTransactionID = topupResult.ServiceTransactionID;
                            transaction.Amount       = pAmount;
                            transaction.CountryID    = pPerson.CountryID;
                            transaction.PhoneNumber  = long.Parse(pPhone.ToString());
                            transaction.RegDate      = DateTime.Now;
                            transaction.ResponseCode = topupResult.Code;
                            transaction.Paid         = true;

                            if (!String.Equals(topupResult.Code, "Success") && !String.Equals(topupResult.Code, "02"))
                            {
                                if (product.PersonDiscount > 0)
                                {
                                    //Refunds user balance from updated values
                                    var updatedBags = topupDAL.GetUserOperatorBags(pPerson.PersonID);
                                    UpdateUserBagsRefund(product, updatedBags, pPerson.PersonID);
                                }
                            }
                            else
                            {
                                topupResult.Message = topupData.Result;
                            }

                            //Updates users bags history
                            //RegisterFinalUserBagState(states, pPerson.PersonID);

                            topupDAL.LogTopupTransaction(transaction, pPerson.PersonID, pPerson.CountryID, topupData.Operator, product.InventoryDiscount, product.PersonDiscount);
                            EventViewerLogger.LogInformation("SendTopup: " + transaction.Response);
                        }
                    }
                    catch (Exception ex)
                    {
                        topupResult.Message = ex.Message;
                        topupResult.Code    = "Error";

                        if (product.PersonDiscount > 0)
                        {
                            //Gets user bags with updated values
                            operatorUserBags = topupDAL.GetUserOperatorBags(pPerson.PersonID);

                            //Refunds user bag if any exception ocurred
                            UpdateUserBagsRefund(product, operatorUserBags, pPerson.PersonID);
                            EventViewerLogger.LogError(String.Format("SendTopup - Inner exception: Refund user bags. PersonID {0}. Amount {1}. Message: {2}",
                                                                     Convert.ToString(pPerson.PersonID), product.PersonDiscount, ex.Message));

                            //Updates users bags history
                            //RegisterFinalUserBagState(states, pPerson.PersonID);
                        }
                    }
                }
                else
                {
                    //Sets the results according to topup data validation
                    topupResult.Message = topupData.Result;
                    topupResult.Code    = topupData.Result;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("SendTopup: " + ex.Message);
            }

            return(topupResult);
        }
예제 #25
0
        /// <summary>
        /// Validates topup requested data is correct. Checks the product selected is available for the mobile operator.
        /// Validates amount requested over user's bags
        /// </summary>
        /// <param name="pPerson">Vendor</param>
        /// <param name="pTopupData">Topup info (phone, amount, operator, etc)</param>
        /// <returns>Topup data result</returns>
        private TopupEN ValidateTopupData(PersonEN pPerson, TopupEN pTopupData, ref ProductEN oProduct)
        {
            ProductEN productAvailable = new ProductEN();
            TopupEN   validTopup       = new TopupEN();

            validTopup.IsValid  = false;
            validTopup.PersonID = pPerson.PersonID;

            try
            {
                //Checks available topup product
                productAvailable = topupDAL.GetAvailableTopupProduct(pTopupData.Operator, pPerson.CountryID, pTopupData.Amount, pTopupData.PackageCode);

                if (productAvailable != null)
                {
                    //Product selected for transaction
                    oProduct = productAvailable;

                    //Validates if user balance is required for transaction
                    if (productAvailable.PersonDiscount > 0)
                    {
                        //Checks user's bags balance
                        Decimal balance = topupDAL.GetPersonAvailableAmount(pPerson.PersonID, pPerson.CountryID, pTopupData.Operator);
                        if (balance > 0)
                        {
                            if (balance >= productAvailable.PersonDiscount)
                            {
                                validTopup.Operator   = productAvailable.OperatorName;
                                validTopup.Product    = productAvailable;
                                validTopup.IsValid    = true;
                                validTopup.Result     = Values.Ok;
                                validTopup.ResultCode = Values.OkCode;
                                validTopup.OperatorID = productAvailable.OperatorID;
                                validTopup.CategoryID = productAvailable.CategoryID;
                            }
                            else
                            {
                                validTopup.Operator   = productAvailable.OperatorName;
                                validTopup.IsValid    = false;
                                validTopup.Result     = Values.NoCreditLeft;
                                validTopup.ResultCode = Values.NoCreditLeftCode;
                            }
                        }
                        else
                        {
                            validTopup.Operator   = productAvailable.OperatorName;
                            validTopup.IsValid    = false;
                            validTopup.Result     = Values.NoCreditLeft;
                            validTopup.ResultCode = Values.NoCreditLeftCode;
                        }
                    }
                    else
                    {
                        //Balance on user bag is not required
                        validTopup.Operator   = productAvailable.OperatorName;
                        validTopup.IsValid    = true;
                        validTopup.Result     = Values.Ok;
                        validTopup.ResultCode = Values.PackageTopupCode;
                    }
                }
                else
                {
                    validTopup.Operator   = pTopupData.Operator;
                    validTopup.IsValid    = false;
                    validTopup.Result     = Values.InvalidProduct;
                    validTopup.ResultCode = Values.InvalidProductCode;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("ValidateTopupData: " + ex.Message);
            }

            return(validTopup);
        }
예제 #26
0
        /// <summary>
        /// Answers to a specific topup request by a consumer. If accepted, sends a topup and adds a coin to consumer's game progress.
        /// </summary>
        /// <param name="pPerson">Vendor data who makes the topup</param>
        /// <param name="pRequestID">Topup request ID as in database</param>
        /// <param name="pAccept">Answer: true if 'accepted' and false if 'denied'</param>
        /// <returns>Boolean: True if succeed and false if something went wrong</returns>
        public bool AnswerTopupRequest(PersonEN pPerson, int pRequestID, bool pAccept)
        {
            bool result = false;

            try
            {
                //Gets Topup request data
                var requestData = topupDAL.GetTopupRequestData(pRequestID);
                requestData.ModDate = DateTime.Now;

                if (pAccept)
                {
                    requestData.StatusCode = 1;

                    //Updates request to 'Status = 1' (accepted)
                    if (topupDAL.UpdateTopupRequest(requestData) > 0)
                    {
                        //Validates and fires topup
                        var topupTransaction = SendTopup(pPerson, requestData.OperatorName, requestData.Amount, requestData.TargetPhone, requestData.PackageCode);

                        if (topupTransaction != null)
                        {
                            if (String.Equals(topupTransaction.Message, Values.Ok) && requestData.OperatorName == "Claro")
                            {
                                bool AddCoinByTopUp = gameBL.AddCoinByTopup(requestData.ConsumerID);

                                if (AddCoinByTopUp == true)
                                {
                                    var content = CreateEarnedCoinContent();
                                    EventViewerLogger.LogInformation("AnswerTopupRequest: Consumer earned coin by accepted Topup request");

                                    if (content != null)
                                    {
                                        string title     = (content.ContainsKey("title")) ? content["title"] : "";
                                        string message   = (content.ContainsKey("message")) ? content["message"] : "";
                                        string pImageURL = "";

                                        //Send Notification
                                        var SendNotification = campaignBL.SendEarnedCoinNotification(title, message, pImageURL, requestData.ConsumerPhone);

                                        if (SendNotification != null)
                                        {
                                            result = SendNotification.Where(n => n.Result).FirstOrDefault().Result;
                                        }
                                    }
                                }
                                else
                                {
                                    EventViewerLogger.LogError("AnswerTopupRequest: Coin earned was not added to player tracking");
                                }


                                result = true;
                            }
                        }
                    }
                }
                else
                {
                    requestData.StatusCode = 2;

                    //Updates request to 'Status = 2' (denied)
                    if (topupDAL.UpdateTopupRequest(requestData) > 0)
                    {
                        //Creates notification content
                        var content = CreateTopupDeniedContent(requestData);

                        if (content != null)
                        {
                            string title     = (content.ContainsKey("title")) ? content["title"] : "";
                            string message   = (content.ContainsKey("message")) ? content["message"] : "";
                            string pImageURL = "";

                            //Fires notificiation
                            var notifications = campaignBL.SendTopupDeniedNotification(title, message, pImageURL, requestData.ConsumerPhone);

                            if (notifications != null)
                            {
                                result = notifications.Where(n => n.Result).FirstOrDefault().Result;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                EventViewerLogger.LogError("AnswerTopupRequest: " + ex.Message);
            }

            return(result);
        }