Esempio n. 1
0
        private static void GetFirstAndLastName(Order rawOrder, out string firstName, out string lastName)
        {
            firstName = String.Empty;
            lastName  = String.Empty;
            try
            {
                if (rawOrder.ShippingAddress == null || String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.Name))
                {
                    return;
                }
                string[] rawName = rawOrder.ShippingAddress.Name.Split(' ');
                if (rawName.Any())
                {
                    firstName = rawName[0];
                }

                if (rawName.Count() < 2)
                {
                    return;
                }

                for (int i = 1; i < rawName.Count(); i++)
                {
                    lastName += rawName[i] + " ";
                }
            }
            catch (Exception)
            {
                firstName = String.Empty;
                lastName  = String.Empty;
            }
        }
Esempio n. 2
0
 public bool Update(AmazonOrder amazonOrder, Order order)
 {
     if (amazonOrder.Status == AmazonOrderStatus.Unshipped)
     {
         var shippingAddress = _validateAmazonOrderService.GetAmazonOrderAddress(order);
         _validateAmazonOrderService.SetShippingAddress(amazonOrder, shippingAddress);
     }
     return true;
 }
Esempio n. 3
0
        public bool Update(AmazonOrder amazonOrder, Order order)
        {
            if (amazonOrder.Status == AmazonOrderStatus.Unshipped && order.OrderStatus == OrderStatusEnum.Canceled)
            {
                amazonOrder.Status = AmazonOrderStatus.Canceled;
                _amazonOrderService.Update(amazonOrder);

                _orderService.Cancel(amazonOrder.Order);
            }
            return true;
        }
Esempio n. 4
0
        public bool Update(AmazonOrder amazonOrder, Order order)
        {
            if (amazonOrder.Id == 0 || (amazonOrder.Status != AmazonOrderStatus.Shipped &&
                                        amazonOrder.Status != AmazonOrderStatus.Canceled))
            {
                var shippingAddress = _validateAmazonOrderService.GetAmazonOrderAddress(order);
                _validateAmazonOrderService.GetAmazonOrderDetails(order, ref amazonOrder, shippingAddress);
            }

            amazonOrder.NumberOfItemsShipped = order.NumberOfItemsShipped;
            amazonOrder.Status = order.OrderStatus.GetEnumByValue<AmazonOrderStatus>();
            return true;
        }
Esempio n. 5
0
        public AddressData GetAmazonOrderAddress(Order rawOrder)
        {
            if (rawOrder.ShippingAddress != null)
            {
                string firstName;
                string lastName;
                GetFirstAndLastName(rawOrder, out firstName, out lastName);

                return(new AddressData
                {
                    Address1 =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.AddressLine1))
                            ? rawOrder.ShippingAddress.AddressLine1
                            : String.Empty,
                    Address2 =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.AddressLine2))
                            ? rawOrder.ShippingAddress.AddressLine2
                            : String.Empty,
                    FirstName = firstName,
                    LastName = lastName,
                    PhoneNumber =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.Phone))
                            ? rawOrder.ShippingAddress.Phone
                            : String.Empty,
                    PostalCode =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.PostalCode))
                            ? rawOrder.ShippingAddress.PostalCode
                            : String.Empty,
                    StateProvince =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.StateOrRegion))
                            ? rawOrder.ShippingAddress.StateOrRegion
                            : String.Empty,
                    City =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.City))
                            ? rawOrder.ShippingAddress.City
                            : String.Empty,
                    CountryCode = (rawOrder.ShippingAddress != null &&
                                   !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.CountryCode))
                        ? rawOrder.ShippingAddress.CountryCode
                        : String.Empty,
                });
            }
            return(null);
        }
        /// <summary>
        /// Internal method to handle an order.
        /// </summary>
        protected virtual void HandleOrder(Order order)
        {
            Console.WriteLine("Processing Order:");
            Console.WriteLine("---------------------------------------------------");
            Console.WriteLine(order.ToString());
            // Fetch the order items in each order
            orderFetcher.FetchOrderItems(order.AmazonOrderId, delegate(OrderItem item)
            {
                Console.WriteLine("\tProcessing Order Item");
                Console.WriteLine("\t---------------------------------------------------");                // Process order item here.
                Console.WriteLine("\t" + item.ToString().Replace("\n", "\n\t"));
            });

            Console.WriteLine("=================================================");
            Console.WriteLine();
        }
