public GenericResult <List <poolingEvent> > Sales(string token, string merchantId)
        {
            var result = new GenericResult <List <poolingEvent> >();

            //var parametros = "merchantId=" + merchantId;

            var url     = string.Format("{0}merchants/{1}/sales", _urlBase, merchantId);
            var client  = new RestClientBase(url);
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", string.Format("Bearer {0}", token));
            IRestResponse response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                result.Result   = JsonConvert.DeserializeObject <List <poolingEvent> >(response.Content);
                result.Success  = true;
                result.Json     = response.Content;
                result.Request  = client.requestResult;
                result.Response = client.responsetResult;
            }
            else if (response.StatusCode == System.Net.HttpStatusCode.NotFound || response.StatusCode == System.Net.HttpStatusCode.NoContent)
            {
                result.Result  = new List <poolingEvent>();
                result.Success = true;
            }
            else
            {
                result.Message = response.StatusDescription;
            }
            result.StatusCode = response.StatusCode;
            return(result);
        }
        ///// <summary>
        ///// Informa ao IFood que o pedido foi integrado pelo e-PDV.
        ///// Integração significa que o e-PDV foi capaz de realizar o parse do pedido e integrar em seu sistema.
        ///// </summary>
        ///// <param name="token"></param>
        ///// <param name="reference"></param>
        ///// <returns></returns>
        //public GenericSimpleResult OrdersIntegration(string token, string reference)
        //{
        //    var data = new { };

        //    var result = new GenericSimpleResult();

        //    var url = string.Format("{0}order/{1}/{2}/{3}/{4}", _urlBase, Constants.VERSION_1, Constants.URL_ORDER, reference, Constants.URL_ORDER_INTEGRATION);
        //    var client = new RestClient(url);
        //    var request = new RestRequest(Method.POST);
        //    request.AddHeader("Authorization", string.Format("bearer {0}", token));
        //    request.AddParameter("application/json", data, ParameterType.RequestBody);
        //    IRestResponse response = client.Execute(request);
        //    if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
        //    {
        //        result.Success = true;
        //    }
        //    else
        //    {
        //        result.Message = response.StatusDescription;
        //    }

        //    return result;
        //}

        /// <summary>
        /// Informa ao IFood que o pedido foi confirmado pelo e-PDV.
        /// </summary>
        /// <param name="token"></param>
        /// <param name="reference"></param>
        /// <returns></returns>
        public GenericSimpleResult OrdersConfirmation(string token, string reference)
        {
            var data   = new { };
            var result = new GenericSimpleResult();

            var url     = string.Format("{0}order/{1}/{2}/{3}/{4}", _urlBase, Constants.VERSION_1, Constants.URL_ORDER, reference, Constants.URL_ORDER_CONFIRM);
            var client  = new RestClientBase(url);
            var request = new RestRequest(Method.POST);

            request.AddHeader("Authorization", string.Format("Bearer {0}", token));
            request.AddParameter("application/json", data, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                result.Success = true;
            }
            else
            {
                result.Message = response.StatusDescription;
            }
            result.Request    = client.requestResult;
            result.Response   = client.responsetResult;
            result.StatusCode = response.StatusCode;

            return(result);
        }
        /// <summary>
        /// Geralmente, após o e-PDV receber um evento com o código 'PLACED', é necessário obter os detalhes do pedido.
        /// Neste cenário, o campo correlationId do evento refere-se à referência do pedido e deve ser fornecido a este endpoint.
        /// </summary>
        /// <param name="token"></param>
        /// <param name="reference"></param>
        /// <returns></returns>
        public GenericResult <order> Orders(string token, string reference)
        {
            var result  = new GenericResult <order>();
            var url     = string.Format("{0}order/{1}/{2}/{3}", _urlBase, Constants.VERSION_1, Constants.URL_ORDER, reference);
            var client  = new RestClientBase(url);
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", string.Format("bearer {0}", token));
            var response = client.Execute <RestObject>(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                result.Result   = JsonConvert.DeserializeObject <order>(response.Content);
                result.Success  = true;
                result.Json     = response.Content;
                result.Request  = client.requestResult;
                result.Response = client.responsetResult;
            }
            else
            {
                result.Message = response.StatusDescription;
            }

            result.Request    = client.requestResult;
            result.Response   = client.responsetResult;
            result.StatusCode = response.StatusCode;
            return(result);
        }
        public GenericResult <List <status> > Status(string token, string merchantGuid)
        {
            var result = new GenericResult <List <status> >();

            var url     = string.Format("{0}merchant/v1.0/merchants/{1}/status/", _urlBase, merchantGuid);
            var client  = new RestClientBase(url);
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", string.Format("Bearer {0}", token));
            IRestResponse response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                result.Result   = JsonConvert.DeserializeObject <List <status> >(response.Content);
                result.Success  = true;
                result.Json     = response.Content;
                result.Request  = client.requestResult;
                result.Response = client.responsetResult;
            }
            else
            {
                var retorno = JsonConvert.DeserializeObject <error_return>(response.Content);
                if (retorno != null && retorno.error != null)
                {
                    result.Message = retorno.error.message;
                }
                else
                {
                    result.Message = response.Content;
                }
            }

            result.StatusCode = response.StatusCode;
            return(result);
        }
