Ejemplo n.º 1
0
        public static async Task <PaymentTopupResponse> Topup(string cardSerial, string cardCode, string cardType, int cardAmount, string accountName, string transactionId)
        {
            cardObj ca = new cardObj();

            ca.Serial     = cardSerial;
            ca.Code       = cardCode;
            ca.Key        = cardType;
            ca.Request_id = transactionId;
            ca.Key        = cardType;
            ca.Amount     = cardAmount;

            var response = await new processCard().PostCardToService(ca);

            if (response.Status == 0 && response.Amount > 0)
            {
                return(new PaymentTopupResponse
                {
                    Amount = response.Amount,
                    ErrorCode = 1
                });
            }

            if (response.Status > 0)
            {
                response.Status *= -1;
            }

            return(new PaymentTopupResponse
            {
                ErrorCode = response.Status,
                Message = "Thẻ sai định dạng hoặc thẻ đã được sử dụng"
            });
        }
Ejemplo n.º 2
0
        public static string detectData(cardObj ca, string type)
        {
            string data = "";

            if (type == "get")
            {
                data = "PartnerID=" + ca.PartnerID + "&PartnerKey=" + ca.PartnerKey;
            }
            else if (type == "post")
            {
                data = "key=" + ca.Key + "&Code=" + ca.Code + "&serial=" + ca.Serial + "&request_id=" + ca.Request_id + "&PartnerID=" + ca.PartnerID + "&PartnerKey=" + ca.PartnerKey + "&checksum=" + ca.Checksum;
            }
            return(data);
        }
Ejemplo n.º 3
0
        public cardObj GetListCardFromService(cardObj ca)
        {
            ASCIIEncoding enCoding = new ASCIIEncoding();
            string        postdata = detectData(ca, "get");
            string        URL      = "https://timopay.com/card_charging_api/get_card_keys.html";

            byte[] data = enCoding.GetBytes(postdata);

            WebRequest request = WebRequest.Create(URL);

            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            Stream stream = request.GetRequestStream();

            stream.Write(data, 0, data.Length);
            stream.Close();

            WebResponse response = request.GetResponse();

            stream = response.GetResponseStream();

            using (StreamReader responseReader = new StreamReader(stream, Encoding.ASCII))
            {
                string  sdata = responseReader.ReadToEnd();
                string  res   = Base64Decode(sdata);
                dynamic stuff = JsonConvert.DeserializeObject(res);
                cardObj ce    = new cardObj();
                if (stuff.status != null)
                {
                    ce.Status = Convert.ToInt32(stuff.status.ToString());
                }
                if (stuff.message != null)
                {
                    ce.Message = stuff.message;
                }
                return(ce);
            }
        }
Ejemplo n.º 4
0
        public async Task <cardObj> PostCardToService(cardObj ca)
        {
            try
            {
                ca.Checksum = GetMD5(ca.PartnerID + ca.Key + ca.Serial + ca.Request_id);

                using (HttpClient client = new HttpClient())
                {
                    client.Timeout = TimeSpan.FromSeconds(100);
                    var formContent = new FormUrlEncodedContent(new[] {
                        new KeyValuePair <string, string>("key", ca.Key),
                        new KeyValuePair <string, string>("code", ca.Code),
                        new KeyValuePair <string, string>("serial", ca.Serial),
                        new KeyValuePair <string, string>("request_id", ca.Request_id),
                        new KeyValuePair <string, string>("PartnerID", ca.PartnerID),
                        new KeyValuePair <string, string>("PartnerKey", ca.PartnerKey.ToString()),
                        new KeyValuePair <string, string>("checksum", ca.Checksum),
                    });

                    var data = await client.PostAsync("https://timopay.com/card_charging_api.html", formContent);

                    var stringStr = await data.Content.ReadAsStringAsync();

                    string res = Base64Decode(stringStr);
                    NLogManager.LogMessage(JsonConvert.SerializeObject(ca) + "|Response TIMO: " + res);
                    dynamic stuff = JsonConvert.DeserializeObject(res);
                    cardObj ce    = new cardObj();
                    ce.Status = -99;
                    if (stuff.status != null)
                    {
                        ce.Status = Convert.ToInt32(stuff.status.ToString());
                    }
                    if (stuff.message != null)
                    {
                        ce.Message = stuff.message;
                    }
                    if (stuff.amount != null)
                    {
                        ce.Amount = stuff.amount;
                    }
                    if (stuff.key != null)
                    {
                        ce.Key = stuff.key;
                    }
                    if (stuff.serial != null)
                    {
                        ce.Serial = stuff.serial;
                    }
                    if (stuff.code != null)
                    {
                        ce.Code = stuff.code;
                    }
                    if (stuff.request_id != null)
                    {
                        ce.Request_id = stuff.request_id;
                    }
                    if (stuff.transid != null)
                    {
                        ce.Transid = stuff.transid;
                    }
                    return(ce);
                }
            }catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            cardObj ce1 = new cardObj();

            ce1.Status = -99;

            return(ce1);
        }