コード例 #1
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();
            }
        }
コード例 #2
0
ファイル: TopupBL.cs プロジェクト: josher93/GPS.Rocket.WebAPI
        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);
        }