public async Task <IHttpActionResult> Get()
 {
     try
     {
         var lstData = MemoryInfo.GetAllPayment();
         if (lstData != null)
         {
             lstData = lstData.Where(x => x.IsDeleted != null && x.IsDeleted != 1).ToList();
         }
         List <PaymentRes> lstResult = new List <PaymentRes>();
         foreach (var payment in lstData)
         {
             if (payment.IsDeleted != 1)
             {
                 var lstPaymentFees = MemoryInfo.GetListPaymentFeeByField(payment.Id.ToString(),
                                                                          PaymentFee.PaymentFeeFields.IdPayment);
                 PaymentRes itemRes = new PaymentRes(payment, lstPaymentFees);
                 lstResult.Add(itemRes);
             }
         }
         var res = new RequestErrorCode(true, null, null);
         res.ListDataResult.AddRange(lstResult);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
 public async Task <IHttpActionResult> Get(int id)
 {
     try
     {
         var data = MemoryInfo.GetPayment(id);
         var res  = new RequestErrorCode(true, null, null);
         if (data != null && data.IsDeleted == 1 || data == null)
         {
             res.DataResult = null;
             return(Ok(res));
         }
         var lstPaymentFees = MemoryInfo.GetListPaymentFeeByField(data.Id.ToString(),
                                                                  PaymentFee.PaymentFeeFields.IdPayment);
         PaymentRes itemRes = new PaymentRes(data, lstPaymentFees);
         res.DataResult = itemRes;
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
Esempio n. 3
0
        public int saveTransaction(PaymentReq value, PaymentRes value2)
        {
            using (var conn = new OracleConnection(Database.conString))
            {
                try
                {
                    conn.Open();
                    var createDate = DateTime.ParseExact(value2.CreatedDate, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                    var expireDate = DateTime.ParseExact(value2.ExpiredDate, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                    using (var cmd = new OracleCommand(SqlCmd.Payment.saveTransaction, conn)
                    {
                        CommandType = CommandType.Text
                    })
                    {
                        cmd.Parameters.Add("transNo", value2.TransactionId);
                        cmd.Parameters.Add(new OracleParameter("orderNo", Int32.Parse(value2.OrderNo)));
                        cmd.Parameters.Add(new OracleParameter("custNo", Int32.Parse(value2.CustomerId)));
                        cmd.Parameters.Add(new OracleParameter("channelId", value2.ChannelCode));
                        cmd.Parameters.Add(new OracleParameter("reqStatus", value2.Status));
                        cmd.Parameters.Add(new OracleParameter("tranStatus", value2.Code));
                        cmd.Parameters.Add(new OracleParameter("payAmt", value.PayAmt));
                        cmd.Parameters.Add(new OracleParameter("returnUrl", value2.ReturnUrl));
                        cmd.Parameters.Add(new OracleParameter("paymentUrl", value2.PaymentUrl));
                        cmd.Parameters.Add(new OracleParameter("ip", value2.IpAddress));
                        cmd.Parameters.Add(new OracleParameter("token", value2.Token));
                        cmd.Parameters.Add(new OracleParameter("createTime", createDate));
                        cmd.Parameters.Add(new OracleParameter("expireTime", expireDate));
                        cmd.Parameters.Add(new OracleParameter("transAmt", value2.Amount));
                        cmd.Parameters.Add(new OracleParameter
                        {
                            ParameterName = "trans_no",
                            OracleDbType  = OracleDbType.Int32,
                            Direction     = ParameterDirection.Output
                        });
                        cmd.ExecuteNonQuery();
                        var lastInsert = Int32.Parse(cmd.Parameters["trans_no"].Value.ToString());
                        cmd.Dispose();
                        return(lastInsert);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(0);
                }
                finally
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
            //try
            //{
            //    oracle = new Database();
            //    var createDate = DateTime.ParseExact(value2.CreatedDate, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
            //    var expireDate = DateTime.ParseExact(value2.ExpiredDate, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
            //    //string cmd = $@"INSERT INTO MPAY110(TRANS_NO, ORDER_NO, CUST_NO, CHANNEL_ID, REQ_STATUS_ID, TRANS_STATUS_ID, PAY_AMT, RETURN_URL, PAYMENT_URL, IP_ADDR, TOKEN, CREATED_TIME, EXPIRE_TIME)
            //    //                VALUES(:transNo, :orderNo, :custNo, :channelId, :reqStatus, :tranStatus, :amount, :returnUrl, :paymentUrl, :ip, :token, :createTime, :expireTime) RETURNING TRANS_NO INTO :trans_no";
            //    List<OracleParameter> parameter = new List<OracleParameter>();
            //    parameter.Add(new OracleParameter("transNo", value2.TransactionId));
            //    parameter.Add(new OracleParameter("orderNo", Int32.Parse(value2.OrderNo)));
            //    parameter.Add(new OracleParameter("custNo", Int32.Parse(value2.CustomerId)));
            //    parameter.Add(new OracleParameter("channelId", value2.ChannelCode));
            //    parameter.Add(new OracleParameter("reqStatus", value2.Status));
            //    parameter.Add(new OracleParameter("tranStatus", value2.Code));
            //    parameter.Add(new OracleParameter("payAmt", value.PayAmt));
            //    parameter.Add(new OracleParameter("returnUrl", value2.ReturnUrl));
            //    parameter.Add(new OracleParameter("paymentUrl", value2.PaymentUrl));
            //    parameter.Add(new OracleParameter("ip", value2.IpAddress));
            //    parameter.Add(new OracleParameter("token", value2.Token));
            //    parameter.Add(new OracleParameter("createTime", createDate));
            //    parameter.Add(new OracleParameter("expireTime", expireDate));
            //    parameter.Add(new OracleParameter("transAmt", value2.Amount));
            //    parameter.Add(new OracleParameter
            //    {
            //        ParameterName = "trans_no",
            //        OracleDbType = OracleDbType.Int32,
            //        Direction = ParameterDirection.Output
            //    });
            //    var resInsert = oracle.SqlExecuteWithParams(SqlCmd.Payment.saveTransaction, parameter);
            //    //var resInsert = oracle.SqlExecuteWithParams(cmd, parameter);
            //    var lastTransaction = Int32.Parse(resInsert.Parameters["trans_no"].Value.ToString());
            //    //parameter.Clear();
            //    //parameter.Add(new OracleParameter("order_no", value.OrderNo));
            //    //oracle.SqlExecuteWithParams(SqlCmd.Payment.setActiveOrder, parameter);

            //    resInsert.Dispose();
            //    oracle.OracleDisconnect();
            //    return lastTransaction;
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //    return 0;
            //}
        }
        public IHttpActionResult PostNewPayment2([FromBody] PaymentReq value)
        {
            var setting        = (AppSettingsSection)WebConfigurationManager.OpenWebConfiguration("~").GetSection("appSettings");
            var appService     = setting.Settings["AppService"].Value;
            var paymentService = setting.Settings["PaymentService"].Value;

            if (appService == "False" || paymentService == "False")
            {
                return(Unauthorized());
            }
            value.IPAddress = HttpContext.Current.Request.UserHostAddress;
            string clientHostname = HttpContext.Current.Request.UserHostName;
            string url            = HttpContext.Current.Request.Path;

            try
            {
                //value.OrderNo = "test001";
                value.Description = "testAPI";
                string strAmt = value.Amount.ToString();
                strAmt       = strAmt.Insert(strAmt.Length - 2, ".");
                value.PayAmt = double.Parse(strAmt);
                mlog         = new m_LogReq();
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid parameter!"));
                }

                user = new User();
                var cust = user.getProfileById(value.CustomerId);
                if (cust != null)
                {
                    var contract = user.findContract(value.CustomerId, value.ContractNo);
                    if (contract != null)
                    {
                        if (value.PayAmt <= (contract.BAL_AMT - contract.DISC_AMT))
                        {
                            Payment    payment = new Payment();
                            PaymentRes res     = payment.createPayment(value);
                            if (res == null)
                            {
                                //mlogOrder = new m_LogOrder();
                                //mlogOrder.cust_no = value.CustomerId;
                                //mlogOrder.con_no = value.ContractNo;
                                //mlogOrder.channel_id = value.ChannelCode;
                                //mlogOrder.pay_amt = value.PayAmt;
                                //mlogOrder.trans_amt = value.Amount;
                                //mlogOrder.device_id = value.DeviceId;
                                //mlogOrder.tel = value.PhoneNumber;
                                //mlogOrder.note = "ระบบขัดข้อง ไม่สามารถทำรายการได้";
                                //mlogOrder.ip_addr = value.IPAddress;
                                //log.logOrder(mlogOrder);



                                monitor.sendMessage(url, clientHostname, value, new { request_status = "FAILURE", desc = "Internal server error / Invalid parameter!", data = res });
                                return(Ok(new { code = 500, message = "ระบบขัดข้อง ไม่สามารถทำรายการได้", data = res }));
                            }
                            else
                            {
                                monitor.sendMessage(url, clientHostname, value, new { request_status = "SUCCESS", desc = "Requested to Payment Gateway", data = res });
                                return(Ok(new { code = 200, message = "สร้างรายการชำระเงินสำเร็จ", data = res }));
                            }
                        }
                        else
                        {
                            mlogOrder            = new m_LogOrder();
                            mlogOrder.cust_no    = value.CustomerId;
                            mlogOrder.con_no     = value.ContractNo;
                            mlogOrder.channel_id = value.ChannelCode;
                            mlogOrder.pay_amt    = value.PayAmt;
                            mlogOrder.trans_amt  = value.Amount;
                            mlogOrder.device_id  = value.DeviceId;
                            mlogOrder.tel        = value.PhoneNumber;
                            mlogOrder.note       = "จำนวนเงินที่ต้องการชำระมากกว่ายอดคงเหลือหลังจากที่หักส่วนลดแล้ว";
                            mlogOrder.ip_addr    = value.IPAddress;
                            log.logOrder(mlogOrder);
                            //mlog.cust_no = value.CustomerId;
                            //mlog.device_id = value.DeviceId;
                            //mlog.ip_addr = value.IPAddress;
                            //mlog.note = "จำนวนเงินที่ต้องการชำระมากกว่ายอดคงเหลือหลังจากที่หักส่วนลดแล้ว";
                            //mlog.url = "api/authen/newpayment2";
                            //log.logRequest(mlog);
                            monitor.sendMessage(url, clientHostname, value, new { request_status = "FAILURE", desc = "จำนวนเงินที่ต้องการชำระมากกว่ายอดคงเหลือหลังจากที่หักส่วนลดแล้ว", data = string.Empty });
                            return(Ok(new { code = 400, message = "จำนวนเงินที่ต้องการชำระมากกว่ายอดคงเหลือหลังจากที่หักส่วนลดแล้ว", data = contract }));
                        }
                    }
                    else
                    {
                        mlogOrder            = new m_LogOrder();
                        mlogOrder.cust_no    = value.CustomerId;
                        mlogOrder.con_no     = value.ContractNo;
                        mlogOrder.channel_id = value.ChannelCode;
                        mlogOrder.pay_amt    = value.PayAmt;
                        mlogOrder.trans_amt  = value.Amount;
                        mlogOrder.device_id  = value.DeviceId;
                        mlogOrder.tel        = value.PhoneNumber;
                        mlogOrder.note       = "ไม่พบสัญญาของลูกค้า";
                        mlogOrder.ip_addr    = value.IPAddress;
                        log.logOrder(mlogOrder);
                        //mlog.cust_no = value.CustomerId;
                        //mlog.device_id = value.DeviceId;
                        //mlog.ip_addr = value.IPAddress;
                        //mlog.note = "ไม่พบสัญญาของลูกค้า";
                        //mlog.url = "api/authen/newpayment2";
                        //log.logRequest(mlog);
                        monitor.sendMessage(url, clientHostname, value, new { request_status = "FAILURE", desc = "Not found contract!", data = contract });
                        return(Ok(new { code = 400, message = "ไม่พบข้อมูลสัญญาในระบบ", data = contract }));
                    }
                }
                else
                {
                    mlogOrder            = new m_LogOrder();
                    mlogOrder.cust_no    = value.CustomerId;
                    mlogOrder.con_no     = value.ContractNo;
                    mlogOrder.channel_id = value.ChannelCode;
                    mlogOrder.pay_amt    = value.PayAmt;
                    mlogOrder.trans_amt  = value.Amount;
                    mlogOrder.device_id  = value.DeviceId;
                    mlogOrder.tel        = value.PhoneNumber;
                    mlogOrder.note       = "ไม่พบข้อมูลลูกค้าในระบบ";
                    mlogOrder.ip_addr    = value.IPAddress;
                    log.logOrder(mlogOrder);
                    //mlog.cust_no = value.CustomerId;
                    //mlog.device_id = value.DeviceId;
                    //mlog.ip_addr = value.IPAddress;
                    //mlog.note = "ไม่พบข้อมูลลูกค้า";
                    //mlog.url = "api/authen/newpayment2";
                    //log.logRequest(mlog);
                    monitor.sendMessage(url, clientHostname, value, new { request_status = "FAILURE", desc = "Not found customer!", data = cust });
                    return(Ok(new { code = 400, message = "ไม่พบข้อมูลลูกค้าในระบบ", data = cust }));
                }
            }
            catch (Exception e)
            {
                mlog           = new m_LogReq();
                mlog.cust_no   = value.CustomerId;
                mlog.device_id = value.DeviceId;
                mlog.ip_addr   = value.IPAddress;
                mlog.note      = e.Message;
                mlog.url       = "api/authen/newpayment2";
                log.logRequest(mlog);
                monitor.sendMessage(url, clientHostname, value, new { request_status = "FAILURE", Message = e.Message });
                return(Ok(new { code = 500, message = e.Message, data = string.Empty }));
            }
        }