Exemplo n.º 1
0
        public void TestServiceVerifyOrder()
        {
            bool res = true;

            try
            {
                Client         client = new Client(publickey, privatekey, mode);
                PlaceOrderInfo order  = new PlaceOrderInfo(
                    "12",
                    "M4 C# SDK",
                    180,
                    "Eduardo Aguilar",
                    "*****@*****.**"
                    );
                NewOrderInfo neworder = client.api.placeOrder(order);
                CpOrderInfo  response = client.api.verifyOrder(neworder.getId());
                res = !response.getId().Equals(null);
            }
            catch (Exception e)
            {
                res = false;
            }

            Assert.IsTrue(res);
        }
Exemplo n.º 2
0
        public void TestServiceSms()
        {
            bool res = true;

            try
            {
                Client         client = new Client(publickey, privatekey, mode);
                PlaceOrderInfo order  = new PlaceOrderInfo(
                    "12",
                    "M4 C# SDK",
                    180,
                    "Eduardo Aguilar",
                    "*****@*****.**"
                    );
                NewOrderInfo neworder = client.api.placeOrder(order);
                SmsInfo      response = client.api.sendSmsInstructions(phone_number, neworder.getId());
                res = !response.getType().Equals("");
            }
            catch (Exception e)
            {
                res = false;
            }

            Assert.IsTrue(res);
        }
Exemplo n.º 3
0
        public ActionResult PlaceOrder(PlaceOrderInfo model, string placeOrder, string placeOrderAndCreateAccount, string validateDelivery, string validateInvoice)
        {
            string group = null;

            if (placeOrder != null)
            {
                group = "Critical AboutYou DeliveryAddress InvoiceAddress";
            }
            if (placeOrderAndCreateAccount != null)
            {
                group = "Critical AboutYou CreateAccount DeliveryAddress InvoiceAddress";
            }
            if (validateDelivery != null)
            {
                group = "DeliveryAddress";
            }
            if (validateInvoice != null)
            {
                group = "InvoiceAddress";
            }
            if ((group != null && ModelState.IsGroupValid(model, group)) || (group == null && ModelState.IsValid))
            {
                ViewBag.Groups = group;
                return(View("ValidationSuccess"));
            }
            return(View(model));
        }
Exemplo n.º 4
0
        public void TestServicePlaceOrderFarmaciaABC()
        {
            bool res = true;

            try
            {
                Client         client = new Client(publickey, privatekey, mode);
                PlaceOrderInfo order  = new PlaceOrderInfo(
                    "12",
                    "M4 C# SDK",
                    180,
                    "Eduardo Aguilar",
                    "*****@*****.**",
                    "FARMACIA_ABC"
                    );
                NewOrderInfo neworder = client.api.placeOrder(order);
                res = !neworder.getId().Equals(null);
            }
            catch (Exception e)
            {
                res = false;
            }

            Assert.IsTrue(res);
        }
Exemplo n.º 5
0
        //
        // GET: /Checkout/

        public ActionResult PlaceOrder()
        {
            var or = new PlaceOrderInfo();

            or.ShoppingBasketKey = Guid.NewGuid().ToString();
            ViewData.Model       = or;
            return(View());
        }
Exemplo n.º 6
0
        /**
         * Genera ordenes de compra
         *
         * @param PlaceOrderInfo info   Objeto con la informacion de la orden de compra
         * @return NewOrderInfo
         */
        public NewOrderInfo placeOrder(PlaceOrderInfo info)
        {
            Validations.validateGateway(this.client);

            var append =
                "order_id=" + info.order_id +
                "&order_price=" + info.order_price +
                "&order_name=" + info.order_name +
                "&customer_name=" + info.customer_name +
                "&customer_email=" + info.customer_email +
                "&image_url=" + info.image_url +
                "&payment_type=" + info.payment_type +
                "&app_client_name" + info.app_client_name +
                "&app_client_version" + info.app_client_version;

            var uri = this.client.getUri() + "charges/";

            var postUrl = new StringBuilder();

            postUrl.Append(append);

            byte[] formBytes = ASCIIEncoding.Default.GetBytes(postUrl.ToString());

            Uri requestUri = null;

            Uri.TryCreate(uri, UriKind.Absolute, out requestUri);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);

            request.Method = "POST";

            request.ContentType = "application/x-www-form-urlencoded";
            request.Headers.Add("Authorization", string.Concat("Basic ",
                                                               (Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}", this.client.getFullAuth()))))));

            foreach (KeyValuePair <string, string> entry in this.headers)
            {
                request.Headers.Add(entry.Key, entry.Value);
            }

            using (Stream postStream = request.GetRequestStream())
            {
                postStream.Write(formBytes, 0, formBytes.Length);
            }

            HttpWebResponse response   = (HttpWebResponse)request.GetResponse();
            Stream          respStream = response.GetResponseStream();

            var reader = new StreamReader(respStream);
            var resp   = reader.ReadToEnd();

            var obj = Factory.Factory.newOrderInfo(resp);

            return(obj);
        }
Exemplo n.º 7
0
        protected string CreateOrdersForCustomers(OrderGeneratorSettings settings, List <ProductInfo> productsAndVariations, List <Customer> customers)
        {
            Stopwatch tmr = Stopwatch.StartNew();

            Random rnd = new Random(DateTime.Now.Millisecond);

            for (int i = 0; i < settings.NumberOfOrdersToGenerate; i++)
            {
                // First get customer
                int      randomCustomerIndex = rnd.Next(0, customers.Count - 1);
                Customer customer            = customers[randomCustomerIndex];

                int            dayNumber = rnd.Next(1, DateTime.Now.DayOfYear);
                DateTime       orderDate = new DateTime(DateTime.Now.Year, 1, 1).AddDays(dayNumber).AddHours(rnd.Next(1, 23)).AddMinutes(rnd.Next(0, 59));
                PlaceOrderInfo orderInfo = new PlaceOrderInfo
                {
                    CustomerId = Guid.Parse(customer.PrimaryKeyId),
                    OrderDate  = orderDate
                };

                // How many line items can we add?
                int numLineItems = rnd.Next(1, settings.MaximumLineItemsPerOrder);
                for (int j = 0; j < numLineItems; j++)
                {
                    int                    next          = rnd.Next(0, productsAndVariations.Count);
                    ProductInfo            productInfo   = productsAndVariations[next];
                    PlaceOrderLineItemInfo orderLineItem = new PlaceOrderLineItemInfo
                    {
                        Count              = 1,
                        ProductEntryCode   = productInfo.Code,
                        VariationEntryCode = productInfo.Variations[rnd.Next(0, productInfo.Variations.Count - 1)].Code
                    };
                    orderInfo.Products.Add(orderLineItem);
                }

                OrderController oc          = new OrderController();
                int             orderNumber = oc.CreateOrder(orderInfo);
                _log.DebugFormat("Order for {0} on {1}: {2} products. Ordernumber: {3}",
                                 customer.FullName, orderInfo.OrderDate, orderInfo.Products.Count, orderNumber);
            }
            tmr.Stop();

            string info = string.Format("Created {0} orders for random customers in {1}", settings.NumberOfOrdersToGenerate, tmr.Elapsed);

            _log.Debug(info);
            return(info);
        }
Exemplo n.º 8
0
        protected int DoOneClickBuy(PlaceOrderInfo orderInfo)
        {
            if (orderInfo == null)
            {
                throw new ArgumentNullException("orderInfo");
            }
            if (orderInfo.Products.Count == 0)
            {
                throw new ArgumentNullException("orderInfo.Products");
            }

            CartHelper ch = new CartHelper("OneClickBuy", orderInfo.CustomerId);

            foreach (PlaceOrderLineItemInfo lineItemInfo in orderInfo.Products)
            {
                Entry ownerProduct = CatalogContext.Current.GetCatalogEntry(lineItemInfo.ProductEntryCode,
                                                                            new CatalogEntryResponseGroup(
                                                                                CatalogEntryResponseGroup.ResponseGroup
                                                                                .CatalogEntryFull));
                if (ownerProduct == null)
                {
                    throw new ArgumentNullException("Cannot load Product with code: " +
                                                    lineItemInfo.ProductEntryCode);
                }

                Entry sku = CatalogContext.Current.GetCatalogEntry(lineItemInfo.VariationEntryCode,
                                                                   new CatalogEntryResponseGroup(
                                                                       CatalogEntryResponseGroup.ResponseGroup
                                                                       .CatalogEntryFull));
                if (sku == null)
                {
                    throw new ArgumentNullException("Cannot load Variation with code: " +
                                                    lineItemInfo.VariationEntryCode);
                }

                sku.ParentEntry = ownerProduct;

                ch.AddEntry(sku, lineItemInfo.Count, fixedQuantity: true);
            }

            int orderId = PlaceOneClickOrder(ch, orderInfo);

            return(orderId);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Places the order.
        /// </summary>
        /// <returns>The order.</returns>
        /// <param name="order">Order.</param>
        ///
        /// <remarks>
        /// Author: Eduardo Aguilar <*****@*****.**>.
        /// </remarks>
        public NewOrderInfo PlaceOrder(PlaceOrderInfo order)
        {
            var data = new Dictionary <string, object>
            {
                { "order_id", order.order_id },
                { "order_name", order.order_name },
                { "order_price", order.order_price.ToString(CultureInfo.InvariantCulture) },
                { "customer_name", order.customer_name },
                { "customer_email", order.customer_email },
                { "payment_type", order.payment_type },
                { "currency", order.currency },
                { "expiration_time", order.expiration_time },
                { "image_url", order.image_url },
                { "app_client_name", order.app_client_name },
                { "app_client_version", order.app_client_version }
            };


            var response = Request.Post(_client.DeployUri + "charges/", data, getAuth());

            return(Factory.Factory.NewOrderInfo(response));
        }
Exemplo n.º 10
0
        private int PlaceOneClickOrder(CartHelper cartHelper, PlaceOrderInfo orderInfo)
        {
            Cart cart = cartHelper.Cart;

            CustomerContact currentContact = CustomerContext.Current.GetContactById(orderInfo.CustomerId);

            if (currentContact == null)
            {
                throw new NullReferenceException("Cannot load customer with id: " + orderInfo.CustomerId.ToString());
            }

            OrderGroupWorkflowManager.RunWorkflow(cart, OrderGroupWorkflowManager.CartCheckOutWorkflowName);
            cart.CustomerId   = orderInfo.CustomerId;
            cart.CustomerName = currentContact.FullName;

            if (currentContact.PreferredBillingAddress != null)
            {
                OrderAddress orderBillingAddress = StoreHelper.ConvertToOrderAddress(currentContact.PreferredBillingAddress);
                int          billingAddressId    = cart.OrderAddresses.Add(orderBillingAddress);
                cart.OrderForms[0].BillingAddressId = orderBillingAddress.Name;
            }
            if (currentContact.PreferredShippingAddress != null)
            {
                int shippingAddressId = cart.OrderAddresses.Add(StoreHelper.ConvertToOrderAddress(currentContact.PreferredShippingAddress));
            }

            if (cart.OrderAddresses.Count == 0)
            {
                CustomerAddress address = currentContact.ContactAddresses.FirstOrDefault();
                if (address != null)
                {
                    int defaultAddressId = cart.OrderAddresses.Add(StoreHelper.ConvertToOrderAddress(address));
                    cart.OrderForms[0].BillingAddressId = address.Name;
                }
            }

            var po = cart.SaveAsPurchaseOrder();

            // These does not persist
            po.OrderForms[0].Created  = orderInfo.OrderDate;
            po.OrderForms[0].Modified = orderInfo.OrderDate;
            po.Created  = orderInfo.OrderDate;
            po.Modified = orderInfo.OrderDate;

            currentContact.LastOrder = po.Created;
            currentContact.SaveChanges();

            // Add note to purchaseOrder
            OrderNotesManager.AddNoteToPurchaseOrder(po, "", OrderNoteTypes.System, orderInfo.CustomerId);
            // OrderNotesManager.AddNoteToPurchaseOrder(po, "Created: " + po.Created, OrderNoteTypes.System, orderInfo.CustomerId);

            po.AcceptChanges();

            SetOrderDates(po.Id, orderInfo.OrderDate);

            //Add do Find index
            // OrderHelper.CreateOrderToFind(po);

            // Remove old cart
            cart.Delete();
            cart.AcceptChanges();
            return(po.Id);
        }
Exemplo n.º 11
0
 public int CreateOrder(PlaceOrderInfo orderInfo)
 {
     return(DoOneClickBuy(orderInfo));
 }