示例#1
0
 //Highrise.Api _highrise;
 public ShopifyController(ITokenHandler tokenStore)
     : base(tokenStore)
 {
     _orders = new Orders();
     _items = new OrderItems();
     //_highrise = new Highrise.Api("XYZ", "your_domain");
 }
示例#2
0
        public static void AuthorizeOrder(dynamic customer, dynamic order) {
            dynamic itemTable = new OrderItems();
            dynamic productionsTable = new Productions();
            dynamic customersTable = new Customers();
            //loop the items and set auth accordingly
            foreach (var item in itemTable.Find(OrderID:order.ID)) {
                if (item.SKU == "monthly") {
                    //bump the customer's streaming
                    if (customer.StreamUntil < DateTime.Today.AddMonths(-1))
                        customer.StreamUntil = DateTime.Today.AddMonths(-1);
                    customer.StreamUntil = customer.StreamUntil.AddMonths(1);
                    customersTable.Update(customer,customer.ID);
                } else if (item.SKU == "yearly") {
                    if (customer.StreamUntil < DateTime.Today.AddYears(-1))
                        customer.StreamUntil = DateTime.Today.AddYears(-1);

                    if (customer.DownloadUntil < DateTime.Today.AddYears(-1))
                        customer.DownloadUntil = DateTime.Today.AddYears(-1);

                    customer.StreamUntil = customer.StreamUntil.AddYears(1);
                    customer.DownloadUntil = customer.DownloadUntil.AddYears(1);
                    customersTable.Update(customer,customer.ID);
                } else {
                    Authorize(customer, productionsTable.First(Slug: item.SKU));
                }
            }

        }
示例#3
0
        public static void AuthorizeOrder(dynamic customer, dynamic order)
        {
            dynamic itemTable        = new OrderItems();
            dynamic productionsTable = new Productions();
            dynamic customersTable   = new Customers();

            //loop the items and set auth accordingly
            foreach (var item in itemTable.Find(OrderID:order.ID))
            {
                if (item.SKU == "monthly")
                {
                    //bump the customer's streaming
                    if (customer.StreamUntil < DateTime.Today.AddMonths(-1))
                    {
                        customer.StreamUntil = DateTime.Today.AddMonths(-1);
                    }
                    customer.StreamUntil = customer.StreamUntil.AddMonths(1);
                    customersTable.Update(customer, customer.ID);
                }
                else if (item.SKU == "yearly")
                {
                    if (customer.StreamUntil < DateTime.Today.AddYears(-1))
                    {
                        customer.StreamUntil = DateTime.Today.AddYears(-1);
                    }

                    if (customer.DownloadUntil < DateTime.Today.AddYears(-1))
                    {
                        customer.DownloadUntil = DateTime.Today.AddYears(-1);
                    }

                    customer.StreamUntil   = customer.StreamUntil.AddYears(1);
                    customer.DownloadUntil = customer.DownloadUntil.AddYears(1);
                    customersTable.Update(customer, customer.ID);
                }
                else
                {
                    Authorize(customer, productionsTable.First(Slug: item.SKU));
                }
            }
        }
示例#4
0
        public ShopifyTests() {
            _orders = new Orders();
            _items = new OrderItems();

        }
示例#5
0
文件: Orders.cs 项目: kodoroph/mvc3
        public dynamic CreateFromPing(dynamic order){
            //this is sorta ugly... but whatever...
            int newOrderID = 0;
            var orderItems = new OrderItems();
            
            var newOrder = new {
                OrderNumber = order.order_number,
                ShopifyID = order.id,
                ShopifyName = order.name,
                Discount = order.total_discounts,
                CreatedAt = DateTime.Parse(order.created_at),
                Subtotal = order.subtotal_price,
                Token = order.token,
                Total = order.total_price,
                TaxIncluded = order.taxes_included,
                LandingPage = order.landing_site,
                ShopifyNumber = order.number,
                ReferringSite = order.referring_site,
                Note = order.note,
                Gateway = order.gateway,
                FulfillmentStatus = order.fulfillment_status,
                FinancialStatus = order.financial_status,
                Currency = order.currency,
                ClosedAt = order.closed_at,
                AcceptsMarketing = order.buyer_accepts_marketing,
                Tax = order.total_tax,
                ReferralID = order.landing_site_ref,
                IP = order.browser_ip,
                Weight = order.total_weight,
                Email = order.email
            };

            try {
                dynamic savedOrder = Insert(newOrder);
                newOrderID = savedOrder.ID;
                var items = new List<dynamic>();
                //line items...
                foreach (var item in order.line_items) {
                    var newItem = new {
                        OrderID = savedOrder.ID,
                        ProductID = item.productID,
                        Name = item.name,
                        Price = item.price,
                        Quantity = item.quantity,
                        RequiresShipping = item.requires_shipping,
                        Title = item.title,
                        Grams = item.grams,
                        SKU = item.SKU,
                        FulfillmentStatus = item.fulfillment_status,
                        Vendor = item.vendor,
                        FulfillmentService = item.fulfillment_service

                    };
                    items.Add(newItem);
                }

                //batch add the line items
                orderItems.Save(items);

            } catch (Exception x) {
                
                //back it out
                orderItems.Delete(where: "where orderID=@0");
                Delete(newOrderID);

                //rethrow and let bubble
                throw x;
            }
            return newOrder;
        }
