Пример #1
0
        bool saveDeal(Int64 bidId)
        {
            var order = Order.FetchByBidId(bidId);

            if (order != null && order.SupplierId > 0)
            {
                return(false);
            }

            decimal TotalPrice = order.TotalPrice;
            var     discount   = BidController.GetDiscountForUser(TotalPrice, order.AppUserId);
            var     supplier   = AppSupplier.FetchByID(312);
            string  response   = "";

            decimal PriceAfterDiscount = Convert.ToDecimal(discount["PriceAfterDiscount"]);
            decimal PrecentDiscount    = Convert.ToDecimal(discount["PrecentDiscount"]);
            Int64?  CampaignId         = Convert.ToInt64(discount["CampaignId"]);
            var     paymentDetails     = new PaymentDetails
            {
                Amount        = (float)PriceAfterDiscount * 100,
                CreditId      = order.Transaction,
                Exp           = order.ExpiryDate,
                AuthNumber    = order.AuthNumber,
                NumOfPayments = order.NumOfPayments,
                SupplierToken = supplier.MastercardCode
            };

            try
            {
                response = CreditGuardManager.CreateMPITransaction(paymentDetails);
            }
            catch
            {
                Notification.SendNotificationAppUserCreditRejected(order.AppUserId, bidId);
                return(false);
            }
            if (response != "000")
            {
                Notification.SendNotificationAppUserCreditRejected(order.AppUserId, bidId);
                return(false);
            }
            order.IsSendRecived = false;
            if (CampaignId != 0)
            {
                order.CampaignId = CampaignId;
            }
            order.TotalPrice         = TotalPrice;
            order.PriceAfterDiscount = PriceAfterDiscount;
            order.PrecentDiscount    = PrecentDiscount;
            // order.SpecialInstructions = special_instructions;
            order.UserPaySupplierStatus = UserPaymentStatus.Payed;
            order.SupplierId            = 312;
            order.Save();
            var bid = Bid.FetchByID(bidId);

            bid.IsActive = false;
            bid.Save();
            Notification.SendNotificationAppUserSupplierApproved(Snoopi.web.Localization.PushStrings.GetText("SupplierApproved"), bid.AppUserId.Value, order.OrderId);
            return(true);
        }
