Ejemplo n.º 1
0
        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="order"></param>
        /// <param name="withoutListCheck"></param>
        /// <returns></returns>
        public async Task <Order> UpdateOrder(Order order, bool withoutListCheck = false)
        {
            if (!withoutListCheck)
            {
                if (Orders.TryGetValue(order.order_key, out var ord))
                {
                    var o = await WooCommerceHelpers.UpdateOrder(order,
                                                                 WooCommerceHelpers.GetFullAPIUrl(
                                                                     $"orders/{ord.id}", WooCommerceStoreUrl, WooCommerceStoreAPIKey, WooCommerceStoreSecret)
                                                                 );

                    ord.Fill(o);
                    return(ord);
                }
                else
                {
                    throw new Exception("Cannot find the order.");
                }
            }
            else
            {
                var o = await WooCommerceHelpers.UpdateOrder(order,
                                                             WooCommerceHelpers.GetFullAPIUrl(
                                                                 $"orders/{order.id}", WooCommerceStoreUrl, WooCommerceStoreAPIKey, WooCommerceStoreSecret)
                                                             );

                order.Fill(o);
                return(order);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="orderkey"></param>
        /// <param name="txid"></param>
        /// <returns></returns>
        public async Task <Order> UpdateOrderTxId(string orderkey, string txid)
        {
            if (Orders.TryGetValue(orderkey, out var ord))
            {
                ord.transaction_id = txid;
                var order = await WooCommerceHelpers.UpdateOrder(ord,
                                                                 WooCommerceHelpers.GetFullAPIUrl(
                                                                     $"orders/{ord.id}", WooCommerceStoreUrl, WooCommerceStoreAPIKey, WooCommerceStoreSecret)
                                                                 );

                if (order != null)
                {
                    ord = order;
                }
                return(order);
            }
            else
            {
                throw new Exception("Cannot find the order.");
            }
        }
Ejemplo n.º 3
0
        /*
         * public async Task<string> StartRefreshingData(int interval = 10000)
         * {
         *  await ReLoadProducts();
         *  await ReLoadOrders();
         *
         *  var minorRefresh = 5;
         *  var firstLoad = true;
         *  // todo cancelation token
         *  _ = Task.Run(async () =>
         *  {
         *      IsRefreshingRunning = true;
         *      Stopwatch st = new Stopwatch();
         *
         *      while (true)
         *      {
         *          long reduceTime = 0;
         *          try
         *          {
         *              if (firstLoad)
         *              {
         *                  try
         *                  {
         *                      //await ReloadCategories(); //todo
         *                      firstLoad = false;
         *                  }
         *                  catch (Exception ex)
         *                  {
         *                      //todo
         *                  }
         *              }
         *              else
         *              {
         *                  await ReLoadProducts();
         *                  await ReLoadOrders();
         *              }
         *
         *              if (!string.IsNullOrEmpty(ConnectedDogeAccountAddress))
         *              {
         *                  await CheckDogePayments();
         *              }
         *              if (AllowDispatchNFTOrders)
         *              {
         *                  await CheckReceivedPaymentsToDispatch();
         *                  st.Start();
         *                  await SendOrdersToCustomer();
         *                  st.Stop();
         *                  var spenttime = st.ElapsedMilliseconds;
         *                  st.Reset();
         *                  if (spenttime < interval)
         *                      reduceTime = spenttime;
         *                  else
         *                      reduceTime = interval;
         *              }
         *
         *              minorRefresh--;
         *              if (minorRefresh < 0)
         *              {
         *                  minorRefresh = 5;
         *                  //await ReloadCategories(); //todo
         *              }
         *              Refreshed?.Invoke(this, null);
         *          }
         *          catch (Exception ex)
         *          {
         *              Console.WriteLine("Cannot process standard cycle. " + ex.Message);
         *              //await InvokeErrorEvent(ex.Message, "Unknown Error During Refreshing Data");
         *          }
         *
         *          await Task.Delay(interval - (int)reduceTime);
         *      }
         *      IsRefreshingRunning = false;
         *  });
         *
         *  return await Task.FromResult("RUNNING");
         * }
         */

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="orderkey"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public async Task <Order> UpdateOrderStatus(string orderkey, string status)
        {
            if (Orders.TryGetValue(orderkey, out var ord))
            {
                var stat = (OrderStatus)Enum.Parse(typeof(OrderStatus), status);
                ord.statusclass = stat;
                var order = await WooCommerceHelpers.UpdateOrder(ord,
                                                                 WooCommerceHelpers.GetFullAPIUrl(
                                                                     $"orders/{ord.id}", WooCommerceStoreUrl, WooCommerceStoreAPIKey, WooCommerceStoreSecret)
                                                                 );

                if (order != null)
                {
                    ord = order;
                }
                return(order);
            }
            else
            {
                throw new Exception("Cannot find the order.");
            }
        }