Beispiel #5
0
        public GenericResult <retornoGeneric <token_data> > OathToken(string username, string password)
        {
            var result = new GenericResult <retornoGeneric <token_data> >();

            try
            {
                var data = new
                {
                    username = username,
                    password = password
                };

                var url = _urlBase + Constants.URL_TOKEN;

                var client = new RestClientBase(url);
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", JsonConvert.SerializeObject(data), ParameterType.RequestBody);

                IRestResponse response = client.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    result.Result = JsonConvert.DeserializeObject <retornoGeneric <token_data> >(response.Content);
                    if (result.Result.success)
                    {
                        result.Success = true;
                    }
                    else
                    {
                        result.Message = result.Result.message;
                    }
                }
                else
                {
                    result.Message = response.StatusDescription + $" => {response.Content}";
                }

                result.Json       = response.Content;
                result.Request    = client.requestResult;
                result.Response   = client.responsetResult;
                result.StatusCode = response.StatusCode;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            return(result);
        }
Beispiel #6
0
        public GenericSimpleResult Acknowledgment(string token, List <int> ids)
        {
            var result = new GenericSimpleResult();

            try
            {
                var data = new
                {
                    ids = ids
                };

                var url     = string.Format("{0}{1}", _urlBase, Constants.URL_Acknowledgment);
                var client  = new RestClientBase(url);
                var request = new RestRequest(Method.POST);
                request.AddHeader("Authorization", string.Format("Bearer {0}", token));
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", JsonConvert.SerializeObject(data), ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var retorno = JsonConvert.DeserializeObject <retorno>(response.Content);
                    if (retorno.success)
                    {
                        result.Success = true;
                    }
                    else
                    {
                        result.Message = retorno.message;
                    }
                }
                else
                {
                    result.Message = response.Content;
                }

                result.Json       = response.Content;
                result.Request    = client.requestResult;
                result.Response   = client.responsetResult;
                result.StatusCode = response.StatusCode;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(result);
        }
Beispiel #7
0
        private PortalToken RequestToken()
        {
            long account = GetAccount();
            Guid device  = GetDevice();

            var client  = new RestClientBase(GetTokenUri());
            var request = new RestRequest(Method.POST);

            request.AddHeader("Cache-Control", "no-cache");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("Account", account);
            request.AddParameter("Device", device);

            var response = client.Execute(request);

            return(JsonConvert.DeserializeObject <PortalToken>(response.Content, new JsonSerializerSettings
            {
                ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
            }));
        }
Beispiel #8
0
        public GenericResult <retornoGeneric <order_result> > Orders(string token, string merchantid)
        {
            var result = new GenericResult <retornoGeneric <order_result> >();

            try
            {
                var url     = string.Format("{0}{1}/{2}", _urlBase, Constants.URL_ORDERS, merchantid);
                var client  = new RestClientBase(url);
                var request = new RestRequest(Method.GET);
                request.AddHeader("Authorization", string.Format("Bearer {0}", token));
                var response = client.Execute <RestObject>(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    result.Result = JsonConvert.DeserializeObject <retornoGeneric <order_result> >(response.Content);
                    if (result.Result.success)
                    {
                        result.Success = true;
                    }
                    else
                    {
                        result.Message = result.Result.message;
                    }
                }
                else
                {
                    result.Message = response.StatusDescription + " -> " + response.Content;
                }

                result.Json       = response.Content;
                result.Request    = client.requestResult;
                result.Response   = client.responsetResult;
                result.StatusCode = response.StatusCode;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            return(result);
        }
Beispiel #9
0
        private long GetAccountFromService(Guid device)
        {
            Logger.Info("Requesting Account number from the api.");

            var client  = new RestClientBase(GetAccountUri());
            var request = new RestRequest(Method.POST);

            request.AddHeader("Cache-Control", "no-cache");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("Device", device);

            try
            {
                return(Convert.ToInt64(client.Execute(request).Content));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                throw new UserFriendlyException("Unable to get the Account number from the api. Please manually enter the Account number through the CLI.");
            }
        }
        /// <summary>
        /// Obtém todos os eventos ainda não recebidos.
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public GenericResult <List <poolingEvent> > EventPolling(string token, string merchantid)
        {
            var result = new GenericResult <List <poolingEvent> >();

            var url     = string.Format("{0}order/{1}/{2}", _urlBase, Constants.VERSION_1, Constants.URL_EVENT_POOLING + "?types=COL,CAN");
            var client  = new RestClientBase(url);
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", string.Format("Bearer {0}", token));
            if (!string.IsNullOrEmpty(merchantid))
            {
                request.AddHeader("x-polling-merchants", merchantid);
            }
            IRestResponse response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                result.Result  = JsonConvert.DeserializeObject <List <poolingEvent> >(response.Content);
                result.Success = true;
                result.Json    = response.Content;
            }
            else if (response.StatusCode == System.Net.HttpStatusCode.NotFound || response.StatusCode == System.Net.HttpStatusCode.NoContent)
            {
                result.Result  = new List <poolingEvent>();
                result.Success = true;
            }
            else
            {
                result.Message = response.StatusDescription;
            }

            result.StatusCode = response.StatusCode;
            result.Request    = client.requestResult;
            result.Response   = client.responsetResult;

            return(result);
        }