Example #1
0
        private CheckoutData GetCheckoutData(Guid UserID = new Guid())
        {
            if (UserID == Guid.Empty && LS.isHaveID())
            {
                UserID = LS.CurrentUser.ID;
            }
            if (UserID == Guid.Empty)
            {
                return(null);
            }
            var checkoutData = _db.CheckoutDatas.FirstOrDefault(x => x.UserID == UserID);

            if (checkoutData == null)
            {
                //add to db if not exists
                checkoutData = new CheckoutData()
                {
                    UserID   = LS.CurrentUser.ID,
                    ShipTime = DateTime.Now,
                };
                _db.CheckoutDatas.Add(checkoutData);
                _db.SaveChanges();
            }
            return(checkoutData);
        }
Example #2
0
        public PaymentResponse InitPayment(CheckoutData data)
        {
            if (data.CurrentPaymentIntentId != null)
            {
                // TODO: If session is still valid, check if there is a need to update the payment intent (e.g. amount)
                return(GetExistingSession(data.CurrentPaymentIntentId));
            }

            var service = new PaymentIntentService();
            var intent  = service.Create(new PaymentIntentCreateOptions
            {
                Amount              = (long)(data.Amount * 100),
                Currency            = data.Currency,
                PaymentMethodTypes  = new List <string>(data.PaymentMethodTypes),
                StatementDescriptor = "ABC-Trading",
                Metadata            = new Dictionary <string, string>
                {
                    { "integration_check", "accept_a_payment" },
                    { "OrderId", data.OrderId }
                }
            });

            return(new PaymentResponse()
            {
                Status = "OK",
                SuccessData = new Dictionary <string, object>()
                {
                    { "paymentIntent", intent.ToJson() }
                }
            });
        }
        public static CheckoutData GetCheckoutData(Guid UserID = new Guid())
        {
            if (LS.CurrentHttpContext != null && LS.CurrentHttpContext.Items["CheckoutData"] != null)
            {
                return(LS.CurrentHttpContext.Items["CheckoutData"] as CheckoutData);
            }
            if (UserID == Guid.Empty && LS.isHaveID())
            {
                UserID = LS.CurrentUser.ID;
            }
            if (UserID == Guid.Empty)
            {
                return(null);
            }
            var checkoutData = LS.CurrentEntityContext.CheckoutDatas.FirstOrDefault(x => x.UserID == UserID);

            if (checkoutData == null)
            {
                //add to db if not exists
                checkoutData = new CheckoutData()
                {
                    UserID   = LS.CurrentUser.ID,
                    ShipTime = DateTime.Now,
                };
                LS.CurrentEntityContext.CheckoutDatas.Add(checkoutData);
                LS.CurrentEntityContext.SaveChanges();
            }
            if (LS.CurrentHttpContext != null)
            {
                LS.CurrentHttpContext.Items["CheckoutData"] = checkoutData;
            }
            return(checkoutData);
        }
        protected override void Handle(IHttpContext context, TFSSourceControlProvider sourceControlProvider)
        {
            IHttpRequest  request  = context.Request;
            IHttpResponse response = context.Response;
            CheckoutData  data     = Helper.DeserializeXml <CheckoutData>(request.InputStream);

            try
            {
                string path     = GetPath(request);
                string location = CheckOut(sourceControlProvider, data, path);
                SetResponseSettings(response, "text/html", Encoding.UTF8, 201);
                response.AppendHeader("Cache-Control", "no-cache");
                string locationUrl = "http://" + request.Headers["Host"] + Helper.EncodeC(location);
                response.AppendHeader("Location", Helper.UrlEncodeIfNeccesary(locationUrl));
                string responseContent =
                    "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" +
                    "<html><head>\n" +
                    "<title>201 Created</title>\n" +
                    "</head><body>\n" +
                    "<h1>Created</h1>\n" +
                    "<p>Checked-out resource " + Helper.Encode(location, true) + " has been created.</p>\n" +
                    "<hr />\n" +
                    "<address>Apache at " + request.Url.Host + " Port " +
                    request.Url.Port + "</address>\n" +
                    "</body></html>\n";
                WriteToResponse(response, responseContent);
            }
            catch (ConflictException ex)
            {
                RequestCache.Items["RequestBody"] = data;
                DefaultLogger logger = Container.Resolve <DefaultLogger>();
                logger.ErrorFullDetails(ex, context);

                SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 409);
                string responseContent =
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<D:error xmlns:D=\"DAV:\" xmlns:m=\"http://apache.org/dav/xmlns\" xmlns:C=\"svn:\">\n" +
                    "<C:error/>\n" +
                    "<m:human-readable errcode=\"160024\">\n" +
                    "The version resource does not correspond to the resource within the transaction.  Either the requested version resource is out of date (needs to be updated), or the requested version resource is newer than the transaction root (restart the commit).\n" +
                    "</m:human-readable>\n" +
                    "</D:error>\n";
                WriteToResponse(response, responseContent);
            }
            catch
            {
                RequestCache.Items["RequestBody"] = data;
                throw;
            }
        }