示例#6
0
文件: Program.cs 项目: kodoroph/mvc3
        public static void LoadLogs() {
            var vidlog = new VideoLog();
            dynamic productions = new Productions();
            dynamic episodes = new Episodes();
            dynamic orderItems = new OrderItems();
            dynamic channels = new Channels();
            var orders = new Orders();

            var rand = new Random();
            Console.WriteLine("Deleting logs...");
            vidlog.Delete();

            foreach (var order in orders.All()) {
                //pull the orderItems
                var items = orderItems.Find(OrderID: order.ID);

                //loop the items
                foreach (var item in items) {

                    var slug = item.SKU;
                    if (slug == "yearly") {
                        Console.WriteLine("Loading Productions and Episodes for Annual...");

                        //create a download log for each production and episode
                        foreach (var p in productions.All()) {
                            var eps = episodes.Find(ProductionID: p.ID);
                            foreach (var e in eps) {
                                var log = new {
                                    Slug = item.SKU,
                                    EpisodeNumber = e.Number,
                                    Email = order.Email,
                                    //the download file for the episode
                                    FileName = p.Slug + "_"+e.Number+".zip",
                                    FileSize = e.HDFileSize,
                                    //1 day lag
                                    LogDate = order.CreatedAt.AddDays(1),
                                    OrderItemID = item.ID
                                };
                                vidlog.Insert(log);
                            }
                        }
                    } else if (slug == "monthly") {
                        //create a stream log for each production and episode
                        Console.WriteLine("Loading Productions and Episodes for Monthly...");
                        foreach (var p in productions.All()) {
                            var eps = episodes.Find(ProductionID: p.ID);
                            foreach (var e in eps) {
                                var log = new {
                                    Slug = item.SKU,
                                    EpisodeNumber = e.Number,
                                    Email = order.Email,
                                    //the download file for the episode
                                    FileName = p.Slug + "_" + e.Number + ".flv",
                                    FileSize = e.StreamFileSize,
                                    //1 day lag
                                    LogDate = order.CreatedAt.AddDays(1),
                                    OrderItemID = item.ID
                               };
                                vidlog.Insert(log);
                            }
                        }
                    } else {
                        var p = productions.First(Slug:item.SKU);
                        var eps = episodes.Find(ProductionID: p.ID);
                        Console.WriteLine("Loading log for {0}...",p.Slug);
                        foreach (var e in eps) {
                            var log = new {
                                Slug = item.SKU,
                                EpisodeNumber = e.Number,
                                Email = order.Email,
                                //the download file for the episode
                                FileName = p.Slug + "_" + e.Number + ".zip",
                                FileSize = e.HDFileSize,
                                //1 day lag
                                LogDate = order.CreatedAt.AddDays(1),
                                OrderItemID = item.ID
                            };
                            vidlog.Insert(log);
                        }
                    }

                }
            }
            
        }
