Пример #1
0
            public HttpResponseMessage InputCard(PayloadApi p)
            {
                LogClass.SaveCustomerLog("InputCard: " + JsonConvert.SerializeObject(p));
                ResultApi  result     = new ResultApi();
                CardObject cardObject = new CardObject();

                try
                {
                    var publisherInfo = publisher.CheckPublickey(p, version);
                    if (publisherInfo.status == (int)ERROR_CODDE.SUCCESS)
                    {
                        ManagerModel managerModel = new ManagerModel();
                        var          data         = JsonConvert.DeserializeObject <InputCard>(publisherInfo.data.ToString());
                        string       msg          = "";

                        if (data.CardType != 1 && data.CardType != 2 && data.CardType != 3)
                        {
                            result.msg = "CardType sai định dạng";
                            return(null);
                        }

                        int   successtransaction = 0;
                        int   errortransaction   = 0;
                        int   errorsavelog       = 0;
                        short debug = 0;
                        try
                        {
                            string serviceCode = string.Empty;

                            if (data.CardType == 1)
                            {
                                serviceCode = "VTT";
                            }
                            else if (data.CardType == 2)
                            {
                                serviceCode = "VMS";
                            }
                            else if (data.CardType == 3)
                            {
                                serviceCode = "VNP";
                            }
                            debug = 1;
                            for (int i = 0; i < data.Qty; i++)
                            {
                                debug = 2;
                                long transactionId = DateTime.Now.Ticks;

                                var    service = new muathe24h.MechantServicesSoapClient();
                                string email   = "*****@*****.**";
                                string pass    = "******";

                                var res = service.BuyCards(new muathe24h.UserCredentials {
                                    userName = email, pass = pass
                                }
                                                           , transactionId.ToString(), serviceCode, data.Amount, 1);
                                debug = 3;
                                LogClass.SaveLog("muathe24h" + JsonConvert.SerializeObject(res));
                                string resultCode = res?.RepCode.ToString();
                                debug = 4;
                                //Khoi tao ket qua ghi log mac dinh

                                cardObject.Amount     = data.Amount;
                                cardObject.Experied   = string.Empty;
                                cardObject.CardType   = data.CardType;
                                cardObject.TelCode    = serviceCode;
                                cardObject.TradeMark  = "muathe24h";
                                cardObject.BuyTime    = DateTime.Now;
                                cardObject.ResultCode = resultCode;

                                debug = 5;
                                if (res != null && res.RepCode == 0)
                                {
                                    successtransaction++;
                                    var seri = JsonConvert.DeserializeObject <List <CardObject_Muathe24h> >(res.Data.ToString());
                                    //Mua thanh cong ghi lai code va seri the
                                    cardObject.CardCode        = seri[0].PinCode;
                                    cardObject.CardSerial      = seri[0].Serial;
                                    cardObject.TransactionCode = transactionId.ToString();
                                    cardObject.Status          = true; //Mua thanh cong
                                    LogClass.SaveLog("cardObject buy success:" + JsonConvert.SerializeObject(cardObject));
                                    result.status = managerModel.GameAcountModel.INPUT_CARD(cardObject, ref msg);
                                    if (result.status != 1)
                                    {
                                        debug = 3;
                                        errorsavelog++;
                                        cardObject.CardCode        = string.Empty;
                                        cardObject.CardSerial      = string.Empty;
                                        cardObject.TransactionCode = string.Empty;
                                        cardObject.Status          = false; // Mua that bai
                                        LogClass.SaveLog("cardObject savelog error:" + JsonConvert.SerializeObject(cardObject));
                                        managerModel.GameAcountModel.INPUT_CARD(cardObject, ref msg);
                                    }
                                }
                                else //Mua the that bai
                                {
                                    debug = 4;
                                    errortransaction++;
                                    cardObject.CardCode        = string.Empty;
                                    cardObject.CardSerial      = string.Empty;
                                    cardObject.TransactionCode = string.Empty;
                                    cardObject.Status          = false; // Mua that bai
                                    LogClass.SaveLog("cardObject buy card error:" + JsonConvert.SerializeObject(cardObject));
                                    managerModel.GameAcountModel.INPUT_CARD(cardObject, ref msg);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogClass.SaveError("Mua thẻ thất bại" + ex + "\n,cardObject:" + JsonConvert.SerializeObject(cardObject));
                        }
                        string msgTotalBuyCard = "Mua thành công " + successtransaction + " thẻ";
                        if (errortransaction > 0)
                        {
                            msgTotalBuyCard += " và thất bại " + errortransaction + " thẻ";
                        }
                        if (errorsavelog > 0)
                        {
                            msgTotalBuyCard += ". Ghi log thất bại " + errorsavelog + " thẻ";
                        }

                        result.msg = msgTotalBuyCard;
                    }
                    else
                    {
                        result = publisherInfo;
                    }
                }
                catch (Exception ex)
                {
                    LogClass.SaveError("ERROR InputCard: " + ex.Message + "\n,cardObject:" + JsonConvert.SerializeObject(cardObject), ex, true);
                    result.status = (int)ERROR_CODDE.ERROR_EX;
                    result.msg    = ex.Message;
                }
                return(Request.CreateResponse(result));
            }
        public dynamic Charge(int cardType, int amount, int total)
        {
            try
            {
                if (cardType != 1 && cardType != 2 && cardType != 3)
                {
                    return(null);
                }

                int successtransaction = 0;
                int errortransaction   = 0;

                try
                {
                    string serviceCode = string.Empty;

                    if (cardType == 1)
                    {
                        serviceCode = "VTT";
                    }
                    else if (cardType == 2)
                    {
                        serviceCode = "VMS";
                    }
                    else if (cardType == 3)
                    {
                        serviceCode = "VNP";
                    }

                    for (int i = 0; i < total; i++)
                    {
                        long transactionId = DateTime.Now.Ticks;

                        int    outRes    = 0;
                        string requestId = string.Empty;

                        var    service = new muathe24h.MechantServicesSoapClient();
                        string email   = "*****@*****.**";
                        string pass    = "******";

                        var res = service.BuyCards(new muathe24h.UserCredentials {
                            userName = email, pass = pass
                        }
                                                   , transactionId.ToString(), serviceCode, amount, 1);

                        NLogManager.LogMessage(JsonConvert.SerializeObject(res));
                        string resultCode = res?.RepCode.ToString();


                        if (res != null && res.RepCode == 0)
                        {
                            var seri = JsonConvert.DeserializeObject <List <CardObject> >(res.Data.ToString());
                            if (PayDAO.InsertCard(seri[0].PinCode, seri[0].Serial, amount, string.Empty, cardType, serviceCode, "muathe24h", DateTime.Now, transactionId.ToString(), resultCode, true))
                            {
                                successtransaction++;
                            }
                            else
                            {
                                PayDAO.InsertCard(string.Empty, string.Empty, amount, string.Empty, cardType, serviceCode, "muathe24h", DateTime.Now, requestId, resultCode, false);
                                errortransaction++;
                            }
                        }
                        else
                        {
                            PayDAO.InsertCard(string.Empty, string.Empty, amount, string.Empty, cardType, serviceCode, "muathe24h", DateTime.Now, requestId, resultCode, false);

                            errortransaction++;
                        }
                    }

                    return(new
                    {
                        suc = successtransaction,
                        err = errortransaction
                    });
                }
                catch (Exception ex)
                {
                    NLogManager.PublishException(ex);
                }
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }
            return(null);
        }