Example #5
0
        //http://localhost:8080/api/checkout?CutomerId=1&Products=2,10


        //http://localhost:8080/api/checkout?CutomerId=9ef6ac0b-9f36-4db4-a498-0070a00b7af8&Products=018a5e88-0f30-4409-b78c-2d8a824d70b7,018a5e88-0f30-4409-b78c-2d8a824d70b7,018a5e88-0f30-4409-b78c-2d8a824d70b7,c5b2084c-9bd7-400f-bf9a-9be14453c7c0
        //Console.WriteLine("{0} \n{1} \n{2}", "Customer: Unilever",
        //						 "SKUs Scanned: 'classic', 'classic', 'classic', 'premium'",
        //						 "Total expected: $934.97");

        public IHttpActionResult Checkout([ModelBinder(typeof(CommaDelimitedArrayModelBinder))] CheckoutData ResourceQuery)
        {
            try
            {
                //using (var context = new AppDbContext())
                {
                    var total = new JobAdsCheckoutService(new PricingRulesService(new JsonPricingRulesRepository()),
                                                          new ProductService(new JsonProductRepository()))
                                .Checkout(ResourceQuery.cutomerId, ResourceQuery.productsId);
                    return(Ok(total));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        private string CheckOut(TFSSourceControlProvider sourceControlProvider, CheckoutData request, string path)
        {
            string activityId = PathParser.GetActivityId(request.ActivitySet.href);

            if (path.Contains("/bln"))
            {
                return(GetLocalPath("//!svn/wbl/" + activityId + path.Substring(9)));
            }

            if (path == "/!svn/vcc/default")
            {
                //    int latestVersion = sourceControlProvider.GetLatestVersion();
                int latestVersion = GetSDKObject().GetLastestVersionNum(path);
                return(GetLocalPath("//!svn/wbl/" + activityId + "/" + latestVersion.ToString()));
            }

            int    revisionStart = path.IndexOf("/ver/") + 5;
            int    version;
            string itemPath;

            if (path.IndexOf('/', revisionStart + 1) != -1)
            {
                int revisionEnd = path.IndexOf('/', revisionStart + 1);
                version  = int.Parse(path.Substring(revisionStart, revisionEnd - revisionStart));
                itemPath = path.Substring(revisionEnd);
            }
            else
            {
                version  = int.Parse(path.Substring(revisionStart));
                itemPath = "/";
            }

            itemPath = itemPath.Replace("//", "/");
            string location = GetLocalPath("//!svn/wrk/" + activityId + itemPath);


            int ver = GetSDKObject().GetLastestVersionNum(itemPath);

            if (ver > version)
            {
                throw new ConflictException();
            }

            return(location);
        }
Example #7
0
 private static double Checkout(string customerName, List <Guid> productsId)
 {
     if (JsonDBMod)
     {
         var customerId   = new CustomerService(new JsonCustomerRepository()).GeCustomer(customerName).Id;
         var checkOutData = new CheckoutData(customerId, productsId);
         return(new JobAdsCheckoutService(new PricingRulesService(new JsonPricingRulesRepository()),
                                          new ProductService(new JsonProductRepository()))
                .Checkout(checkOutData));
     }
     else
     {
         var customerId   = new CustomerService(new SQLCustomerRepository()).GeCustomer(customerName).Id;
         var checkOutData = new CheckoutData(customerId, productsId);
         return(new JobAdsCheckoutService(new PricingRulesService(new SQLPricingRulesRepository()),
                                          new ProductService(new SQLProductRepository()))
                .Checkout(checkOutData));
     }
 }
Example #8
0
        private string CheckOut(TFSSourceControlProvider sourceControlProvider, CheckoutData request, string path)
        {
            string activityId = PathParser.GetActivityId(request.ActivitySet.href);

            if (path.Contains("/bln"))
            {
                return(GetLocalPath("//!svn/wbl/" + activityId + path.Substring(9)));
            }

            if (path == "/!svn/vcc/default")
            {
                int latestVersion = sourceControlProvider.GetLatestVersion();
                return(GetLocalPath("//!svn/wbl/" + activityId + "/" + latestVersion.ToString()));
            }

            int    revisionStart = path.IndexOf("/ver/") + 5;
            int    version;
            string itemPath;

            if (path.IndexOf('/', revisionStart + 1) != -1)
            {
                int revisionEnd = path.IndexOf('/', revisionStart + 1);
                version  = int.Parse(path.Substring(revisionStart, revisionEnd - revisionStart));
                itemPath = path.Substring(revisionEnd);
            }
            else
            {
                version  = int.Parse(path.Substring(revisionStart));
                itemPath = "/";
            }

            itemPath = itemPath.Replace("//", "/");
            string location = GetLocalPath("//!svn/wrk/" + activityId + itemPath);

            ItemMetaData item = sourceControlProvider.GetItemsWithoutProperties(-1, Helper.Decode(itemPath), Recursion.None);

            if (item.ItemRevision > version || item.PropertyRevision > version)
            {
                throw new ConflictException();
            }

            return(location);
        }
Example #9
0
        //Clean items from the cart and update order and order details
        public IActionResult CleanAndUpdate()
        {
            //Retrieve SessionId and UserId From Cookies
            string sessionId = Request.Cookies["sessionId"];
            string userId    = Request.Cookies["userId"];

            Session sess = new Session()
            {
                SessionId = sessionId,
                UserId    = userId
            };

            //Call functions to update sales records and clear items from the cart
            CheckoutData.UpdateSales(userId);
            CheckoutData.UpdateSalesDetails(sess);
            CheckoutData.CleanCart(userId);

            //Redirect to gallery page after database update
            return(RedirectToAction("Index", "Gallery"));
        }
        public int CheckoutSmsConfirmSmsToUser(CheckoutData checkooutData, User user)
        {
            MethodBase            method = MethodBase.GetCurrentMethod();
            MailTemplateAttribute attr   = (MailTemplateAttribute)method.GetCustomAttributes(typeof(MailTemplateAttribute), true)[0];
            string templateSystemName    = attr.TemplateSystemName;

            if (user != null && checkooutData.Phone != null || _isGetTokensOnly)
            {
                if (checkooutData.Phone == null)
                {
                    checkooutData.Phone = "";
                }
                var res = Tokenize(templateSystemName, checkooutData.Phone.Replace(" ", "").Replace("-", "") + _SMSGateway, new List <object>()
                {
                    user,
                    checkooutData
                });
                return(res);
            }
            return(0);
        }
Example #11
0
 public double Checkout(CheckoutData data)
 {
     return(Checkout(data.cutomerId, data.productsId));
 }