예제 #1
0
 public static int AddPay(COM.Pay mPay)
 {
     try
     {
         using (var ent = DB.Entity)
         {
             ent.Pays.Add(mPay);
             ent.SaveChanges();
             return(mPay.PayID);
         }
     }
     catch (Exception e)
     {
         Log.DoLog(COM.Action.AddPay, mPay.BuyID, -100, e.Message);
         return(-100);
     }
 }
예제 #2
0
 public static bool UpdatePayAfterConfirm(COM.Pay mPay)
 {
     try
     {
         using (var ent = DB.Entity)
         {
             ent.Pays.Attach(mPay);
             var Entry = ent.Entry(mPay);
             Entry.Property(ex => ex.IsReverse).IsModified  = true;
             Entry.Property(ex => ex.FinalState).IsModified = true;
             ent.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Log.DoLog(COM.Action.UpdatePayAfterConfirm, mPay.BuyID, -100, e.Message);
         return(false);
     }
 }
예제 #3
0
 public static bool UpdatePayAfterDargah(COM.Pay mPay)
 {
     try
     {
         using (var ent = DB.Entity)
         {
             ent.Pays.Attach(mPay);
             var Entry = ent.Entry(mPay);
             Entry.Property(ex => ex.DargahState).IsModified     = true;
             Entry.Property(ex => ex.Token).IsModified           = true;
             Entry.Property(ex => ex.TrackingNumber).IsModified  = true;
             Entry.Property(ex => ex.ReferenceNumber).IsModified = true;
             Entry.Property(ex => ex.EndMoment).IsModified       = true;
             ent.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Log.DoLog(COM.Action.UpdateProduct, mPay.BuyID, -100, e.Message);
         return(false);
     }
 }
예제 #4
0
        public async Task <COM.BuyResult> ReBuy()
        {
            COM.BuyResult buyResult = new COM.BuyResult();
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    buyResult.HasError  = true;
                    buyResult.StateDesc = "Exception dade: UnsupportedMediaType";
                    return(buyResult);
                }


                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                if (filesReadToProvider.Contents[0].Headers.ContentDisposition.Name == "Object" || filesReadToProvider.Contents[0].Headers.ContentDisposition.Name == "\"Object\"")
                {
                    var jsonString = await filesReadToProvider.Contents[0].ReadAsStringAsync();
                    var serializer = new JavaScriptSerializer();
                    COM.MiddleRePayment mMiddleRePayment = serializer.Deserialize <COM.MiddleRePayment>(jsonString);

                    var PreOrder = BLL.Salement.GetOrdersByOID(mMiddleRePayment.OID);
                    if (PreOrder == null)
                    {
                        buyResult.HasError  = true;
                        buyResult.StateDesc = "in Order vojood nadarad";
                        return(buyResult);
                    }

                    if (PreOrder.PayStatus)
                    {
                        buyResult.HasError  = true;
                        buyResult.StateDesc = "in sefaresh ghablan pardakt shode ast";
                        return(buyResult);
                    }

                    List <COM.ProductInfo> ListProductInfo = serializer.Deserialize <List <COM.ProductInfo> >(PreOrder.ProductsInfo);


                    double SumPrice = 0;
                    foreach (var itemPro in ListProductInfo)
                    {
                        var pr = BLL.Product.GetProductByID(itemPro.PID);
                        if (pr == null)
                        {
                            buyResult.HasError  = true;
                            buyResult.StateDesc = "product nistesh";
                            return(buyResult);
                        }
                        SumPrice = SumPrice + (pr.PriceOff * itemPro.Count);
                    }

                    var ghestInfo = BLL.Product.GetGhestInfo();

                    if (PreOrder.GhestNumber > ghestInfo.MaxGhestNumber || PreOrder.GhestNumber < ghestInfo.MinGhestNumber)
                    {
                        buyResult.HasError  = true;
                        buyResult.StateDesc = "tedade ghest mojaz nemibashad";
                        return(buyResult);
                    }

                    double MablagheGhabelePardakht = 0;
                    double MablaghHarGhest         = 0;
                    if (SumPrice < ghestInfo.MinGhestValue)
                    {
                        // go to dagah pardaj
                        MablagheGhabelePardakht = SumPrice;
                    }
                    else
                    {
                        double A = (SumPrice + (((SumPrice * ghestInfo.Percentage) / 100.0f) * PreOrder.GhestNumber) - ghestInfo.MinPishPardakht);
                        if (A < ghestInfo.MaxGhestValue)
                        {
                            MablaghHarGhest         = A / PreOrder.GhestNumber;
                            MablagheGhabelePardakht = ghestInfo.MinPishPardakht;
                        }
                        else
                        {
                            double C = A - ghestInfo.MaxGhestValue;
                            MablagheGhabelePardakht = ghestInfo.MinPishPardakht + C;
                            MablaghHarGhest         = C / PreOrder.GhestNumber;
                        }
                    }

                    string BuyID = "70000324" + DateTime.Now.ToString("MMddyyyyhmms");


                    PreOrder.BuyID        = BuyID;
                    PreOrder.GhestValue   = (long)MablaghHarGhest;
                    PreOrder.MainPrice    = (long)SumPrice;
                    PreOrder.PishPardakht = (long)MablagheGhabelePardakht;

                    bool OIDRes = BLL.Salement.UpdateOrderReBuy(PreOrder);
                    if (!OIDRes)
                    {
                        buyResult.HasError  = true;
                        buyResult.StateDesc = "Etela'at Kharid dar DB Update nashode";
                        return(buyResult);
                    }



                    COM.PayResultRequested payResultRequested = PayStart(10000, BuyID);
                    if (payResultRequested.Result > 0)
                    {
                        COM.Pay newPay = new COM.Pay()
                        {
                            Amount      = 10000,//MablagheGhabelePardakht
                            BuyID       = BuyID,
                            StartMoment = DateTime.Now,
                            UID         = mMiddleRePayment.UID,
                            OID         = mMiddleRePayment.OID,
                        };
                        int resDB = BLL.Payment.AddPay(newPay);
                        if (resDB < 0)
                        {
                            buyResult.HasError  = true;
                            buyResult.StateDesc = "Etela'at pardakht dar DB Save nashode";
                            return(buyResult);
                        }

                        buyResult.PayID = resDB;
                        buyResult.MablagheKoleKharid   = (long)SumPrice;
                        buyResult.MablagheHarGhest     = (long)MablaghHarGhest;
                        buyResult.MablaghePishpardakht = (long)MablagheGhabelePardakht;
                        buyResult.HasError             = false;
                        buyResult.LinkPardakht         = "http://www.poolban.ir/V2PayGate/Pool/StartPayRedirectww/" + payResultRequested.Result;
                        buyResult.StateDesc            = "OK Successsssss hoooraaa";
                    }
                    else
                    {
                        buyResult.MablagheKoleKharid   = (long)SumPrice;
                        buyResult.MablagheHarGhest     = (long)MablaghHarGhest;
                        buyResult.MablaghePishpardakht = (long)MablagheGhabelePardakht;
                        buyResult.HasError             = true;
                        buyResult.StateDesc            = "irad dar dargahe pardakht";
                    }

                    return(buyResult);
                }
                else
                {
                    buyResult.HasError  = true;
                    buyResult.StateDesc = "eshtbahi dar ersal Post pish amade";
                    return(buyResult);
                }
            }
            catch (Exception e)
            {
                new System.Threading.Thread(delegate() { Log.DoLog(COM.Action.Buy, "", -100, e.Message); }).Start();
                buyResult.HasError  = true;
                buyResult.StateDesc = "Exception dade: " + e.Message;
                return(buyResult);
            }
        }