Esempio n. 7
0
        private bool ProcessOrder(Order order, ref AmazonOrder amazonOrder, bool newOrder)
        {
            foreach (var update in _amazonUpdates.OrderBy(updates => updates.Order))
            {
                if (!update.Update(amazonOrder, order))
                    return false;
            }

            _amazonOrderService.SaveOrUpdate(amazonOrder);

            if (newOrder)
                foreach (var orderPlaced in _onAmazonOrderPlaceds)
                    orderPlaced.OnAmazonOrderPlaced(amazonOrder);

            return true;
        }
Esempio n. 8
0
 public bool Update(AmazonOrder amazonOrder, Order order)
 {
     if (amazonOrder.Items.Any())
         return true;
     try
     {
         var orderItems = _amazonOrdersApiService.ListOrderItems(amazonOrder.AmazonOrderId);
         _importAmazonOrderService.SetAmazonOrderItems(orderItems, amazonOrder);
         return true;
     }
     catch (Exception exception)
     {
         CurrentRequestData.ErrorSignal.Raise(exception);
         return false;
     }
 }
        public AmazonOrder ScheduleSync(Order order)
        {
            switch (order.OrderStatus)
            {
                case OrderStatusEnum.Unshipped:
                case OrderStatusEnum.PartiallyShipped:
                case OrderStatusEnum.Shipped:
                case OrderStatusEnum.Canceled:
                    {
                        if (!_importAmazonOrderService.IsCurrencyValid(order))
                        {
                            _amazonLogService.Add(AmazonLogType.Orders, AmazonLogStatus.Stage, null, null,
                                                  AmazonApiSection.Orders,
                                                  null, null, null, null,
                                                  string.Format(
                                                      "Amazon Order #{0} uses different currency than current MrCMS Site.",
                                                      order.AmazonOrderId));
                        }
                        else
                        {
                            var amazonOrder = _amazonOrderService.GetByAmazonOrderId(order.AmazonOrderId);
                            var amazonOrderData = _amazonOrderSyncInfoService.GetByAmazonOrderId(order.AmazonOrderId).ToList();

                            if (order.OrderStatus == OrderStatusEnum.Canceled) return amazonOrder;

                            var newAmazonOrderData = new AmazonOrderSyncData
                            {
                                OrderId = order.AmazonOrderId,
                                Operation = (amazonOrder == null
                                            ? (amazonOrderData.Any(x=>x.Operation==SyncAmazonOrderOperation.Add) ? SyncAmazonOrderOperation.Update : SyncAmazonOrderOperation.Add) : SyncAmazonOrderOperation.Update),
                                Status = SyncAmazonOrderStatus.Pending,
                                Data = AmazonAppHelper.SerializeToJson(order),
                                Site = CurrentRequestData.CurrentSite
                            };

                            if (amazonOrder != null)
                                newAmazonOrderData.AmazonOrder = amazonOrder;

                            _amazonOrderSyncInfoService.Add(newAmazonOrderData);

                            return amazonOrder;
                        }
                    }
                    break;
            }
            return null;
        }
