Esempio n. 1
0
        public string QueryStartimeBalance(dynamic payObjx)
        {
            try
            {
                Paytv.CustomerObj PayObj = new Paytv.CustomerObj();
                //dynamic payObjx = new JObject();
                PayObj.CustomerID = payObjx.smartCardCode;
                PayObj.Amount     = payObjx.Amount;
                PayObj.Phone      = payObjx.Phone;

                string transactionID = payObjx.transactionlNo;
                //string transactionID = "movingtotestEnvironment";
                //PayObj.Service = payObjx.transactionlNo;
                PayObj.Service = transactionID;
                // UpdateCustomerTransaction(payObject);
                Paytv _paytv = new Paytv();
                //Customer Validation
                if (string.IsNullOrEmpty(PayObj.CustomerID))
                {
                    soapResult =
                        new JObject(
                            new JProperty("status", "error"),
                            new JProperty("message", "Empty CustomerID"),
                            new JProperty("data", new JObject())).ToString();
                    return(soapResult.ToString());
                }
                dynamic AgentObj = new JObject();
                // var req = Request;
                // var headers = req.Headers;
                // string myAgentID = "";
                // try
                // {
                //     myAgentID = headers.GetValues("agentID").First() ?? "";
                // }
                // catch
                // {
                //     WebLog.Log("Cannot Read AgentID as header");
                // }

                // var agentID = headers.GetValues("agentID").First() ?? "";
                // var agentKey = headers.GetValues("agentKey").First() ?? "";
                // var signature = headers.GetValues("signature").First() ?? "";

                // AgentObj.AgentID = agentID;
                // AgentObj.AgentKey = agentKey;
                // AgentObj.Signature = signature;
                // var Authenticated = IsTransactionAutheticated(AgentObj);

                // if (Authenticated == false)
                // {
                //     soapResult =
                //      new JObject(
                //          new JProperty("status", "Error"),
                //          new JProperty("message", "Authentication Failed"),
                //          new JProperty("data", new JObject())).ToString();
                //     // return Json(soapResult);
                //     return soapResult.ToString();
                // }
                // payObjx.agentID = agentID;
                //// payObjx.Phone = Phone;
                payObjx.PayResCode = payObjx.returnCode;
                soapResult         = _paytv.GetBalance(PayObj);

                XmlDocument xd = new XmlDocument();
                xd.LoadXml(soapResult);
                XmlTextReader reader  = default(XmlTextReader);
                XmlReader     xReader = XmlReader.Create(new StringReader(soapResult));
                using (StringReader stringReader = new StringReader(soapResult))
                {
                    reader = new XmlTextReader(stringReader);
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:

                            if ((reader.Name == "returnCode"))
                            {
                                returnCode         = reader.ReadElementString();
                                payObjx.returnCode = returnCode;
                            }


                            if ((reader.Name == "returnMsg"))
                            {
                                returnMsg         = reader.ReadElementString();
                                payObjx.returnMsg = returnMsg;
                            }
                            if ((reader.Name == "balance"))
                            {
                                returnMsg      = reader.ReadElementString();
                                payObjx.Amount = returnMsg;
                            }
                            if ((reader.Name == "customerName"))
                            {
                                returnMsg = reader.ReadElementString();
                                var Name = returnMsg;
                                payObjx.CustomerName = Name;
                            }
                            if ((reader.Name == "smartCardCode"))
                            {
                                returnMsg = reader.ReadElementString();
                                var Name = returnMsg;
                                payObjx.smartCardCode = Name;
                            }
                            if ((reader.Name == "TELDealID"))
                            {
                                var tranNum = reader.ReadElementString();
                                payObjx.tranNum = tranNum;
                                //payObjx.Phone = Phone;
                                //var json = new JavaScriptSerializer().Serialize(payObjx);

                                // soapResult = json;
                                string json = Newtonsoft.Json.JsonConvert.SerializeObject(payObjx);
                                soapResult = json;
                            }
                            break;

                        case XmlNodeType.Text:

                            break;

                        case XmlNodeType.EndElement:

                            break;
                        }
                    }
                }

                insertTransactionLog(payObjx);

                return(soapResult.ToString());
            }
            catch (Exception ex)
            {
                WebLog.Log(ex);
                var obj =
                    new JObject(
                        new JProperty("status", "error"),
                        new JProperty("message", $"{ex.Message}"),
                        new JProperty("data", new JObject()));

                return(obj.ToString());
            }
        }
