예제 #1
0
        public void SendRecharge(string actId, GrappedRecharge data)
        {
            var POSBalance = new RechargeRepo().GetBalance(data.PointOfSaleAccount);
            var messages   = new MessageTemplateRepo().GetMessages(actId);

            if (messages != null && messages.Count > 0)
            {
                foreach (var msgObj in messages)
                {
                    var msg = msgObj.Message;
                    msg = msg.Replace("{amount}", data.Amount.ToString("N2"));
                    msg = msg.Replace("{mobile.1}", data.PointOfSaleId);
                    msg = msg.Replace("{mobile.2}", data.SubscriberNo);
                    msg = msg.Replace("{balance.1}", POSBalance.ToString("N2"));

                    var sendResult = new SMSOutRepo().Create(
                        new Entities.SMSOut()
                    {
                        Message  = msg,
                        Receiver = (msgObj.ToWho == 1 ? data.PointOfSaleId : data.SubscriberNo),
                        Sender   = "4444"
                    });
                }
            }
        }
예제 #2
0
        public GrappedRecharge GetSingle(int id)
        {
            var masterDataTable = DB.GetDataTable("Select * from COLLECTION t WHERE cl_id=" + id, null);

            if (masterDataTable == null)
            {
                return(null);
            }
            if (masterDataTable.Rows.Count == 0)
            {
                return(null);
            }

            DataRow row = masterDataTable.Rows[0];
            var     obj = new GrappedRecharge();

            obj.Id                 = row["row_id"] == DBNull.Value ? -1 : int.Parse(row["row_id"].ToString());
            obj.SubscriberNo       = row["subs_no"] == DBNull.Value ? string.Empty : row["subs_no"].ToString();
            obj.MasterId           = row["cl_id"] == DBNull.Value ? int.MinValue : int.Parse(row["cl_id"].ToString());
            obj.Amount             = row["amount"] == DBNull.Value ? 0 : double.Parse(row["amount"].ToString());
            obj.PointOfSaleId      = row["pos_id"] == DBNull.Value ? string.Empty : row["pos_id"].ToString();
            obj.PointOfSaleAccount = row["pos_acc"] == DBNull.Value ? 0 : int.Parse(row["pos_acc"].ToString());
            obj.AccessChannelId    = row["access_channel"] == DBNull.Value ? string.Empty : row["access_channel"].ToString();
            obj.Status             = row["status"] == DBNull.Value ? 0 : int.Parse(row["status"].ToString());
            obj.StatusTime         = row["status_time"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["status_time"].ToString());
            obj.QueueNo            = row["queue_no"] == DBNull.Value ? 0 : int.Parse(row["queue_no"].ToString());
            obj.RefNo              = row["ref_no"] == DBNull.Value ? string.Empty : row["ref_no"].ToString();
            obj.RefMessage         = row["ref_message"] == DBNull.Value ? string.Empty : row["ref_message"].ToString();
            obj.RefTransNo         = row["ref_trans_no"] == DBNull.Value ? string.Empty : row["ref_trans_no"].ToString();
            obj.RefTime            = row["ref_time"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["ref_time"].ToString());
            obj.DebugInfo          = row["debug_info"] == DBNull.Value ? string.Empty : row["debug_info"].ToString();

            return(obj);
        }
예제 #3
0
        public Queue <GrappedRecharge> GetPendingRechargeQueue(int queueNo, int count = 100)
        {
            var masterDataTable = DB.GetDataTable("Select * from v_pending_recharge_req t WHERE queue_no=" + queueNo + "  AND ROWNUM < " + count + " order by dcreatedon", null);

            if (masterDataTable == null)
            {
                return(null);
            }
            if (masterDataTable.Rows.Count == 0)
            {
                return(null);
            }

            var results = new Queue <GrappedRecharge>();

            foreach (DataRow row in masterDataTable.Rows)
            {
                var obj = new GrappedRecharge();
                obj.Id                 = row["row_id"] == DBNull.Value ? -1 : int.Parse(row["row_id"].ToString());
                obj.SubscriberNo       = row["subs_no"] == DBNull.Value ? string.Empty : row["subs_no"].ToString();
                obj.MasterId           = row["cl_id"] == DBNull.Value ? int.MinValue : int.Parse(row["cl_id"].ToString());
                obj.Amount             = row["amount"] == DBNull.Value ? 0 : double.Parse(row["amount"].ToString());
                obj.PointOfSaleId      = row["pos_id"] == DBNull.Value ? string.Empty : row["pos_id"].ToString();
                obj.PointOfSaleAccount = row["pos_acc"] == DBNull.Value ? 0 : int.Parse(row["pos_acc"].ToString());
                obj.AccessChannelId    = row["access_channel"] == DBNull.Value ? string.Empty : row["access_channel"].ToString();
                obj.Status             = row["status"] == DBNull.Value ? 0 : int.Parse(row["status"].ToString());
                obj.StatusTime         = row["status_time"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["status_time"].ToString());
                obj.QueueNo            = row["queue_no"] == DBNull.Value ? 0 : int.Parse(row["queue_no"].ToString());
                obj.RefNo              = row["ref_no"] == DBNull.Value ? string.Empty : row["ref_no"].ToString();
                obj.RefMessage         = row["ref_message"] == DBNull.Value ? string.Empty : row["ref_message"].ToString();
                obj.RefTransNo         = row["ref_trans_no"] == DBNull.Value ? string.Empty : row["ref_trans_no"].ToString();
                obj.RefTime            = row["ref_time"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["ref_time"].ToString());
                obj.DebugInfo          = row["debug_info"] == DBNull.Value ? string.Empty : row["debug_info"].ToString();
                results.Enqueue(obj);
            }
            return(results);
        }