Esempio n. 10
0
 public void GetAmazonOrderDetails(Order rawOrder, ref AmazonOrder order, AddressData shippingAddress)
 {
     order.AmazonOrderId = !String.IsNullOrWhiteSpace(rawOrder.AmazonOrderId)
         ? rawOrder.AmazonOrderId
         : String.Empty;
     order.BuyerEmail   = !String.IsNullOrWhiteSpace(rawOrder.BuyerEmail) ? rawOrder.BuyerEmail : String.Empty;
     order.BuyerName    = !String.IsNullOrWhiteSpace(rawOrder.BuyerName) ? rawOrder.BuyerName : String.Empty;
     order.PurchaseDate = TimeZoneInfo.ConvertTime(rawOrder.PurchaseDate, TimeZoneInfo.Utc,
                                                   CurrentRequestData.TimeZoneInfo);
     order.PaymentMethod = rawOrder.PaymentMethod.GetEnumByValue <AmazonPaymentMethod>();
     order.SalesChannel  = !String.IsNullOrWhiteSpace(rawOrder.SalesChannel)
         ? rawOrder.SalesChannel
         : String.Empty;
     order.OrderType        = !String.IsNullOrWhiteSpace(rawOrder.OrderType) ? rawOrder.OrderType : String.Empty;
     order.OrderTotalAmount = (rawOrder.OrderTotal != null && rawOrder.OrderTotal.Amount != null)
         ? Decimal.Parse(rawOrder.OrderTotal.Amount, (new CultureInfo("en-GB", false)))
         : 0;
     order.OrderCurrency = (rawOrder.OrderTotal != null && rawOrder.OrderTotal.Amount != null)
         ? rawOrder.OrderTotal.CurrencyCode
         : String.Empty;
     order.MarketplaceId = !String.IsNullOrWhiteSpace(rawOrder.MarketplaceId)
         ? rawOrder.MarketplaceId
         : String.Empty;
     order.ShipServiceLevel = !String.IsNullOrWhiteSpace(rawOrder.ShipServiceLevel)
         ? rawOrder.ShipServiceLevel
         : String.Empty;
     order.ShipmentServiceLevelCategory = !String.IsNullOrWhiteSpace(rawOrder.ShipmentServiceLevelCategory)
         ? rawOrder.ShipmentServiceLevelCategory
         : String.Empty;
     SetShippingAddress(order, shippingAddress);
     order.NumberOfItemsUnshipped = rawOrder.NumberOfItemsUnshipped;
     order.NumberOfItemsShipped   = rawOrder.NumberOfItemsShipped;
     order.FulfillmentChannel     = rawOrder.FulfillmentChannel.GetEnumByValue <AmazonFulfillmentChannel>();
     order.LastUpdatedDate        = TimeZoneInfo.ConvertTime(rawOrder.LastUpdateDate, TimeZoneInfo.Utc,
                                                             CurrentRequestData.TimeZoneInfo);
 }
 public void GetAmazonOrderDetails(Order rawOrder, ref AmazonOrder order, AddressData shippingAddress)
 {
     order.AmazonOrderId = !String.IsNullOrWhiteSpace(rawOrder.AmazonOrderId)
         ? rawOrder.AmazonOrderId
         : String.Empty;
     order.BuyerEmail = !String.IsNullOrWhiteSpace(rawOrder.BuyerEmail) ? rawOrder.BuyerEmail : String.Empty;
     order.BuyerName = !String.IsNullOrWhiteSpace(rawOrder.BuyerName) ? rawOrder.BuyerName : String.Empty;
     order.PurchaseDate = TimeZoneInfo.ConvertTime(rawOrder.PurchaseDate, TimeZoneInfo.Utc,
         CurrentRequestData.TimeZoneInfo);
     order.PaymentMethod = rawOrder.PaymentMethod.GetEnumByValue<AmazonPaymentMethod>();
     order.SalesChannel = !String.IsNullOrWhiteSpace(rawOrder.SalesChannel)
         ? rawOrder.SalesChannel
         : String.Empty;
     order.OrderType = !String.IsNullOrWhiteSpace(rawOrder.OrderType) ? rawOrder.OrderType : String.Empty;
     order.OrderTotalAmount = (rawOrder.OrderTotal != null && rawOrder.OrderTotal.Amount != null)
         ? Decimal.Parse(rawOrder.OrderTotal.Amount, (new CultureInfo("en-GB", false)))
         : 0;
     order.OrderCurrency = (rawOrder.OrderTotal != null && rawOrder.OrderTotal.Amount != null)
         ? rawOrder.OrderTotal.CurrencyCode
         : String.Empty;
     order.MarketplaceId = !String.IsNullOrWhiteSpace(rawOrder.MarketplaceId)
         ? rawOrder.MarketplaceId
         : String.Empty;
     order.ShipServiceLevel = !String.IsNullOrWhiteSpace(rawOrder.ShipServiceLevel)
         ? rawOrder.ShipServiceLevel
         : String.Empty;
     order.ShipmentServiceLevelCategory = !String.IsNullOrWhiteSpace(rawOrder.ShipmentServiceLevelCategory)
         ? rawOrder.ShipmentServiceLevelCategory
         : String.Empty;
     SetShippingAddress(order, shippingAddress);
     order.NumberOfItemsUnshipped = rawOrder.NumberOfItemsUnshipped;
     order.NumberOfItemsShipped = rawOrder.NumberOfItemsShipped;
     order.FulfillmentChannel = rawOrder.FulfillmentChannel.GetEnumByValue<AmazonFulfillmentChannel>();
     order.LastUpdatedDate = TimeZoneInfo.ConvertTime(rawOrder.LastUpdateDate, TimeZoneInfo.Utc,
         CurrentRequestData.TimeZoneInfo);
 }
 /// <summary>
 /// Creates a ListOrderItems request object for a given order.
 /// </summary>
 /// <param name="order">The order in which the items for it are being requested.</param>
 /// <returns>A ListOrderItemsRequest object.</returns>
 private ListOrderItemsRequest CreateListOrderItemsRequest(Order order)
 {
     var listItemsRequest = new ListOrderItemsRequest()
     {
         SellerId = _MerchantId,
         AmazonOrderId = order.AmazonOrderId
     };
     return listItemsRequest;
 }
Esempio n. 13
0
 /// <summary>
 /// Sets the Orders property.
 /// </summary>
 /// <param name="orders">Orders property.</param>
 /// <returns>this instance.</returns>
 public ListOrdersResult WithOrders(Order[] orders)
 {
     this._orders.AddRange(orders);
     return this;
 }
        public AddressData GetAmazonOrderAddress(Order rawOrder)
        {
            if (rawOrder.ShippingAddress != null)
            {
                string firstName;
                string lastName;
                GetFirstAndLastName(rawOrder, out firstName, out lastName);

                return new AddressData
                {
                    Address1 =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.AddressLine1))
                            ? rawOrder.ShippingAddress.AddressLine1
                            : String.Empty,
                    Address2 =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.AddressLine2))
                            ? rawOrder.ShippingAddress.AddressLine2
                            : String.Empty,
                    FirstName = firstName,
                    LastName = lastName,
                    PhoneNumber =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.Phone))
                            ? rawOrder.ShippingAddress.Phone
                            : String.Empty,
                    PostalCode =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.PostalCode))
                            ? rawOrder.ShippingAddress.PostalCode
                            : String.Empty,
                    StateProvince =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.StateOrRegion))
                            ? rawOrder.ShippingAddress.StateOrRegion
                            : String.Empty,
                    City =
                        (rawOrder.ShippingAddress != null &&
                         !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.City))
                            ? rawOrder.ShippingAddress.City
                            : String.Empty,
                    CountryCode = (rawOrder.ShippingAddress != null &&
                                   !String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.CountryCode))
                        ? rawOrder.ShippingAddress.CountryCode
                        : String.Empty,
                };
            }
            return null;
        }
Esempio n. 15
0
        /// <summary>
        /// Converts the response object into MarketplaceOrder object.
        /// Also makes the call to get the items for the order.
        /// </summary>
        /// <param name="order">The given Amazon order objecdt.</param>
        /// <returns>A MarketplaceOrder object</returns>
        private MarketplaceOrder convertOrderResponseToMarketplaceOrder(MarketplaceWebServiceOrders.Model.Order order)
        {
            var orderStatus = (Inventory.Shared.Models.OrderStatus)Enum.Parse(typeof(Inventory.Shared.Models.OrderStatus), order.OrderStatus, true);

            var marketplaceOrder = new MarketplaceOrder()
            {
                BuyerEmail              = order.BuyerEmail,
                BuyerName               = order.BuyerName,
                OrderTotal              = order.IsSetOrderTotal() ? decimal.Parse(order.OrderTotal.Amount) : 0,
                OrderId                 = order.AmazonOrderId,
                Marketplace             = ChannelName,
                ShipServiceLevel        = order.ShipServiceLevel,
                ShipmentServiceCategory = order.ShipmentServiceLevelCategory,
                NumOfItemsShipped       = order.NumberOfItemsShipped,
                NumOfItemsUnshipped     = order.NumberOfItemsUnshipped,
                PurchaseDate            = order.PurchaseDate,
                LastUpdateDate          = order.LastUpdateDate,
                PaymentMethod           = order.PaymentMethod,
                OrderStatus             = orderStatus,
                OrderType               = order.OrderType,
                EarliestShipDate        = order.EarliestShipDate,
                LatestShipDate          = order.LatestShipDate,
                EarliestDeliveryDate    = order.EarliestDeliveryDate,
                LatestDeliveryDate      = order.LatestDeliveryDate,
                MarketplaceId           = order.MarketplaceId,
                PurchaseOrderNumber     = order.PurchaseOrderNumber,
                SalesChannel            = order.SalesChannel,
                SellerOrderId           = order.SellerOrderId,
            };

            if (order.IsSetShippingAddress())
            {
                marketplaceOrder.ShippingAddressLine1  = order.ShippingAddress.AddressLine1;
                marketplaceOrder.ShippingAddressLine2  = order.ShippingAddress.AddressLine2;
                marketplaceOrder.ShippingAddressLine3  = order.ShippingAddress.AddressLine3;
                marketplaceOrder.ShippingCity          = order.ShippingAddress.City;
                marketplaceOrder.ShippingStateOrRegion = order.ShippingAddress.StateOrRegion;
                marketplaceOrder.ShippingPostalCode    = order.ShippingAddress.PostalCode;
                marketplaceOrder.ShippingAddressName   = order.ShippingAddress.Name;
                marketplaceOrder.ShippingAddressPhone  = order.ShippingAddress.Phone;
            }

            // do the request for the list of items for this order
            var listOrderRequest = new ListOrderItemsRequest {
                SellerId = _credential.MerchantId, AmazonOrderId = order.AmazonOrderId
            };
            var listItemsResponse = _ordersClient.ListOrderItems(listOrderRequest);
            var nextToken         = listItemsResponse.ListOrderItemsResult.NextToken;
            var items             = new List <MarketplaceOrderItem>();
            ListOrderItemsByNextTokenResponse nextTokenResponse = null;

            // convert the item responses to marketplace order item objects.
            var orderItems = listItemsResponse.ListOrderItemsResult.OrderItems;

            do
            {
                if (nextTokenResponse != null)
                {
                    orderItems = nextTokenResponse.ListOrderItemsByNextTokenResult.OrderItems;
                    nextToken  = nextTokenResponse.ListOrderItemsByNextTokenResult.NextToken;
                }

                // iterate and convert the marketplace order item into local object
                for (var i = 0; i < orderItems.Count; i++)
                {
                    var orderItem = orderItems[i];
                    var item      = new MarketplaceOrderItem
                    {
                        OrderId           = order.AmazonOrderId,
                        MarketplaceItemId = orderItem.ASIN,
                        OrderItemId       = orderItem.OrderItemId,
                        SKU           = orderItem.SellerSKU,
                        Title         = orderItem.Title,
                        QtyOrdered    = Convert.ToInt32(orderItem.QuantityOrdered),
                        QtyShipped    = Convert.ToInt32(orderItem.QuantityShipped),
                        ConditionNote = orderItem.ConditionNote
                    };

                    item.Price             = orderItem.IsSetItemPrice() ? decimal.Parse(orderItem.ItemPrice.Amount) : 0;
                    item.ShippingPrice     = orderItem.IsSetShippingPrice() ? decimal.Parse(orderItem.ShippingPrice.Amount) : 0;
                    item.GiftWrapPrice     = orderItem.IsSetGiftWrapPrice() ? decimal.Parse(orderItem.GiftWrapPrice.Amount) : 0;
                    item.Tax               = orderItem.IsSetItemTax() ? decimal.Parse(orderItem.ItemTax.Amount) : 0;
                    item.ShippingTax       = orderItem.IsSetShippingTax() ? decimal.Parse(orderItem.ShippingTax.Amount) : 0;
                    item.GiftWrapTax       = orderItem.IsSetGiftWrapTax() ? decimal.Parse(orderItem.GiftWrapTax.Amount) : 0;
                    item.ShippingDiscount  = orderItem.IsSetShippingDiscount() ? decimal.Parse(orderItem.ShippingDiscount.Amount) : 0;
                    item.PromotionDiscount = orderItem.IsSetPromotionDiscount() ? decimal.Parse(orderItem.PromotionDiscount.Amount) : 0;

                    items.Add(item);
                }

                // get the page order items if the next token not null
                if (!string.IsNullOrWhiteSpace(nextToken))
                {
                    // pause for 2 seconds, this is the restore reate for the ListOrderItemsByNextToken for every 30 quota
                    Thread.Sleep(2000);

                    var nextRequest = new ListOrderItemsByNextTokenRequest {
                        SellerId = _credential.MerchantId, NextToken = nextToken
                    };
                    nextTokenResponse = _ordersClient.ListOrderItemsByNextToken(nextRequest);
                }
            } while (!string.IsNullOrWhiteSpace(nextToken));

            // set the order items to the local object
            marketplaceOrder.OrderItems = items;

            return(marketplaceOrder);
        }
 private void ProcessOrder(Order order)
 {
     order.WriteSeparatedFragment(Account.ToString(), _orderCsv, "\t");
     _orderIds.Add(order.AmazonOrderId);
     _orderIdtxt.WriteLine(order.AmazonOrderId);
 }
Esempio n. 17
0
 public bool IsCurrencyValid(Order order)
 {
     var currency = _ecommerceSettings.Currency();
     return !(order.OrderTotal != null && order.OrderTotal.CurrencyCode != currency.Code);
 }
        /// <summary>
        /// Converts the response object into MarketplaceOrder object. Also makes the call to get the items for the order.
        /// </summary>
        /// <param name="order">The given amazon order object.</param>
        /// <returns>A MarketplaceOrder object</returns>
        private Contracts.MarketplaceOrder ConvertOrderResponseToMarketplaceOrder(Order order)
        {
            var marketplaceOrder = new Contracts.MarketplaceOrder()
            {
                BuyerShippingAddress1 = order.ShippingAddress.AddressLine1,
                BuyerShippingAddress2 = order.ShippingAddress.AddressLine2,
                BuyerShippingAddress3 = order.ShippingAddress.AddressLine3,
                BuyerShippingCity = order.ShippingAddress.City,
                BuyerShippingState = order.ShippingAddress.StateOrRegion,
                BuyerShippingZip = order.ShippingAddress.PostalCode,
                BuyerShippingName = order.ShippingAddress.Name,
                BuyerShippingPhone = order.ShippingAddress.Phone,
                BuyerEmail = order.BuyerEmail,
                BuyerName = order.BuyerName,
                OrderTotal = decimal.Parse(order.OrderTotal.Amount),
                MarketplaceOrderId = order.AmazonOrderId,
                OrderStatus = order.OrderStatus == OrderStatusEnum.PartiallyShipped
                    ? Contracts.EOrderStatus.PartiallyShipped
                    : Contracts.EOrderStatus.Unshipped,
                Marketplace = Contracts.EMarketplace.Amazon,
                ShipmentServiceLevel = order.ShipmentServiceLevelCategory
            };

            var listItemsResponse = _AmazonOrdersClient.ListOrderItems(CreateListOrderItemsRequest(order));
            if (!string.IsNullOrWhiteSpace(listItemsResponse.ListOrderItemsResult.NextToken))
                throw new MarketplaceWebServiceException("ListOrderItems returned a next token. Please restructure the code to continue pulling order items with this token.");
            // Convert the item responses to marketplace order item objects.
            marketplaceOrder.Items = listItemsResponse.ListOrderItemsResult.OrderItems.OrderItem.Select(item =>
                new Contracts.MarketplaceOrderItem()
                {
                    MarketplaceItemId = item.ASIN,
                    MarketplaceOrderItemId = item.OrderItemId,
                    SKU = item.SellerSKU,
                    Price = decimal.Parse(item.ItemPrice.Amount),
                    ShippingPrice = decimal.Parse(item.ShippingPrice.Amount),
                    Tax = decimal.Parse(item.ItemTax.Amount),
                    ShippingTax = decimal.Parse(item.ShippingTax.Amount),
                    QuantityShipped = Convert.ToInt32(item.QuantityShipped),
                    QuantityUnshipped = Convert.ToInt32(item.QuantityOrdered - item.QuantityShipped)
                }
            );
            return marketplaceOrder;
        }
