static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // TODO: Substitute the code below with a valid preApproval days interval for your transaction int interval = 10; try { AccountCredentials credentials = PagSeguroConfiguration.GetAccountCredentials(isSandbox); PreApprovalSearchResult result = PreApprovalSearchService.SearchByInterval(credentials, interval); if (result.PreApprovals.Count <= 0) { } foreach (PreApprovalSummary preApproval in result.PreApprovals) { } } catch (PagSeguroServiceException exception) { foreach (ServiceError element in exception.Errors) { } } }
public PessoaAssinatura ConsultaAssintura(string reference) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); var myTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); DateTime initialDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow.AddMonths(-12), myTimeZone); DateTime finalDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, myTimeZone); int maxPageResults = 10; int pageNumber = 1; AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); try { PreApprovalSearchResult result = PreApprovalSearchService.SearchByReference( credentials, reference, initialDate, finalDate, pageNumber, maxPageResults ); var pessoa = new PessoaAssinatura(); var resultAtive = result.PreApprovals.Where(m => m.Status == "ACTIVE").FirstOrDefault(); if (resultAtive != null) { pessoa.Codigo = 0; pessoa.CodigoPessoa = 0; pessoa.CodigoAssinatura = resultAtive.Code; pessoa.Status = resultAtive.Status; pessoa.DataAssinatura = resultAtive.Date; return(pessoa); } else { var resultNoAtive = result.PreApprovals.OrderByDescending(d => d.Date).FirstOrDefault(); pessoa.Codigo = 0; pessoa.CodigoPessoa = 0; pessoa.CodigoAssinatura = resultNoAtive.Code; pessoa.Status = resultNoAtive.Status; pessoa.DataAssinatura = resultNoAtive.Date; return(pessoa); } } catch (Exception) { return(null); } }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="result"></param> internal static void Read(XmlReader reader, PreApprovalSearchResult result) { if (reader.IsEmptyElement) { XMLParserUtils.SkipNode(reader); return; } reader.ReadStartElement(PreApprovalSearchResultSerializer.PreApprovalSearchResult); reader.MoveToContent(); while (!reader.EOF) { if (XMLParserUtils.IsEndElement(reader, PreApprovalSearchResultSerializer.PreApprovalSearchResult)) { XMLParserUtils.SkipNode(reader); break; } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case PreApprovalSearchResultSerializer.Date: result.Date = reader.ReadElementContentAsDateTime(); break; case PreApprovalSearchResultSerializer.CurrentPage: result.CurrentPage = reader.ReadElementContentAsInt(); break; case PreApprovalSearchResultSerializer.TotalPages: result.TotalPages = reader.ReadElementContentAsInt(); break; case PreApprovalSummaryListSerializer.PreApprovals: PreApprovalSummaryListSerializer.Read(reader, result.PreApprovals); break; default: XMLParserUtils.SkipElement(reader); break; } } else { XMLParserUtils.SkipNode(reader); } } }
static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // TODO: Substitute the code below with a valid preApproval reference for your transaction String reference = "REF1234"; DateTime initialDate = new DateTime(2015, 10, 01, 00, 00, 0); DateTime finalDate = DateTime.Now; //DateTime finalDate = new DateTime(2015, 10, 15, 11, 35, 15); int maxPageResults = 10; int pageNumber = 1; try { AccountCredentials credentials = PagSeguroConfiguration.GetAccountCredentials(isSandbox); PreApprovalSearchResult result = PreApprovalSearchService.SearchByReference( credentials, reference, initialDate, finalDate, pageNumber, maxPageResults ); if (result.PreApprovals.Count <= 0) { Console.WriteLine("Nenhuma assinatura"); } foreach (PreApprovalSummary preApproval in result.PreApprovals) { Console.WriteLine("Começando listagem de assinaturas - \n"); Console.WriteLine(preApproval.ToString()); Console.WriteLine(" - Terminando listagem de assinaturas "); } Console.ReadKey(); } catch (PagSeguroServiceException exception) { Console.WriteLine(exception.Message + "\n"); foreach (ServiceError element in exception.Errors) { Console.WriteLine(element + "\n"); } Console.ReadKey(); } }
static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // TODO: Substitute the code below with a valid preApproval reference for your transaction String reference = "REF1234"; DateTime initialDate = new DateTime(2015, 10, 01, 00, 00, 0); DateTime finalDate = DateTime.Now; //DateTime finalDate = new DateTime(2015, 10, 15, 11, 35, 15); int maxPageResults = 10; int pageNumber = 1; try { AccountCredentials credentials = PagSeguroConfiguration.GetAccountCredentials(isSandbox); PreApprovalSearchResult result = PreApprovalSearchService.SearchByReference( credentials, reference, initialDate, finalDate, pageNumber, maxPageResults ); if (result.PreApprovals.Count <= 0) { } foreach (PreApprovalSummary preApproval in result.PreApprovals) { } } catch (PagSeguroServiceException exception) { foreach (ServiceError element in exception.Errors) { } } }
private bool IsAssinatura(string reference) { bool valida = false; bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); var myTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); DateTime initialDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow.AddMonths(-4), myTimeZone); DateTime finalDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, myTimeZone); int maxPageResults = 10; int pageNumber = 1; AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); try { PreApprovalSearchResult result = PreApprovalSearchService.SearchByReference( credentials, reference, initialDate, finalDate, pageNumber, maxPageResults ); if (result.PreApprovals.Count >= 1) { var dateMax = result.PreApprovals.Select(m => m.LastEventDate).Max(); var resultMax = result.PreApprovals.Where(m => m.LastEventDate == dateMax).FirstOrDefault(); if (resultMax.Status == "ACTIVE") { valida = true; } } return(valida); } catch (PagSeguroServiceException exception) { return(valida); } }
private static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // TODO: Substitute the code below with a valid preApproval days interval for your transaction int interval = 10; try { AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); PreApprovalSearchResult result = PreApprovalSearchService.SearchByInterval(credentials, interval); if (result.PreApprovals.Count <= 0) { Console.WriteLine("Nenhuma assinatura"); } foreach (PreApprovalSummary preApproval in result.PreApprovals) { Console.WriteLine("Começando listagem de assinaturas - \n"); Console.WriteLine(preApproval.ToString()); Console.WriteLine(" - Terminando listagem de assinaturas "); } Console.ReadKey(); } catch (PagSeguroServiceException exception) { Console.WriteLine(exception.Message + "\n"); foreach (ServiceError element in exception.Errors) { Console.WriteLine(element + "\n"); } Console.ReadKey(); } }
/// <summary> /// Finds a pre-approval with a matching pre-approval reference /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <param name="reference">PagSeguro Pre-Approval Reference</param> /// <param name="initialDate"></param> /// <param name="finalDate">End of date range. Use DateTime.MaxValue to search without an upper boundary.</param> /// <param name="pageNumber">Page number, starting with 1. If passed as 0, it will call the web service to get the default page, also page number 1.</param> /// <param name="resultsPerPage">Results per page, optional.</param> /// <returns></returns> public static PreApprovalSearchResult SearchByReference(Credentials credentials, string reference, DateTime initialDate, DateTime finalDate, int?pageNumber = null, int?resultsPerPage = null) { PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByReference(reference={0}) - begin", reference)); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByReference(credentials, reference, initialDate, finalDate, pageNumber, resultsPerPage))) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { PreApprovalSearchResult preApproval = new PreApprovalSearchResult(); PreApprovalSearchResultSerializer.Read(reader, preApproval); PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByReference(reference={0}) - end {1}", reference, preApproval)); return(preApproval); } } } catch (WebException exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByReference(reference={0}) - error {1}", reference, pse)); throw pse; } }
/// <summary> /// Finds a pre-approval with a matching date interval /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <param name="initialDate"></param> /// <param name="finalDate">End of date range. Use DateTime.MaxValue to search without an upper boundary.</param> /// <param name="pageNumber">Page number, starting with 1. If passed as 0, it will call the web service to get the default page, also page number 1.</param> /// <param name="resultsPerPage">Results per page, optional.</param> /// <returns></returns> public static PreApprovalSearchResult SearchByDate(Credentials credentials, DateTime initialDate, DateTime finalDate, int?pageNumber = null, int?resultsPerPage = null) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByDate(initialDate={0} - finalDate={1}) - begin", initialDate, finalDate)); try { using (var response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByDate(credentials, initialDate, finalDate, pageNumber, resultsPerPage))) { using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result)) { PreApprovalSearchResult preApproval = new PreApprovalSearchResult(); PreApprovalSearchResultSerializer.Read(reader, preApproval); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByDate(initialDate={0} - finalDate={1}) - end {2}", initialDate, finalDate, preApproval)); return(preApproval); } } } catch (System.Exception exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByDate(initialDate={0} - finalDate={1}) - error {2}", initialDate, finalDate, pse)); throw pse; } }
/// <summary> /// Finds a pre-approval with a matching day interval /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <param name="interval">Day interval</param> /// <returns cref="T:Uol.PagSeguro.PreApprovalSearchResult"><c>PreApprovalSearchResult</c></returns> public static PreApprovalSearchResult SearchByInterval(Credentials credentials, int interval) { PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByInterval(Days={0}) - begin", interval)); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByInterval(credentials, interval))) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { PreApprovalSearchResult preApproval = new PreApprovalSearchResult(); PreApprovalSearchResultSerializer.Read(reader, preApproval); PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByInterval(Days={0}) - end {1}", interval, preApproval)); return(preApproval); } } } catch (WebException exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error(string.Format(CultureInfo.InvariantCulture, "PreApprovalSearchService.SearchByInterval(Days={0}) - error {1}", interval, pse)); throw pse; } }