예제 #4
0
        public RechargeResponseDto DoRecharge(GrappedRecharge recharge)
        {
            //Thread.Sleep(2000);
            #region Local test
            var    result       = new RechargeResponseDto();
            var    watch        = System.Diagnostics.Stopwatch.StartNew();
            double elapsedMs    = watch.ElapsedMilliseconds;
            var    removeResult = new RechargeRepo().RemoveRechargeDraft(recharge.Id);
            if (removeResult)
            {
                var    paymentValue = new PaymentValuesRepo().GetSingleOrDefault(recharge.Amount);
                double profileId    = 0;
                if (paymentValue != null)
                {
                    profileId = paymentValue.ProfileId;
                }

                //result.ResultCode = SharedParams.SuccessPaymentCode;
                //result.ResultDesc = "success";
                //System.Threading.Thread.Sleep(1000);
                #region Call OSC recharge service

                //Start Send Request------------------------------ -
                using (var payService = new RechargePrcFWFW.bank.CBSInterfaceAccountMgrService())
                {
                    payService.Url = SharedParams.OCSEndpoint;
                    RechargePrcFWFW.bank.PaymentRequestMsg msg       = new RechargePrcFWFW.bank.PaymentRequestMsg();
                    RechargePrcFWFW.bank.RequestHeader     reqheader = new RechargePrcFWFW.bank.RequestHeader();

                    reqheader.SessionEntity          = new RechargePrcFWFW.bank.SessionEntityType();
                    reqheader.SessionEntity.Name     = SharedParams.OCSApiUser;
                    reqheader.SessionEntity.Password = SharedParams.OCSApiPassword;
                    reqheader.TransactionId          = $"VTU{recharge.MasterId}";
                    reqheader.SequenceId             = "1";
                    reqheader.CommandId   = "Payment";
                    reqheader.Version     = "1";
                    reqheader.SerialNo    = $"VTU{recharge.MasterId}";
                    reqheader.RequestType = RechargePrcFWFW.bank.RequestHeaderRequestType.Event;
                    reqheader.SessionEntity.RemoteAddress = SharedParams.PaymentRemoteAddress;
                    msg.RequestHeader  = reqheader;
                    msg.PaymentRequest = new RechargePrcFWFW.bank.PaymentRequest();
                    msg.PaymentRequest.SubscriberNo    = recharge.SubscriberNo;
                    msg.PaymentRequest.PaymentAmt      = Convert.ToInt64(recharge.Amount) * 100;
                    msg.PaymentRequest.PaymentMode     = "1000";
                    msg.PaymentRequest.TransactionCode = $"VTU{recharge.MasterId}";
                    msg.PaymentRequest.RefillProfileID = profileId.ToString();

                    try
                    {
                        var requestResult = payService.Payment(msg);

                        if (requestResult != null)
                        {
                            result.ResultCode = requestResult.ResultHeader.ResultCode;
                            result.ResultDesc = requestResult.ResultHeader.ResultDesc;
                            result.TransNo    = requestResult.PaymentResult.InternalSerialNo;
                        }
                        else
                        {
                            result.ResultCode = "-1001";
                            result.ResultDesc = "OCS return null";
                        }
                    }
                    catch (Exception ex)
                    {
                        result.ResultCode = "-1000";
                        result.ResultDesc = ex.GetType().Name + "-" + ex.Message;
                    }
                }

                #endregion

                //}
                // End Send Request -------------------------------
                watch.Stop();

                var collection = new RechargeCollection();
                collection.Id         = recharge.MasterId;
                collection.Status     = result.ResultCode == SharedParams.SuccessPaymentCode ? 1 : 2;
                collection.RefNo      = result.ResultCode.ToString();
                collection.RefMessage = result.ResultDesc;
                collection.RefTransNo = result.TransNo;
                collection.RefTime    = DateTime.Now;
                collection.DebugInfo  = result.ResultDesc + " OCS(" + elapsedMs + ")";
                resultDisplayMsg      = collection.DebugInfo;
                elapsedMs             = 0;
                watch = System.Diagnostics.Stopwatch.StartNew();
                var dbResult = new RechargeRepo().UpdateWithBalance(collection);
                if (collection.Status == 1)
                {
                    new Notifications().SendRecharge("Recharge.Create", recharge);
                }
                else
                {
                    var POSBalance = new RechargeRepo().GetBalance(recharge.PointOfSaleAccount);
                    var sendResult = new SMSOutRepo().Create(
                        new Entities.SMSOut()
                    {
                        Message  = $"فشلت عملية شحن رصيد للرقم {recharge.SubscriberNo} بمبلغ {recharge.Amount.ToString("N2")} ر.ي رصيدك {POSBalance.ToString("N2")}",
                        Receiver = recharge.PointOfSaleId,
                        Sender   = "4444"
                    });
                }
                watch.Stop();
                elapsedMs         = watch.ElapsedMilliseconds;
                resultDisplayMsg += " DB(" + elapsedMs + ")";
                return(result);

                #endregion
            }
            else
            {
                return(new RechargeResponseDto()
                {
                    Duration = Convert.ToInt16(Math.Truncate(elapsedMs)),
                    ResultCode = "-10000",
                    ResultDesc = "Could not remove draft"
                });
            }
        }