private String Format(ProductShippingInfo info)
 {
     return String.Format(
         "products[][key]={0}&products[][quantity]={1}&",
         UrlEncode(info.Key), UrlEncode(info.Quantity)
     );
 }
Exemplo n.º 2
0
        public Order Create(String reference, Option shippingOption, NameAndAddress shipTo, ProductShippingInfo product)
        {
            var uri = Map("/orders");

            var payload = new Payload {
                new Field { Name = "ref", Value = reference },
                new Field { Name = "shipping_option_code", Value = shippingOption.Code },
            };

            payload.AddRange(Format(product));
            payload.AddRange(Format(shipTo));

            var response = Post(uri, payload);

            if (response.StatusCode != HttpStatusCode.OK)
                throw Error("Failed to create order", response);

            var json = ReadAll(response);

            var theOrderNode = new Deserializer().Deserialize(json)["order"];

            return OrderDeserializer.Deserialize(theOrderNode.ToString());
        }
Exemplo n.º 3
0
 private IEnumerable<Field> Format(ProductShippingInfo info)
 {
     return new List<Field> {
        		new Field {Name = "products[][key]", Value = info.Key},
        		new Field {Name = "products[][quantity]", Value = info.Quantity.ToString()}
     };
 }
        private Order CreateANewOrder(Product product)
        {
            var command = new OrderRepository(Internet, Settings.BaseUrl);

            var reference = Guid.NewGuid().ToString();

            var shippingInfo = new ProductShippingInfo() { Key = product.Key, Quantity = 1};

            return command.Create(reference, AnyShippingOption(shippingInfo), ExampleShippingAddress, shippingInfo);
        }
        private Option AnyShippingOption(ProductShippingInfo shipping)
        {
            var allOptions = new ShippingOptionsRepository(Internet, Settings.BaseUrl).
                For(ExampleAddress, shipping);

            return allOptions.Options.First();
        }