Esempio n. 1
0
        public static Order Parse(XElement element, bool validate = true)
        {
            var order = new Order();

            var initial = element.Element("initial");

            order.FirstName   = element.Element("firstName").Value;
            order.Initial     = initial == null ? (char?)null : ((string)initial)[0];
            order.LastName    = element.Element("lastName").Value;
            order.Email       = element.Element("email").Value;
            order.Phone       = element.Element("phone").Value;
            order.Country     = element.Element("country").Value;
            order.Address1    = element.Element("address1").Value;
            order.Address2    = element.Element("address2").Value;
            order.City        = element.Element("city").Value;
            order.State       = element.Element("state").Value;
            order.PostalCode  = element.Element("postalCode").Value;
            order.CardNumber  = element.Element("cardNumber").Value;
            order.CVV2        = (int)element.Element("cvv2");
            order.ExpireMonth = (int)element.Element("expireMonth");
            order.ExpireYear  = (int)element.Element("expireYear");

            foreach (var detail in element.Element("details").Elements("detail"))
            {
                var shipping = detail.Element("shipping");
                var tax      = detail.Element("tax");

                order.Details.Add(new Detail()
                {
                    SKU      = detail.Element("sku").Value,
                    Name     = detail.Element("name").Value,
                    Price    = (double)detail.Element("price"),
                    Shipping = shipping == null ? 0.0 : (double)shipping,
                    Tax      = shipping == null ? 0.0 : (double)tax,
                    Quantity = (int)detail.Element("quantity")
                });
            }

            if (validate)
            {
                order.Validate();
            }

            return(order);
        }
Esempio n. 2
0
        public static Outcome PlaceOrder(ILogger logger, Config config, Order order, bool validate = true)
        {
            const string OAUTHERROR =
                "An unexpected OAUTH validation error occured!  Please contact support for help in resolving this issue.";

            Contract.Requires(logger != null);
            Contract.Requires(config != null);
            Contract.Requires(order != null);

            if (validate)
            {
                config.Validate();
                order.Validate();
            }

            logger.Log(LogLevel.Info, "Placing Order (OrderId: {0})", order.OrderId);

            var oauth = new OAuthHelper(logger, config);

            var accessToken = oauth.GetAccessToken();

            if (accessToken == null)
            {
                logger.Log(LogLevel.Error, OAUTHERROR);

                throw new Exception(OAUTHERROR);
            }

            var context = new Context(accessToken, order.OrderId);

            var payment = GetPayment(logger, config, context, order, validate);

            var outcome = new Outcome()
            {
                CreatedOn = DateTime.Parse(payment.create_time),
                UpdatedOn = DateTime.Parse(payment.update_time),
                State     = (OrderState)Enum.Parse(typeof(OrderState), payment.state, true),
                PaymentId = payment.id
            };

            logger.Log(LogLevel.Info, "OrderId: {0}, Outcome: {1}, PaymentId: {2}",
                       order.OrderId, outcome.State, outcome.PaymentId);

            return(outcome);
        }
Esempio n. 3
0
        public static Outcome PlaceOrder(ILogger logger, Config config, Order order, bool validate = true)
        {
            const string OAUTHERROR =
                "An unexpected OAUTH validation error occured!  Please contact support for help in resolving this issue.";

            Contract.Requires(logger != null);
            Contract.Requires(config != null);
            Contract.Requires(order != null);

            if (validate)
            {
                config.Validate();
                order.Validate();
            }

            logger.Log(LogLevel.Info, "Placing Order (OrderId: {0})", order.OrderId);

            var oauth = new OAuthHelper(logger, config);

            var accessToken = oauth.GetAccessToken();

            if (accessToken == null)
            {
                logger.Log(LogLevel.Error, OAUTHERROR);

                throw new Exception(OAUTHERROR);
            }

            var context = new Context(accessToken, order.OrderId);

            var payment = GetPayment(logger, config, context, order, validate);

            var outcome = new Outcome()
            {
                CreatedOn = DateTime.Parse(payment.create_time),
                UpdatedOn = DateTime.Parse(payment.update_time),
                State = (OrderState)Enum.Parse(typeof(OrderState), payment.state, true),
                PaymentId = payment.id
            };

            logger.Log(LogLevel.Info, "OrderId: {0}, Outcome: {1}, PaymentId: {2}",
                order.OrderId, outcome.State, outcome.PaymentId);

            return outcome;
        }
Esempio n. 4
0
        public static Order Parse(XElement element, bool validate = true)
        {
            var order = new Order();

            var initial = element.Element("initial");

            order.FirstName = element.Element("firstName").Value;
            order.Initial = initial == null ? (char?)null : ((string)initial)[0];
            order.LastName = element.Element("lastName").Value;
            order.Email = element.Element("email").Value;
            order.Phone = element.Element("phone").Value;
            order.Country = element.Element("country").Value;
            order.Address1 = element.Element("address1").Value;
            order.Address2 = element.Element("address2").Value;
            order.City = element.Element("city").Value;
            order.State = element.Element("state").Value;
            order.PostalCode = element.Element("postalCode").Value;
            order.CardNumber = element.Element("cardNumber").Value;
            order.CVV2 = (int)element.Element("cvv2");
            order.ExpireMonth = (int)element.Element("expireMonth");
            order.ExpireYear = (int)element.Element("expireYear");

            foreach (var detail in element.Element("details").Elements("detail"))
            {
                var shipping = detail.Element("shipping");
                var tax = detail.Element("tax");

                order.Details.Add(new Detail()
                {
                    SKU = detail.Element("sku").Value,
                    Name = detail.Element("name").Value,
                    Price = (double)detail.Element("price"),
                    Shipping = shipping == null ? 0.0 : (double)shipping,
                    Tax = shipping == null ? 0.0 : (double)tax,
                    Quantity = (int)detail.Element("quantity")
                });
            }

            if (validate)
                order.Validate();

            return order;
        }