示例#7
0
文件: Program.cs 项目: kodoroph/mvc3
        public static void LoadOrders() {
            var _orders = new Orders();
            var _items = new OrderItems();
            var _customers = new Customers();
            var _productions = new Productions();
            dynamic _channels = new Channels();

            var orderID = 1001;
            var rand = new Random(100);

            Console.WriteLine("Blowing away dev data");
            _items.Delete();
            _orders.Delete();
            _customers.Delete();

            for (int i = 0; i < 1000; i++) {

                var month = rand.Next(1, 12);
                var day = rand.Next(1, 28);
                var orderDate = new DateTime(2011, month, day);

                Console.WriteLine("Adding " + i + " of 1000");
                var productID = 1;
                var price = 12.00;
                if (i > 250 && i < 500) {
                    productID = 2;
                    price = 15.00;
                } else if (i >= 500 && i < 750) {
                    productID = 3;
                    price = 18.00;
                } else if (i >= 750) {
                    productID = 4;
                    price = 10.00;
                }
                var p = _productions.Single(productID);
                var c = _channels.Single(p.ChannelID);
                var name = p.Title;
                var sku = p.Slug;
                var vendor = p.Author;
                var orderType = "single";
                //do a monthly every 5th one
                if (i % 5 == 0) {
                    name = "Monthly Subscription";
                    sku = "monthly";
                    vendor = "Tekpub";
                    price = 30.00;
                    orderType = "subscription";
                }

                //do an annual every 12th
                if (i % 12 == 0) {
                    name = "Annual Subscription";
                    sku = "yearly";
                    vendor = "Tekpub";
                    price = 279.00;
                    orderType = "subscription";
                }
                var tax = price * 0.0825;


                var newOrder = new {
                    OrderNumber = Guid.NewGuid().ToString(),
                    ShopifyID = orderID,
                    ShopifyName = "#" + orderID,
                    CreatedAt = orderDate,
                    Subtotal = price,
                    Token = Guid.NewGuid().ToString(),
                    Total = price + tax,
                    TaxIncluded = true,
                    LandingPage = "http://localhost",
                    ShopifyNumber = orderID,
                    Gateway = "bogus",
                    FulfillmentStatus = "fulfilled",
                    Currency = "USD",
                    ClosedAt = orderDate,
                    AcceptsMarketing = false,
                    Tax = tax,
                    IP = "127.0.0.1",
                    Weight = 1,
                    Email = i + "@example.com",
                };

                dynamic savedOrder = _orders.Insert(newOrder);
                //line items...
                for (int x = 1; x < 3; x++) {
                    var newItem = new {
                        OrderID = savedOrder.ID,
                        Name = name,
                        Price = price,
                        Quantity = x,
                        RequiresShipping = false,
                        Title = name,
                        Grams = 2,
                        SKU = sku,
                        Vendor = vendor,
                        OrderType = orderType,
                        Channel = c.Name
                    };
                    _items.Insert(newItem);

                    if (i % 5 == 0 || i % 12 == 0)
                        break;
                }
                Console.WriteLine("Creating Customer " + i);
                var customer = new {
                    First = "First" + i,
                    Last = "Last" + i,
                    Email = savedOrder.Email
                };
                _customers.Insert(customer);
                orderID++;
            }
        }
示例#8
0
        public dynamic CreateFromPing(dynamic order)
        {
            //this is sorta ugly... but whatever...
            int newOrderID = 0;
            var orderItems = new OrderItems();

            var newOrder = new {
                OrderNumber       = order.order_number,
                ShopifyID         = order.id,
                ShopifyName       = order.name,
                Discount          = order.total_discounts,
                CreatedAt         = DateTime.Parse(order.created_at),
                Subtotal          = order.subtotal_price,
                Token             = order.token,
                Total             = order.total_price,
                TaxIncluded       = order.taxes_included,
                LandingPage       = order.landing_site,
                ShopifyNumber     = order.number,
                ReferringSite     = order.referring_site,
                Note              = order.note,
                Gateway           = order.gateway,
                FulfillmentStatus = order.fulfillment_status,
                FinancialStatus   = order.financial_status,
                Currency          = order.currency,
                ClosedAt          = order.closed_at,
                AcceptsMarketing  = order.buyer_accepts_marketing,
                Tax        = order.total_tax,
                ReferralID = order.landing_site_ref,
                IP         = order.browser_ip,
                Weight     = order.total_weight,
                Email      = order.email
            };

            try {
                dynamic savedOrder = Insert(newOrder);
                newOrderID = savedOrder.ID;
                var items = new List <dynamic>();
                //line items...
                foreach (var item in order.line_items)
                {
                    var newItem = new {
                        OrderID          = savedOrder.ID,
                        ProductID        = item.productID,
                        Name             = item.name,
                        Price            = item.price,
                        Quantity         = item.quantity,
                        RequiresShipping = item.requires_shipping,
                        Title            = item.title,
                        Grams            = item.grams,
                        SKU = item.SKU,
                        FulfillmentStatus  = item.fulfillment_status,
                        Vendor             = item.vendor,
                        FulfillmentService = item.fulfillment_service
                    };
                    items.Add(newItem);
                }

                //batch add the line items
                orderItems.Save(items);
            } catch (Exception x) {
                //back it out
                orderItems.Delete(where : "where orderID=@0");
                Delete(newOrderID);

                //rethrow and let bubble
                throw x;
            }
            return(newOrder);
        }