Esempio n. 19
0
        public SalesOrder MapOrderFromStore(Order amazonOrder)
        {
            var order = new SalesOrder();
            order.OrderId = amazonOrder.AmazonOrderId;
            order.NativeId = amazonOrder.AmazonOrderId;
            order.StoreStatus = amazonOrder.OrderStatus.ToString();
            order.StoreCreatedAt = amazonOrder.PurchaseDate;
            order.StoreUpdatedAt = amazonOrder.LastUpdateDate;

            if(amazonOrder.IsSetShippingAddress())
            {
                order.DeliveryCustomerName = amazonOrder.ShippingAddress.Name;
                order.DeliveryStreet = amazonOrder.ShippingAddress.AddressLine1;
                if(!String.IsNullOrWhiteSpace(amazonOrder.ShippingAddress.AddressLine2))
                   order.DeliveryStreet += System.Environment.NewLine + amazonOrder.ShippingAddress.AddressLine2;
                if(!String.IsNullOrWhiteSpace(amazonOrder.ShippingAddress.AddressLine3))
                    order.DeliveryStreet += System.Environment.NewLine + amazonOrder.ShippingAddress.AddressLine3;
                order.DeliveryCity = amazonOrder.ShippingAddress.City;
                order.DeliveryState = amazonOrder.ShippingAddress.StateOrRegion;
                order.DeliveryZip = amazonOrder.ShippingAddress.PostalCode;
                order.DeliveryCountry = amazonOrder.ShippingAddress.CountryCode;
            }

            return order;
        }
Esempio n. 20
0
 /// <summary>
 /// Sets the Order property.
 /// </summary>
 /// <param name="order">Order property.</param>
 /// <returns>this instance.</returns>
 public OrderList WithOrder(Order[] order)
 {
     this._order.AddRange(order);
     return this;
 }
        private static void GetFirstAndLastName(Order rawOrder, out string firstName, out string lastName)
        {
            firstName = String.Empty;
            lastName = String.Empty;
            try
            {
                if (rawOrder.ShippingAddress == null || String.IsNullOrWhiteSpace(rawOrder.ShippingAddress.Name))
                    return;
                string[] rawName = rawOrder.ShippingAddress.Name.Split(' ');
                if (rawName.Any())
                    firstName = rawName[0];

                if (rawName.Count() < 2) return;

                for (int i = 1; i < rawName.Count(); i++)
                {
                    lastName += rawName[i] + " ";
                }
            }
            catch (Exception)
            {
                firstName = String.Empty;
                lastName = String.Empty;
            }
        }