Ejemplo n.º 1
0
        /// <summary>
        /// Sets shipping method used to compute shipping charges.
        /// </summary>
        /// <param name="shippingMethod">The name of the shipper.</param>
        /// <returns>Updated shopping cart.</returns>
        public ShoppingCart SetShippingMethod(string shippingMethod)
        {
            CartRequest request = new CartRequest();

            request.RequestId   = NewRequestId;
            request.AccessToken = AccessToken;
            request.ClientTag   = ClientTag;

            request.Action         = "Update";
            request.ShippingMethod = shippingMethod;

            CartResponse response = ActionServiceClient.SetCart(request);

            if (request.RequestId != response.CorrelationId)
            {
                throw new ApplicationException("SetShippingMethod: Request and CorrelationId do not match.");
            }

            return(response.Cart);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes a line item from the shopping cart.
        /// </summary>
        /// <param name="productId">The item to be removed.</param>
        /// <returns>Updated shopping cart.</returns>
        public ShoppingCart RemoveItem(int productId)
        {
            CartRequest request = new CartRequest();

            request.RequestId   = NewRequestId;
            request.AccessToken = AccessToken;
            request.ClientTag   = ClientTag;

            request.Action   = "Delete";
            request.CartItem = new ShoppingCartItem {
                Id = productId
            };

            CartResponse response = ActionServiceClient.SetCart(request);

            if (request.RequestId != response.CorrelationId)
            {
                throw new ApplicationException("RemoveItem: Request and CorrelationId do not match.");
            }

            return(response.Cart);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds an item to the shopping cart.
        /// </summary>
        /// <param name="productId">Unique product identifier or item.</param>
        /// <param name="name">Item name.</param>
        /// <param name="quantity">Quantity of items.</param>
        /// <param name="unitPrice">Unit price for each item.</param>
        /// <returns>Updated shopping cart.</returns>
        public ShoppingCart AddItem(int productId, string name, int quantity, double unitPrice)
        {
            CartRequest request = new CartRequest();

            request.RequestId   = NewRequestId;
            request.AccessToken = AccessToken;
            request.ClientTag   = ClientTag;

            request.Action   = "Create";
            request.CartItem = new ShoppingCartItem {
                Id = productId, Name = name, Quantity = quantity, UnitPrice = unitPrice
            };

            CartResponse response = ActionServiceClient.SetCart(request);

            if (request.RequestId != response.CorrelationId)
            {
                throw new ApplicationException("AddItem: Request and CorrelationId do not match.");
            }

            return(response.Cart);
        }