Esempio n. 2
0
        public string BuyStartimeRequest(string CustomerID, string Amount, string Phone, string Bouqet)
        {
            try
            {
                Paytv.CustomerObj PayObj  = new Paytv.CustomerObj();
                dynamic           payObjx = new JObject();
                PayObj.CustomerID = CustomerID;
                PayObj.Amount     = Amount;
                PayObj.Phone      = Phone;
                PayObj.Bouquet    = Bouqet;
                // UpdateCustomerTransaction(payObject);
                Paytv _paytv = new Paytv();
                //Customer Validation
                if (string.IsNullOrEmpty(CustomerID))
                {
                    soapResult =
                        new JObject(
                            new JProperty("status", "error"),
                            new JProperty("message", "Empty CustomerID"),
                            new JProperty("data", new JObject())).ToString();
                    return(soapResult.ToString());
                }
                dynamic AgentObj  = new JObject();
                var     req       = Request;
                var     headers   = req.Headers;
                string  myAgentID = "";
                try
                {
                    myAgentID = headers.GetValues("agentID").First() ?? "";
                }
                catch
                {
                    WebLog.Log("Cannot Read AgentID as header");
                }

                var agentID   = headers.GetValues("agentID").First() ?? "";
                var agentKey  = headers.GetValues("agentKey").First() ?? "";
                var signature = headers.GetValues("signature").First() ?? "";

                AgentObj.AgentID   = agentID;
                AgentObj.AgentKey  = agentKey;
                AgentObj.Signature = signature;
                var Authenticated = IsTransactionAutheticated(AgentObj);

                if (Authenticated == false)
                {
                    soapResult =
                        new JObject(
                            new JProperty("status", "Error"),
                            new JProperty("message", "Authentication Failed"),
                            new JProperty("data", new JObject())).ToString();
                    // return Json(soapResult);
                    return(soapResult.ToString());
                }
                payObjx.agentID       = agentID;
                payObjx.Phone         = Phone;
                payObjx.smartCardCode = CustomerID;
                payObjx.Amount        = PayObj.Amount;
                payObjx.PayResCode    = payObjx.returnCode;
                payObjx.Bouqet        = PayObj.Bouquet;
                soapResult            = _paytv.PaySubscription(PayObj, Phone);

                XmlDocument xd = new XmlDocument();
                xd.LoadXml(soapResult);
                XmlTextReader reader  = default(XmlTextReader);
                XmlReader     xReader = XmlReader.Create(new StringReader(soapResult));
                using (StringReader stringReader = new StringReader(soapResult))
                {
                    reader = new XmlTextReader(stringReader);
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:

                            if ((reader.Name == "returnCode"))
                            {
                                returnCode         = reader.ReadElementString();
                                payObjx.returnCode = returnCode;
                            }

                            if ((reader.Name == "returnMsg"))
                            {
                                returnMsg         = reader.ReadElementString();
                                payObjx.returnMsg = returnMsg;
                            }
                            if ((reader.Name == "Phone"))
                            {
                                returnMsg     = reader.ReadElementString();
                                payObjx.Phone = returnMsg;
                            }

                            if ((reader.Name == "transactionNo"))
                            {
                                var tranNum = reader.ReadElementString();
                                //payObjx.tranNum = tranNum;
                                payObjx.transactionlNo = tranNum;
                                //payObjx.Phone = Phone;
                                //var json = new JavaScriptSerializer().Serialize(payObjx);

                                // soapResult = json;
                                string json = Newtonsoft.Json.JsonConvert.SerializeObject(payObjx);
                                soapResult = json;
                            }
                            break;

                        case XmlNodeType.Text:

                            break;

                        case XmlNodeType.EndElement:

                            break;
                        }
                    }
                }

                //insertTransactionLog(payObjx);
                QueryStartimeBalance(payObjx);
                return(soapResult.ToString());
            }
            catch (Exception ex)
            {
                WebLog.Log(ex);
                var obj =
                    new JObject(
                        new JProperty("status", "error"),
                        new JProperty("message", $"{ex.Message}"),
                        new JProperty("data", new JObject()));

                return(obj.ToString());
            }
        }