Exemplo n.º 1
0
        public static async Task <ResultAgent> GetAgetByEmailAsync(string userCEN, Uri url)
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(url, $"api/v1/resources/agents/?email={userCEN}");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri); // GET

                    if (res != null)
                    {
                        Agent agent = JsonConvert.DeserializeObject <Agent>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        if (agent.Results.Count == 1)
                        {
                            return(agent.Results[0]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
        public static async Task <ResultPaymentExecution> GetPayId(ResultInstruction instruction)
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"/api/v1/resources/payment-execution-payment-instructions/?instruction={instruction.Id}");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri);  // GET

                    if (res != null)
                    {
                        PaymentExecution p = JsonConvert.DeserializeObject <PaymentExecution>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        if (p.Count == 1)
                        {
                            return(p.Results[0]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 3
0
        public static async Task <List <ResultPaymentMatrix> > GetPaymentMatrixAsync(int year)
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/payment-matrices/?created_after={year - 1}-12-31&created_before={year + 1}-01-01");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri); // GET

                    if (res != null)
                    {
                        PaymentMatrix p = JsonConvert.DeserializeObject <PaymentMatrix>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        return(p.Results);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 4
0
        public static async Task <List <ResultPaymentMatrix> > GetPaymentMatrixByBillingWindowIdAsync(ResultBillingWindow window)
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/payment-matrices/?billing_window={window.Id}");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri); // GET

                    if (res != null)
                    {
                        PaymentMatrix p = JsonConvert.DeserializeObject <PaymentMatrix>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        foreach (ResultPaymentMatrix item in p.Results)
                        {
                            item.BillingWindow = window;
                        }
                        return(p.Results);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 5
0
        public static async Task <ResultInstruction> GetInstructionDebtorAsync(ResultPaymentMatrix matrix, ResultParticipant participant, ResultParticipant userPart)
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/instructions/?payment_matrix={matrix.Id}&creditor={participant.Id}&debtor={userPart.Id}&status=Publicado");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri);

                    if (res != null)
                    {
                        Instruction instruction = JsonConvert.DeserializeObject <Instruction>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        if (instruction.Count > 0)
                        {
                            instruction.Results[0].PaymentMatrix       = matrix;
                            instruction.Results[0].ParticipantCreditor = participant;
                            instruction.Results[0].ParticipantDebtor   = userPart;
                            return(instruction.Results[0]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 6
0
        public static async Task <List <ResultPaymentMatrix> > GetPaymentMatrixAsync(DateTime date)
        {
            DateTime createdBefore = date.AddMonths(1);

            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/payment-matrices/?created_after={string.Format("{0:yyyy-MM-dd}", date)}&created_before={string.Format("{0:yyyy-MM-dd}", createdBefore)}");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri); // GET

                    if (res != null)
                    {
                        PaymentMatrix p = JsonConvert.DeserializeObject <PaymentMatrix>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        return(p.Results);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 7
0
        public static async Task <ResultBillingWindow> GetBillingWindowByIdAsync(ResultPaymentMatrix matrix)
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/billing-windows/?id={matrix.BillingWindowId}");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri); // GET

                    if (res != null)
                    {
                        BillingWindow b = JsonConvert.DeserializeObject <BillingWindow>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        return(b.Results[0]);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 8
0
        public static async Task <ResultParticipant> GetParticipantByRutAsync(string rut)
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/participants/?rut={rut}");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri); // GET

                    if (res != null)
                    {
                        Participant p = JsonConvert.DeserializeObject <Participant>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        if (p.Count > 0)
                        {
                            return(p.Results[0]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 9
0
        public static async Task <List <ResultBilingType> > GetBilinTypesAsync()
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/billing-types");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri); // GET

                    if (res != null)
                    {
                        BilingType bilingType = JsonConvert.DeserializeObject <BilingType>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        return(bilingType.Results);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 10
0
        public static async Task <ResultDte> GetDteAsync(Detalle detalle, bool isCreditor)
        {
            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/dtes/?reported_by_creditor={isCreditor}&folio={detalle.Folio}&instruccion={detalle.Instruction.Id}&creditor={detalle.Instruction.Creditor}");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri);  // GET

                    if (res != null)
                    {
                        Dte p = JsonConvert.DeserializeObject <Dte>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        if (p.Count == 1)
                        {
                            return(p.Results[0]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 11
0
        public static async Task <ResultBillingWindow> GetBillingWindowByNaturalKeyAsync(DTEDefTypeDocumentoReferencia referencia)
        {
            TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
            string   r1 = referencia.RazonRef.Substring(0, referencia.RazonRef.IndexOf(']') + 1).TrimStart();
            string   r2 = referencia.RazonRef.Substring(0, referencia.RazonRef.IndexOf(']', referencia.RazonRef.IndexOf(']') + 1) + 1);

            r2 = r2.Substring(r2.IndexOf(']') + 1);

            // Controlling lower & upper
            string rznRef = ti.ToTitleCase(r2.ToLower());

            try
            {
                using (CustomWebClient wc = new CustomWebClient())
                {
                    Uri uri = new Uri(Properties.Settings.Default.UrlCen, $"api/v1/resources/billing-windows/?natural_key={r1 + rznRef}");
                    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string res = await wc.DownloadStringTaskAsync(uri);

                    if (res != null)
                    {
                        BillingWindow b = JsonConvert.DeserializeObject <BillingWindow>(res, new JsonSerializerSettings {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        if (b.Count > 0)
                        {
                            return(b.Results[0]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }