Beispiel #1
0
        public DL_SessionCyberPlateStatusReturn GetCyberPlateStatus(DL_SessionCyberPlateStatus dL_SessionCyberPlateStatus)
        {
            _IsSuccess = true;
            dL_SessionCyberPlateStatusReturn = new DL_SessionCyberPlateStatusReturn();
            ProcessReqReturn prt          = new ProcessReqReturn();
            string           TransationId = string.Empty;

            try
            {
                RechargeProcess  rechargeProcess  = new RechargeProcess();
                CyberPlateStatus cyberPlateStatus = GetSessionId(dL_SessionCyberPlateStatus.TransactionId); //Added | Ranjeet |26-Dec |Get Session and Opid
                if (cyberPlateStatus != null)
                {
                    string strinputMsgStatus = rechargeProcess.GetInputMessageForStatus(cyberPlateStatus.SessionId,
                                                                                        cyberPlateStatus.OperatorId, string.Empty);

                    string statusResponse = RechargeProcess.Process(rechargeProcess.Status_OperatorRequestUrl(cyberPlateStatus.OperatorId), strinputMsgStatus);

                    int num = statusResponse.LastIndexOf("TRANSID=");
                    TransationId = statusResponse.Substring(num).Split(new char[1] {
                        '\r'
                    })[0].Split('=')[1];
                    if (statusResponse.IndexOf("ERROR=0") != -1 && statusResponse.IndexOf("RESULT=7") != -1)
                    {
                        dL_SessionCyberPlateStatusReturn.TransId = TransationId;
                        dL_SessionCyberPlateStatusReturn.Status  = "1";
                        dL_SessionCyberPlateStatusReturn.Message = "Successfully recharged.";
                        return(dL_SessionCyberPlateStatusReturn);
                    }
                    else
                    {
                        dL_SessionCyberPlateStatusReturn.TransId = TransationId;
                        dL_SessionCyberPlateStatusReturn.Status  = "2";
                        dL_SessionCyberPlateStatusReturn.Message = rechargeProcess.GetErrorDescription(statusResponse);
                        return(dL_SessionCyberPlateStatusReturn);
                    }
                }

                else
                {
                    return(null);
                }
            }


            catch (Exception ex)
            {
                Logger.WriteLog(LogLevelL4N.ERROR, "Exception : " + ex.Message);
                _IsSuccess = false;
            }

            return(dL_SessionCyberPlateStatusReturn);
        }
        public DL_ServiceReturn Service(DL_Service service)
        {
            try
            {
                this._IsSuccess    = true;
                this.serviceReturn = new DL_ServiceReturn();
                ProcessReqReturn rechargeStatus = new ProcessReqReturn();

                #region Check Account available balance and servie status.

                this.SpName = DL_StoreProcedure.SP_DHS_API_AvailableBalanceNServieStatus; //Sp Name || Get the Available balance and Service status.
                SqlParameter[] p = new SqlParameter[2];
                p[0] = new SqlParameter("@UserId", service.UserId);
                p[1] = new SqlParameter("@OpId", service.OperatorId);
                ds   = db.GetDataSet(this.SpName, p);
                UserInfo userInfo = null;

                if (ds != null && ds.Tables.Count > 0)
                {
                    DataRow drc = ds.Tables[0].Rows[0];

                    userInfo = new UserInfo()
                    {
                        AvailBal      = Convert.ToDouble(drc["AvailableBalance"] != null ? drc["AvailableBalance"] : 0),
                        Margin        = Convert.ToDouble(drc["Margin"]),
                        ServiceStatus = Convert.ToBoolean(drc["ServiceStatus"]),
                        UType         = Convert.ToInt32(drc["UType"]),
                        IsFixedCharge = Convert.ToBoolean(drc["IsFixedCharge"])
                    };
                }

                #endregion

                #region Call Cyber Plate APIs

                if (userInfo.AvailBal >= service.Amount && userInfo.ServiceStatus)
                {
                    //if (!string.IsNullOrEmpty(service.InsuranceDob) && (Convert.ToInt32(service.OperatorId) == 243) || Convert.ToInt32(service.OperatorId) == 242)//Insurance
                    //account = service.InsuranceDob;
                    rechargeStatus = new RechargeProcess().ProcessRequest(service.OperatorId, service.Number, service.Amount, service.Account);

                    //double profit = 0;
                    string transactionId = string.IsNullOrEmpty(rechargeStatus.TransactionId) ? "-1" : rechargeStatus.TransactionId;
                    string status        = rechargeStatus.StatusCode == 1 ? "1" : "0"; //check once
                    int    apiId         = (int)APIName.Cyber_Plate;                   //"CyberPate";
                    string billRecieptId = string.Empty;

                    //Profit ||
                    //check || Postpaid,electricity, gas bill, insurense and broadband
                    if (rechargeStatus.StatusCode == 1)
                    {
                        //if (userInfo.IsFixedCharge)
                        //{
                        //    profit = 0; //No Profit
                        //    //service.Amount = service.Amount+ userInfo.Margin;//Fixed charges from Crebit
                        //}
                        //else
                        //{
                        //    profit = ((service.Amount * userInfo.Margin) / 100); //Percentage margin
                        //}
                    }
                    else //Fail
                    {
                        //profit = 0;
                        service.Amount = 0;
                    }

                    #region SQLParameters

                    this.SpName = DL_StoreProcedure.SP_DHS_API_Service; //Sp Name
                    SqlParameter[] param = new SqlParameter[10];
                    param[0] = new SqlParameter("@UserId", service.UserId);
                    param[1] = new SqlParameter("@Number", service.Number);
                    param[2] = new SqlParameter("@Amount", service.Amount);
                    //param[3] = new SqlParameter("@Profit", profit);
                    param[3] = new SqlParameter("@ApiTransactionId", transactionId); //transId from CyberPlate
                    param[4] = new SqlParameter("@OperaterId", service.OperatorId);
                    param[5] = new SqlParameter("@Status", status);                  //'1-pass' || '0-fail'
                    param[6] = new SqlParameter("@Source", service.Source);          //'website/androidapp'
                    param[7] = new SqlParameter("@ApiId", apiId);                    //CyberPlate
                    param[8] = new SqlParameter("@Date", indianTime);
                    param[9] = new SqlParameter("@Session", rechargeStatus.SessionId);

                    #endregion

                    ds = db.GetDataSet(this.SpName, param);
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];
                        serviceReturn.TransId          = dr["TransId"].ToString();
                        serviceReturn.AvailableBalance = dr["AvBalance"].ToString();
                        string reMobile = dr["Mobile"].ToString();
                        //AvBalance
                        serviceReturn.StatusCode = rechargeStatus.StatusCode; //success
                        #region commented || SMS || Not required || 05-Aug-14
                        if (serviceReturn.StatusCode == 1)
                        {
                            //send message to retailer
                            //Dear USER ##Field##. Recharge successful on ##Field## for Rs. ##Field##.Your Available Balance is ##Field##.CREBIT Customer Experience Team.
                            //string message = "Dear USER " + service.UserId + ". Recharge successful on " + service.Number + " for Rs.  " + service.Amount + ".Your Available Balance is " + serviceReturn.AvailableBalance + ".CREBIT Customer Experience Team.";
                            //string message = "Dear User" + service.UserId + ". Recharge successful on " + service.Number + " for Rs. " + service.Amount + ".Your Available Balance is " + serviceReturn.AvailableBalance + " .Crebit Customer Experience Team.";

                            //send meesage to customer > amount => 250
                            string message = "Dear User, Recharge successful on " + service.Number + " for Rs." + service.Amount + " .CREBIT Customer Experience Team.";

                            if (service.Amount >= 250)
                            {
                                Task t = new Task(() => BL_SMS.SendSMS(service.Number, message));
                                t.Start();
                            }
                            //send message to customer
                            //if (service.TransactionType == "1" || service.TransactionType == "2")
                            {
                                //  message = "Dear Customer, Your account has been successfully recharged for Rs. " + service.Amount + " .Crebit Customer Experience Team.";
                                //BL_SMS.SendSMS(service.Number, message);
                            }
                        }
                        #endregion
                    }
                    serviceReturn.Message = rechargeStatus.Message;
                }
                #endregion

                #region If Either not enough balance or Servie if Off
                else
                {
                    //serviceReturn.IsSuccess = false;
                    serviceReturn.TransId = null;

                    if (userInfo.AvailBal < service.Amount)
                    {
                        //serviceReturn.Message = "Not enough Balance in account";
                        serviceReturn.StatusCode = 2;
                    }
                    else
                    {
                        //serviceReturn.Message = "Serice is Off";
                        serviceReturn.StatusCode = 3;
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                Logger.WriteLog(LogLevelL4N.ERROR, "@Service | Exception : " + ex.Message);
                serviceReturn.StatusCode = 0; //error
                serviceReturn.TransId    = null;
                _IsSuccess = false;
            }

            return(serviceReturn);
        }