Пример #2
0
        public override void Get(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);
            Response.ContentType = @"application/json";

            try
            {
                string transactionId = Request["txId"];
                var    results       = CreditGuardManager.QueryMPITransaction(transactionId);
                string redirectUrl   = AppConfig.GetString(@"cgSuccessRedirectUrl", @"");

                if (results.ResultCode != "000")
                {
                    Response.ClearContent();
                    Response.StatusCode  = 200;
                    Response.ContentType = @"text/plain";
                    Response.Output.Write("שגיאה נכשלה ! " + results.ErrorMessage + " מספר שגיאה: " + results.ResultCode + " אנא פנה לשירות לקוחות ");
                    Response.End();
                }

                var preOrder = PreOrder.FetchByID(results.UniqueId);
                if (preOrder == null)
                {
                    Helpers.LogProcessing("ProcessingResultsHandler - preorder not found -", "\n exception: " + results.UniqueId, false);
                    RespondError(Response, HttpStatusCode.OK, "preorder");
                }

                results.SpecialInstructions = Request["userData3"];
                redirectUrl = String.Format(redirectUrl, true);
                long AppUserId = Convert.ToInt64(Request["userData4"]);
                results.NumOfPayments = Convert.ToInt32(Request["userData2"]);
                var bid = Bid.FetchByID(preOrder.BidId);
                bid.IsActive = true;
                bid.Save();
                var products = ProductController.GetProductsByBid(bid.BidId);
                var order    = OrderController.GenerateNewOrder(results, AppUserId, preOrder.BidId, preOrder.Gifts, preOrder.SupplierId, preOrder.TotalPrice, Source.WebSite);

                var sb = new StringBuilder();
                var sw = new StringWriter(sb);
                using (var jsonWriter = new JsonTextWriter(sw))
                {
                    jsonWriter.WriteStartObject();
                    jsonWriter.WritePropertyName(@"isSuccess");
                    jsonWriter.WriteValue(results != null);
                    jsonWriter.WritePropertyName(@"total_price");
                    jsonWriter.WriteValue(preOrder.TotalPrice);
                    jsonWriter.WritePropertyName(@"bid_id");
                    jsonWriter.WriteValue(bid.BidId);
                    jsonWriter.WritePropertyName(@"products");
                    jsonWriter.WriteStartArray();
                    foreach (var product in products)
                    {
                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName(@"product_id");
                        jsonWriter.WriteValue(product.ProductId);
                        jsonWriter.WritePropertyName(@"product_name");
                        jsonWriter.WriteValue(product.ProductName);
                        jsonWriter.WritePropertyName(@"product_category");
                        jsonWriter.WriteValue(product.CategoryName);
                        jsonWriter.WritePropertyName(@"product_sub_category");
                        jsonWriter.WriteValue(product.SubCategoryName);
                        jsonWriter.WritePropertyName(@"product_animal_name");
                        jsonWriter.WriteValue(product.AnimalName);
                        jsonWriter.WriteEndObject();
                    }
                    jsonWriter.WriteEndArray();
                    jsonWriter.WriteEndObject();
                }
                Response.Redirect(redirectUrl + "&results=" + sb.ToString(), false);
            }

            catch (Exception ex)
            {
                Helpers.LogProcessing("ProcessingResultsHandler - ex -", "\n exception: " + ex.ToString(), true);
            }
        }
Пример #3
0
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);
            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            Int64 supplierId;

            if (IsAuthorizedRequestSupplier(Request, Response, true, out supplierId))
            {
                Response.ContentType = @"application/json";

                try
                {
                    JToken jt;
                    Int64  bidId      = 0;
                    bool   isApproved = false;
                    if (inputData.TryGetValue(@"bid_id", out jt))
                    {
                        bidId = jt.Value <Int64>();
                    }
                    if (inputData.TryGetValue(@"is_approved", out jt))
                    {
                        isApproved = jt.Value <bool>();
                    }
                    var supplier = AppSupplier.FetchByID(supplierId);
                    var bid      = Bid.FetchByID(bidId);
                    if (bid.IsActive == false)
                    {
                        RespondError(Response, HttpStatusCode.NotAcceptable, @"inactive-bid");
                    }
                    long   orderId  = 0;
                    string response = "";
                    if (isApproved)
                    {
                        var order   = Order.FetchByBidId(bidId);
                        var offerUi = SupplierController.GetBidOfferById(bidId, supplierId);
                        if (offerUi == null || offerUi.BidId <= 0)
                        {
                            RespondError(Response, HttpStatusCode.NotAcceptable, @"inactive-bid");
                        }
                        decimal TotalPrice         = offerUi.TotalPrice;
                        var     discount           = BidController.GetDiscountForUser(TotalPrice, bid.AppUserId.Value);
                        decimal PriceAfterDiscount = Convert.ToDecimal(discount["PriceAfterDiscount"]);
                        decimal PrecentDiscount    = Convert.ToDecimal(discount["PrecentDiscount"]);
                        Int64?  CampaignId         = Convert.ToInt64(discount["CampaignId"]);
                        var     paymentDetails     = new PaymentDetails
                        {
                            Amount        = (float)PriceAfterDiscount * 100,
                            CreditId      = order.Transaction,
                            Exp           = order.ExpiryDate,
                            AuthNumber    = order.AuthNumber,
                            NumOfPayments = order.NumOfPayments,
                            SupplierToken = supplier.MastercardCode
                        };
                        try
                        {
                            response = CreditGuardManager.CreateMPITransaction(paymentDetails);
                        }
                        catch (Exception ex)
                        {
                            Helpers.LogProcessing("SupplierBidApprovalHandler - ex -", "\n exception: " + ex.ToString(), true);

                            endRequest(Response, order.AppUserId, bidId);
                        }
                        if (response != "000")
                        {
                            endRequest(Response, order.AppUserId, bidId);
                        }
                        order.IsSendRecived = false;
                        if (CampaignId != 0)
                        {
                            order.CampaignId = CampaignId;
                        }
                        order.TotalPrice         = TotalPrice;
                        order.PriceAfterDiscount = PriceAfterDiscount;
                        order.PrecentDiscount    = PrecentDiscount;
                        order.CreateDate         = DateTime.UtcNow;
                        // order.SpecialInstructions = special_instructions;
                        order.BidId                 = bidId;
                        order.AppUserId             = bid.AppUserId.Value;
                        order.UserPaySupplierStatus = UserPaymentStatus.Payed;
                        order.SupplierId            = supplierId;
                        order.Save();
                        bid.IsActive = false;
                        bid.Save();
                        var message = BIdMessageController.GetMessageByBidAndSupplier(bidId, supplierId);
                        message.IsActive = false;
                        message.Save();
                        orderId = order.OrderId;
                        //Notification.SendNotificationAppUserSupplierApproved(Snoopi.web.Localization.PushStrings.GetText("SupplierApproved"), bid.AppUserId.Value, order.OrderId);
                    }

                    else
                    {
                        var message = BIdMessageController.GetMessageByBidAndSupplier(bidId, supplierId);
                        message.ExpirationTime = DateTime.Now.AddHours(-1);
                        message.Save();
                    }

                    using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                    {
                        using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                        {
                            jsonWriter.WriteStartObject();
                            jsonWriter.WritePropertyName(@"success");
                            jsonWriter.WriteValue(true);
                            jsonWriter.WritePropertyName(@"order_id");
                            jsonWriter.WriteValue(orderId);
                            jsonWriter.WriteEndObject();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Helpers.LogProcessing("SupplierBidApprovalHandler - ex -", "\n exception: " + ex.ToString(), true);
                    RespondError(Response, HttpStatusCode.NotAcceptable, @"inactive-bid");
                }
            }
        }
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);
            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            try
            {
                Int64 AppUserId;
                if (IsAuthorizedRequest(Request, Response, true, out AppUserId))
                {
                    JToken  jt;
                    string  specialInstruction = null, masterCardNumber = null;
                    JArray  products         = null;
                    Int64   supplierId       = 0;
                    int     numberOfPayments = 1;
                    decimal totalPrice       = 0;
                    var     lstProduct       = new Dictionary <Int64, int>();

                    if (inputData.TryGetValue(@"products", out jt))
                    {
                        products = jt.Value <JArray>();
                    }
                    if (inputData.TryGetValue(@"supplier_id", out jt))
                    {
                        supplierId = jt.Value <Int64>();
                    }
                    if (inputData.TryGetValue(@"total_price", out jt) && jt != null)
                    {
                        totalPrice = jt.Value <decimal>();
                    }
                    if (inputData.TryGetValue(@"special_instructions", out jt) && jt != null)
                    {
                        specialInstruction = jt.Value <string>();
                    }
                    if (inputData.TryGetValue(@"mastercardCode", out jt) && jt != null)
                    {
                        masterCardNumber = jt.Value <string>();
                    }
                    if (inputData.TryGetValue(@"num_of_payments", out jt) && jt != null)
                    {
                        numberOfPayments = jt.Value <int>();
                    }

                    bool isNumberOfPaymentsValid = numberOfPayments == 3 && totalPrice > 239 ||
                                                   numberOfPayments == 2 && totalPrice >= 150 ||
                                                   (totalPrice / 100 / numberOfPayments > 1 && numberOfPayments <= 12);
                    if (!isNumberOfPaymentsValid)
                    {
                        RespondError(Response, HttpStatusCode.OK, @"num-of-payments-not-valid");
                    }

                    foreach (JObject obj in products.Children <JObject>())
                    {
                        Int64 product_id = 0;
                        int   amount     = 1;
                        if (obj.TryGetValue(@"product_id", out jt))
                        {
                            product_id = jt.Value <Int64>();
                        }
                        if (obj.TryGetValue(@"amount", out jt))
                        {
                            amount = jt.Value <int>();
                        }
                        lstProduct.Add(product_id, amount);
                    }
                    string token        = Request.Headers["Authorization"].Substring(6);
                    bool   isPriceValid = false;

                    if (supplierId > 0 && totalPrice > 0)
                    {
                        isPriceValid = OfferController.IsOfferStillValid(lstProduct, supplierId, totalPrice);
                    }
                    if (!isPriceValid)
                    {
                        RespondError(Response, HttpStatusCode.ExpectationFailed, @"price-not-valid");
                    }

                    Response.ContentType = @"application/json";
                    using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                    {
                        using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                        {
                            string gifts;
                            Random rand     = new Random();
                            long   uniqueID = DateTime.Now.Ticks + rand.Next(0, 1000);
                            string tansactionId;
                            string url = CreditGuardManager.GetCgUrl(AppUserId, totalPrice, uniqueID, numberOfPayments, masterCardNumber, specialInstruction, out tansactionId);

                            var bidId    = BidController.CreateBidProduct(AppUserId, supplierId, lstProduct, false, out gifts);
                            var preOrder = new Snoopi.core.DAL.PreOrder
                            {
                                BidId         = bidId,
                                TotalPrice    = totalPrice,
                                UniqueId      = uniqueID,
                                TransactionId = tansactionId,
                                SupplierId    = supplierId,
                                Created       = DateTime.Now,
                                Gifts         = gifts
                            };
                            preOrder.Save();

                            jsonWriter.WriteStartObject();
                            jsonWriter.WritePropertyName(@"url");
                            jsonWriter.WriteValue(url);
                            jsonWriter.WriteEndObject();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Helpers.LogProcessing("ProcessingUrlHandler - ex -", "\n exception: " + e.ToString(), true);
            }
        }
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);
            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            try
            {
                Int64 AppUserId;
                if (IsAuthorizedRequest(Request, Response, true, out AppUserId))
                {
                    JToken  jt;
                    string  specialInstruction = null, masterCardNumber = null, cardToken = null, cardExp = null;
                    JArray  products         = null;
                    Int64   supplierId       = 0;
                    int     numberOfPayments = 1;
                    decimal totalPrice       = 0;
                    var     lstProduct       = new Dictionary <Int64, int>();

                    if (inputData.TryGetValue(@"products", out jt))
                    {
                        products = jt.Value <JArray>();
                    }
                    if (inputData.TryGetValue(@"supplier_id", out jt))
                    {
                        supplierId = jt.Value <Int64>();
                    }
                    if (inputData.TryGetValue(@"total_price", out jt) && jt != null)
                    {
                        totalPrice = jt.Value <decimal>();
                    }
                    if (inputData.TryGetValue(@"special_instructions", out jt) && jt != null)
                    {
                        specialInstruction = jt.Value <string>();
                    }
                    if (inputData.TryGetValue(@"mastercardCode", out jt) && jt != null)
                    {
                        masterCardNumber = jt.Value <string>();
                    }
                    if (inputData.TryGetValue(@"num_of_payments", out jt) && jt != null)
                    {
                        numberOfPayments = jt.Value <int>();
                    }
                    if (inputData.TryGetValue(@"card_token", out jt) && jt != null)
                    {
                        cardToken = jt.Value <string>();
                    }
                    if (inputData.TryGetValue(@"card_exp", out jt) && jt != null)
                    {
                        cardExp = jt.Value <string>();
                    }

                    bool isNumberOfPaymentsValid = numberOfPayments == 3 && totalPrice > 239 ||
                                                   numberOfPayments == 2 && totalPrice >= 150 ||
                                                   totalPrice / 100 / numberOfPayments > 1;
                    if (!isNumberOfPaymentsValid)
                    {
                        RespondError(Response, HttpStatusCode.OK, @"num-of-payments-not-valid");
                    }

                    foreach (JObject obj in products.Children <JObject>())
                    {
                        Int64 product_id = 0;
                        int   amount     = 1;
                        if (obj.TryGetValue(@"product_id", out jt))
                        {
                            product_id = jt.Value <Int64>();
                        }
                        if (obj.TryGetValue(@"amount", out jt))
                        {
                            amount = jt.Value <int>();
                        }
                        lstProduct.Add(product_id, amount);
                    }
                    string token        = Request.Headers["Authorization"].Substring(6);
                    bool   isPriceValid = false;

                    if (supplierId > 0 && totalPrice > 0)
                    {
                        isPriceValid = OfferController.IsOfferStillValid(lstProduct, supplierId, totalPrice);
                    }
                    if (!isPriceValid)
                    {
                        RespondError(Response, HttpStatusCode.ExpectationFailed, @"price-not-valid");
                    }

                    string gifts;
                    Random rand     = new Random();
                    long   uniqueID = DateTime.Now.Ticks + rand.Next(0, 1000);
                    string tansactionId;
                    var    results = CreditGuardManager.ProcessSavedCard(AppUserId, totalPrice, numberOfPayments, masterCardNumber, specialInstruction, cardToken, cardExp, out tansactionId);
                    if (results.ResultCode != "000")
                    {
                        RespondError(Response, HttpStatusCode.ExpectationFailed, @"failed");
                    }


                    results.SpecialInstructions = specialInstruction;
                    results.NumOfPayments       = numberOfPayments;
                    var bidId          = BidController.CreateBidProduct(AppUserId, supplierId, lstProduct, true, out gifts);
                    var order          = OrderController.GenerateNewOrder(results, AppUserId, bidId, gifts, supplierId, totalPrice, core.DAL.Source.WebSite);
                    var productsParams = ProductController.GetProductsWithIds(lstProduct.Select(x => x.Key));
                    using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                    {
                        using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                        {
                            jsonWriter.WriteStartObject();
                            jsonWriter.WritePropertyName(@"isSuccess");
                            jsonWriter.WriteValue(results != null);
                            jsonWriter.WritePropertyName(@"total_price");
                            jsonWriter.WriteValue(totalPrice);
                            jsonWriter.WritePropertyName(@"bid_id");
                            jsonWriter.WriteValue(bidId);


                            jsonWriter.WritePropertyName(@"products");
                            jsonWriter.WriteStartArray();
                            foreach (var product in productsParams)
                            {
                                jsonWriter.WriteStartObject();

                                jsonWriter.WritePropertyName(@"product_id");
                                jsonWriter.WriteValue(product.ProductId);
                                jsonWriter.WritePropertyName(@"product_name");
                                jsonWriter.WriteValue(product.ProductName);
                                jsonWriter.WritePropertyName(@"product_category");
                                jsonWriter.WriteValue(product.CategoryName);
                                jsonWriter.WritePropertyName(@"product_sub_category");
                                jsonWriter.WriteValue(product.SubCategoryName);
                                jsonWriter.WritePropertyName(@"product_animal_name");
                                jsonWriter.WriteValue(product.AnimalName);
                                jsonWriter.WritePropertyName(@"product_quentity");
                                jsonWriter.WriteValue(lstProduct[product.ProductId]);
                                jsonWriter.WriteEndObject();
                            }

                            jsonWriter.WriteEndArray();

                            jsonWriter.WriteEndObject();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Helpers.LogProcessing("SavedCardProcessingHandler - ex -", "\n exception: " + ex.ToString(), true);
            }
        }