static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); String referenceCode = "REF123"; try { AccountCredentials credentials = PagSeguroConfiguration.GetAccountCredentials(isSandbox); // Realizando a consulta TransactionSearchResult result = TransactionSearchService.SearchByReference(credentials, referenceCode); if (result.Transactions.Count <= 0) { } foreach (TransactionSummary transaction in result.Transactions) { } } catch (PagSeguroServiceException exception) { foreach (ServiceError element in exception.Errors) { } } }
public bool ConsultaBoletoRef(String reference) { bool valida = false; bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); var myTimeZone = TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time"); var dataAtual = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, myTimeZone); try { AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); // Realizando a consulta TransactionSearchResult result = TransactionSearchService.SearchByReference(credentials, reference); foreach (var item in result.Transactions.Where(m => m.LastEventDate.Month == dataAtual.Month && m.LastEventDate.Year == dataAtual.Year)) { if (item.TransactionStatus != 3) { valida = false; } else { valida = true; } } } catch (PagSeguroServiceException exception) { } return(valida); }
static void SearchByDateExample() { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); // Definindo a data de ínicio da consulta DateTime initialDate = new DateTime(2011, 06, 1, 08, 50, 0); // Definindo a data de término da consulta DateTime finalDate = new DateTime(2011, 06, 29, 10, 30, 0); // Definindo o número máximo de resultados por página int maxPageResults = 20; // Definindo o número da página int pageNumber = 1; // Realizando a consulta TransactionSearchResult result = TransactionSearchService.SearchByDate( credentials, initialDate, finalDate, pageNumber, maxPageResults); }
static void TransactionSearchResultExample(TransactionSearchResult transactionSearchResult) { // Obtendo a data da realização da consulta DateTime date = transactionSearchResult.Date; // Obtendo a quantidade de resultados na página int resultsInThisPage = transactionSearchResult.Transactions.Count; // Obtendo a quantidade total de páginas int totalPages = transactionSearchResult.TotalPages; // Obtendo o número da página consultada int currentPage = transactionSearchResult.CurrentPage; // Iterando na lista de transações foreach (TransactionSummary transaction in transactionSearchResult.Transactions) { // Código da transação string code = transaction.Code; // Status da transação var status = transaction.TransactionStatus; // Refência da transação string reference = transaction.Reference; // Valor bruto da transação decimal amount = transaction.GrossAmount; } }
internal static void Read(XmlReader reader, TransactionSearchResult result) { if (reader == null) { throw new ArgumentNullException("reader"); } if (result == null) { throw new ArgumentNullException("result"); } if (reader.IsEmptyElement) { SerializationHelper.SkipNode(reader); return; } reader.ReadStartElement(TransactionSearchResultSerializer.TransactionSearchResult); reader.MoveToContent(); while (!reader.EOF) { if (SerializationHelper.IsEndElement(reader, TransactionSearchResultSerializer.TransactionSearchResult)) { SerializationHelper.SkipNode(reader); break; } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case TransactionSearchResultSerializer.Date: result.Date = reader.ReadElementContentAsDateTime(); break; case TransactionSearchResultSerializer.CurrentPage: result.CurrentPage = reader.ReadElementContentAsInt(); break; case TransactionSearchResultSerializer.TotalPages: result.TotalPages = reader.ReadElementContentAsInt(); break; case TransactionSummaryListSerializer.Transactions: TransactionSummaryListSerializer.Read(reader, result.Items); break; default: SerializationHelper.SkipElement(reader); break; } } else { SerializationHelper.SkipNode(reader); } } }
static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // Definindo a data de ínicio da consulta DateTime initialDate = new DateTime(2015, 10, 14, 08, 50, 0); // Definindo a data de término da consulta DateTime finalDate = DateTime.Now.AddMinutes(-15); // Definindo o número máximo de resultados por página int maxPageResults = 10; // Definindo o número da página int pageNumber = 1; try { AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); // Realizando a consulta TransactionSearchResult result = TransactionSearchService.SearchAbandoned( credentials, initialDate, finalDate, pageNumber, maxPageResults); if (result.Transactions.Count <= 0) { Console.WriteLine("Nenhuma transação abandonada"); } foreach (TransactionSummary transaction in result.Transactions) { Console.WriteLine("Começando listagem de transações abandonadas - \n"); Console.WriteLine(transaction.ToString()); Console.WriteLine(" - Terminando listagem de transações abandonadas"); } Console.ReadKey(); } catch (PagSeguroServiceException exception) { Console.WriteLine(exception.Message + "\n"); foreach (ServiceError element in exception.Errors) { Console.WriteLine(element + "\n"); } Console.ReadKey(); } }
public IList <TransactionSearchResult> SearchTransactions(DateRange dateRange, string invoiceNumber, TransactionSearchType transactionType, SearchScope searchScope, CffCustomer customer, ICffClient client, string batchFrom, string batchTo) { if (invoiceNumber.Length < 3) { throw new ArgumentException("You need more than 3 invoice number to search "); } SqlParameter[] queryBuilder = CreateSqlBuilder(dateRange, invoiceNumber, transactionType, searchScope, customer, client, batchFrom, batchTo); IList <TransactionSearchResult> transactionSearchResults = new List <TransactionSearchResult>(); using (SqlConnection connection = CreateConnection()) { try { using (SqlDataReader dataReader = SqlHelper.ExecuteReader(connection, CommandType.StoredProcedure, "stGetCustomersSearchAll", queryBuilder)) { CleverReader cleverReader = new CleverReader(dataReader); while (!cleverReader.IsNull && cleverReader.Read()) { var transactionSearchResult = new TransactionSearchResult(cleverReader.ToDate("Transdate"), cleverReader.ToDate("factorDate"), cleverReader.ToString("TransRef"), cleverReader.ToDecimal("TransAmount"), cleverReader.ToDecimal("TransBalance"), cleverReader.FromBigInteger("BatchID"), cleverReader.FromBigInteger("CustNum"), cleverReader.FromBigInteger("CustomerID"), cleverReader.ToString("Customer"), cleverReader.FromBigInteger("ClientID"), cleverReader.ToString("ClientName"), cleverReader.ToString("Title"), cleverReader.ToDecimal("Balance"), cleverReader.ToString("BatchFrom"), cleverReader.ToString("BatchTo")); transactionSearchResults.Add(transactionSearchResult); } } } catch (SqlException exception) { if (exception.Message.Contains("Timeout expired")) { throw new CffTimeoutException(exception.Message, exception); } throw; } } Console.WriteLine(transactionSearchResults.Count); return(RecordLimiter.ReturnMaximumRecords(transactionSearchResults)); }
public static List <Transaction> BuscaPorData(int pIdConta, DateTime pDataDesde, out string error, DateTime?pDataAte = null, int?ItemsPerPage = null, string StatusCodes = "") { error = null; try { AccountCredentials credentials = PagSeguroConfiguration.Credentials(false); credentials.Email = pMeuEmail[pIdConta]; credentials.Token = pMeuToken[pIdConta]; var ret = new List <Transaction>(); bool hasResult = true; int page = 1; StatusCodes = (StatusCodes == null || StatusCodes == "" ? "" : "," + StatusCodes + ","); StatusCodes = StatusCodes.Replace(" ", ""); do { TransactionSearchResult result = TransactionSearchService.SearchByDate( credentials, pDataDesde, pDataAte == null ? DateTime.Now : pDataAte.Value, page, ItemsPerPage == null ? iDefaulMaxPerPage : ItemsPerPage.Value); if (result.Transactions.Count > 0) { foreach (TransactionSummary transactionsummary in result.Transactions) { if (StatusCodes == "" || StatusCodes.Contains("," + transactionsummary.TransactionStatus.ToString() + ",")) { Transaction transaction = TransactionSearchService.SearchByCode(credentials, transactionsummary.Code); ret.Add(transaction); } } } page++; hasResult = (page <= result.TotalPages); } while (hasResult); return(ret); } catch (Exception ex) { error = ex.ToString(); return(null); } }
internal static void Read(XmlReader reader, TransactionSearchResult result) { if (reader == null) throw new ArgumentNullException("reader"); if (result == null) throw new ArgumentNullException("result"); if (reader.IsEmptyElement) { SerializationHelper.SkipNode(reader); return; } reader.ReadStartElement(TransactionSearchResultSerializer.TransactionSearchResult); reader.MoveToContent(); while (!reader.EOF) { if (SerializationHelper.IsEndElement(reader, TransactionSearchResultSerializer.TransactionSearchResult)) { SerializationHelper.SkipNode(reader); break; } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case TransactionSearchResultSerializer.Date: result.Date = reader.ReadElementContentAsDateTime(); break; case TransactionSearchResultSerializer.CurrentPage: result.CurrentPage = reader.ReadElementContentAsInt(); break; case TransactionSearchResultSerializer.TotalPages: result.TotalPages = reader.ReadElementContentAsInt(); break; case TransactionSummaryListSerializer.Transactions: TransactionSummaryListSerializer.Read(reader, result.Items); break; default: SerializationHelper.SkipElement(reader); break; } } else { SerializationHelper.SkipNode(reader); } } }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="result"></param> internal static void Read(XmlReader reader, TransactionSearchResult result) { if (reader.IsEmptyElement) { XMLParserUtils.SkipNode(reader); return; } reader.ReadStartElement(TransactionSearchResultSerializer.TransactionSearchResult); reader.MoveToContent(); while (!reader.EOF) { if (XMLParserUtils.IsEndElement(reader, TransactionSearchResultSerializer.TransactionSearchResult)) { XMLParserUtils.SkipNode(reader); break; } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case TransactionSearchResultSerializer.Date: result.Date = reader.ReadElementContentAsDateTime(); break; case TransactionSearchResultSerializer.CurrentPage: result.CurrentPage = reader.ReadElementContentAsInt(); break; case TransactionSearchResultSerializer.TotalPages: result.TotalPages = reader.ReadElementContentAsInt(); break; case TransactionSummaryListSerializer.Transactions: TransactionSummaryListSerializer.Read(reader, result.Transactions); break; default: XMLParserUtils.SkipElement(reader); throw new InvalidOperationException("Unexpected value"); } } else { XMLParserUtils.SkipNode(reader); } } }
protected void TransactionSearchGridViewCustomCallback(object sender, ReportGridViewCustomCallbackEventArgs e) { CallbackParameter parameter = CallbackParameter.Parse(e.Parameters); TransactionSearchResult transaction = (TransactionSearchResult)transactionSearchGridView.GetRow(parameter.RowIndex); RedirectionParameter redirectionParameter = new RedirectionParameter(parameter.FieldName, transaction.ClientId, transaction.CustomerId, transaction.Batch); ISecurityManager securityManager = SecurityManagerFactory.Create(Context.User as CffPrincipal, this.CurrentScope()); Redirector redirector = new Redirector(RedirectionService.Create(this, securityManager)); redirector.Redirect(redirectionParameter); }
static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // Definindo a data de ínicio da consulta DateTime initialDate = new DateTime(2015, 10, 14, 08, 50, 0); // Definindo a data de término da consulta DateTime finalDate = DateTime.Now.AddMinutes(-15); // Definindo o número máximo de resultados por página int maxPageResults = 10; // Definindo o número da página int pageNumber = 1; try { AccountCredentials credentials = PagSeguroConfiguration.GetAccountCredentials(isSandbox); // Realizando a consulta TransactionSearchResult result = TransactionSearchService.SearchAbandoned( credentials, initialDate, finalDate, pageNumber, maxPageResults); if (result.Transactions.Count <= 0) { throw new Exception("Nenhuma transação abandonada"); } foreach (TransactionSummary transaction in result.Transactions) { } } catch (PagSeguroServiceException exception) { foreach (ServiceError element in exception.Errors) { } } }
public async Task <ActionResult <TransactionSearchResponse> > Search([FromQuery] TransactionSearchRequest request) { request.EnsureValidation(); TransactionSearchArgs transactionSearchArgs = new TransactionSearchArgs(); IMediator mediator = Factory.Resolve <IMediator>(); TransactionSearchResult transactionSearchResult = await mediator.Send(new TransactionSearchCommand(transactionSearchArgs)); transactionSearchResult.EnsureSuccess(); TransactionSearchResponse response = new TransactionSearchResponse { Transactions = transactionSearchResult.Results .Select(x => { return(new TransactionLiteView(x)); }) .ToArray() }; return(Ok(response)); }
public int UpdateRecebimentosPeriodoPagSeguro(TransactionSearchResult transactionSearchResult) { int _qtd = 0; string _msg = ""; if (transactionSearchResult != null) { foreach (var t in transactionSearchResult.Transacoes) { // _msg = UpdateRecebimentoPagSeguro(t); _msg = SaveDadosTransacaoPagSeguro(t); if (_msg.Equals("Atualização realizada com sucesso")) { _qtd++; } } } return(_qtd); }
public TransactionSearchResult ConsultaTransacaoDate(DateTime InitialDate, DateTime FinalDate) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); int maxPageResults = 1000; int pageNumber = 1; TransactionSearchResult result = TransactionSearchService.SearchByDate( credentials, InitialDate, FinalDate, pageNumber, maxPageResults); return(result); }
private static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); string referenceCode = "REF123"; try { AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); // Realizando a consulta TransactionSearchResult result = TransactionSearchService.SearchByReference(credentials, referenceCode); if (result.Transactions.Count <= 0) { Console.WriteLine("Nenhuma transação encontrada com a referência " + referenceCode); } foreach (TransactionSummary transaction in result.Transactions) { Console.WriteLine("Começando listagem de transações - \n"); Console.WriteLine(transaction.ToString()); Console.WriteLine(" - Terminando listagem de transações "); } Console.ReadKey(); } catch (PagSeguroServiceException exception) { Console.WriteLine(exception.Message + "\n"); foreach (ServiceError element in exception.Errors) { Console.WriteLine(element + "\n"); } Console.ReadKey(); } }
/// <summary> /// Finds abandoned transactions /// </summary> /// <param name="credentials">PagSeguro credentials. Required.</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 TransactionSearchResult SearchAbandoned(Credentials credentials, DateTime initialDate, DateTime finalDate, int?pageNumber = null, int?resultsPerPage = null) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchAbandoned(initialDate={0}, finalDate={1}) - begin", initialDate, finalDate)); try { using (var response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlAbandoned(credentials, initialDate, finalDate, pageNumber, resultsPerPage))) { using (XmlReader reader = XmlReader.Create(response.Content.ReadAsStreamAsync().Result)) { TransactionSearchResult result = new TransactionSearchResult(); TransactionSearchResultSerializer.Read(reader, result); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchAbandoned(initialDate={0}, finalDate={1}) - end {2}", initialDate, finalDate, result)); return(result); } } } catch (System.Exception exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException(exception); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchAbandoned(initialDate={0}, finalDate={1}) - error {2}", initialDate, finalDate, pse)); throw pse; } }
/// <summary> /// Common implmentation of all SearchByDate methods /// </summary> /// <param name="credentials">PagSeguro credentials. Required.</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> private static TransactionSearchResult SearchByDateCore(Credentials credentials, DateTime initialDate, DateTime finalDate, int pageNumber, int resultsPerPage) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - begin", initialDate, finalDate)); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByDate(credentials, initialDate, finalDate, pageNumber, resultsPerPage))) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { TransactionSearchResult result = new TransactionSearchResult(); TransactionSearchResultSerializer.Read(reader, result); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - end {2}", initialDate, finalDate, result)); return(result); } } } catch (WebException exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - error {2}", initialDate, finalDate, pse)); throw pse; } }
/// <summary> /// Finds a transaction with a matching reference code /// </summary> /// <param name="credentials">PagSeguro credentials</param> /// <param name="reference">Reference</param> /// <returns></returns> public static TransactionSearchResult SearchByReference(Credentials credentials, string reference) { PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - begin", reference)); try { using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpGetConnection(BuildSearchUrlByReference(credentials, reference), credentials.IsSandbox())) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { TransactionSearchResult result = new TransactionSearchResult(); TransactionSearchResultSerializer.Read(reader, result); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - end", reference)); return(result); } } } catch (WebException exception) { PagSeguroServiceException pse = HttpURLConnectionUtil.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByReference(reference={0}) - error {1}", reference, pse)); throw pse; } }
public async Task <HttpResponseMessage> GetSincronizarRecebimentosPagSeguro(int nrDias, int nrPage, int nrMaxPageResults) { HttpResponseMessage response = new HttpResponseMessage(); var tsc = new TaskCompletionSource <HttpResponseMessage>(); try { if (nrDias == 0) { throw new Exception("Número de dias não informado!"); } var dtRef = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); dtRef = dtRef.AddHours(-2); DateTime _dtFinal = dtRef; DateTime _dtInicial = _dtFinal.AddDays(-nrDias); string _dtIni, _dtFim; _dtIni = _dtInicial.Year + "-" + _dtInicial.Month + "-" + _dtInicial.Day + "T" + _dtInicial.Hour + ":" + _dtInicial.Minute; _dtFim = _dtFinal.Year + "-" + _dtFinal.Month + "-" + _dtFinal.Day + "T" + _dtFinal.Hour + ":" + _dtFinal.Minute; int _page, _maxPageResults, _nrRegistrosAtualizados; _page = nrPage == 0 ? 1 : nrPage; _maxPageResults = nrMaxPageResults == 0 ? 100 : nrMaxPageResults; _nrRegistrosAtualizados = 0; int?_currPage; TransactionSearchResult _transacoesPS = await GetSincronizarRecebimentosAPIPagSeguro(_dtIni, _dtFim, _page, _maxPageResults, EMail, Token); _currPage = _transacoesPS.CurrentPage ?? 0; if (_currPage > 0) { while (_currPage <= _transacoesPS.TotalPages) { _nrRegistrosAtualizados += _pagSeguroApplication.UpdateRecebimentosPeriodoPagSeguro(_transacoesPS); _currPage++; if (_currPage <= _transacoesPS.TotalPages) { _transacoesPS = await GetSincronizarRecebimentosAPIPagSeguro(_dtIni, _dtFim, (int)_currPage, _maxPageResults, EMail, Token); } } response = Request.CreateResponse(HttpStatusCode.OK, $"Foram atualizados {_nrRegistrosAtualizados} registros!"); } else { response = Request.CreateResponse(HttpStatusCode.NotFound, "Não foram encontrados registros para o período informado!"); } tsc.SetResult(response); return(await tsc.Task); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); tsc.SetResult(response); return(await tsc.Task); } }
/// <summary> /// Consulta ao PagSeguro por período. /// </summary> /// <param name="dtInicial"></param> /// <param name="dtFinal"></param> /// <param name="page"></param> /// <param name="maxPageResults"></param> /// <param name="eMail"></param> /// <param name="token"></param> /// <returns></returns> public async Task <TransactionSearchResult> GetSincronizarRecebimentosAPIPagSeguro(string dtInicial, string dtFinal, int page, int maxPageResults, string eMail, string token) { try { Uri _uri = new Uri($"{BaseUrl}transactions?initialDate={dtInicial}&finalDate={dtFinal}&page={page}&maxPageResults={maxPageResults}&email={eMail}&token={token}"); HttpResponseMessage responseGet = await httpClient.GetAsync(_uri); string response = await responseGet.Content.ReadAsStringAsync(); if (response.Equals("Unauthorized")) { throw new Exception("ATENÇÃO: Ocorreu uma falha durante a autenticação do acesso ao serviço PagSeguro/transactions"); } TransactionSearchResult _ts = new TransactionSearchResult(); _ts.Transacoes = new List <TransacaoPagSeguro>(); ErrorsPagSeguro errorsPagSeguro = new ErrorsPagSeguro(); XDocument doc = XDocument.Parse(response); // Verificando se houve erro na requisição: foreach (var er in doc.Descendants("error")) { errorsPagSeguro.NotificationConde = ""; errorsPagSeguro.DtNotificacaoErro = DateTime.Now; errorsPagSeguro.Code = (string)er.Element("code") ?? ""; errorsPagSeguro.Message = (string)er.Element("message") ?? ""; } if (errorsPagSeguro.Message != null) { throw new Exception($"ATENÇÃO: Ocorreu um erro ao tentar obter listagem de recebimentos junto ao PagSeguro. Código do Erro: {errorsPagSeguro.Code} - Mensagem: {errorsPagSeguro.Message} - dtInicial: {dtInicial} & dtFinal: {dtFinal}"); } // Fim da verificação: foreach (var t in doc.Descendants("transactionSearchResult")) { _ts.Date = (DateTime?)t.Element("date") ?? null; foreach (var tr in doc.Descendants("transaction")) { TransacaoPagSeguro _tran = new TransacaoPagSeguro() { Date = (string)tr.Element("date") ?? String.Empty, Reference = (string)tr.Element("reference") ?? String.Empty, NotificationCode = (string)tr.Element("code") ?? String.Empty, Type = (int?)tr.Element("type") ?? null, Status = (int?)tr.Element("status") ?? null, PaymentMethod = new PaymentMethodPagSeguro() { Type = (int?)tr.Element("type") ?? null }, GrossAmount = (decimal?)tr.Element("grossAmount") ?? null, DiscountAmount = (decimal?)tr.Element("discountAmount") ?? null, FeeAmount = (decimal?)tr.Element("feeAmount") ?? null, NetAmount = (decimal?)tr.Element("netAmount") ?? null, ExtraAmount = (decimal?)tr.Element("extraAmount") ?? null, Lasteventdate = (string)tr.Element("date") ?? String.Empty }; _ts.Transacoes.Add(_tran); } _ts.ResultsInThisPage = (int?)t.Element("resultsInThisPage") ?? null; _ts.CurrentPage = (int?)t.Element("currentPage") ?? null; _ts.TotalPages = (int?)t.Element("totalPages") ?? null; } return(_ts); } catch (Exception ex) { throw ex; } }
/// <summary> /// Common implmentation of all SearchByDate methods /// </summary> /// <param name="credentials">PagSeguro credentials. Required.</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> private static TransactionSearchResult SearchByDateCore(Credentials credentials, DateTime initialDate, DateTime finalDate, int pageNumber, int resultsPerPage) { UriBuilder uriBuilder = new UriBuilder(PagSeguroConfiguration.SearchUri); QueryStringBuilder query = new QueryStringBuilder(ServiceHelper.EncodeCredentialsAsQueryString(credentials)); query.Append(InitialDateParameterName, initialDate); if (finalDate < DateTime.MaxValue) { query.Append(FinalDateParameterName, finalDate); } if (pageNumber > 0) { query.Append(PageNumberParameterName, pageNumber); } if (resultsPerPage > 0) { query.Append(MaxPageResultsParameterName, resultsPerPage); } uriBuilder.Query = query.ToString(); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - begin", initialDate, finalDate)); WebRequest request = WebRequest.Create(uriBuilder.Uri); request.Method = ServiceHelper.GetMethod; request.Timeout = PagSeguroConfiguration.RequestTimeout; try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { TransactionSearchResult result = new TransactionSearchResult(); TransactionSearchResultSerializer.Read(reader, result); PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - end {2}", initialDate, finalDate, result)); return result; } } } catch (WebException exception) { PagSeguroServiceException pse = ServiceHelper.CreatePagSeguroServiceException((HttpWebResponse)exception.Response); PagSeguroTrace.Error(String.Format(CultureInfo.InvariantCulture, "TransactionSearchService.SearchByDate(initialDate={0}, finalDate={1}) - error {2}", initialDate, finalDate, pse)); throw pse; } }
public int UpdateRecebimentosPeriodoPagSeguro(TransactionSearchResult transactionSearchResult) { return(_pagSeguroRepository.UpdateRecebimentosPeriodoPagSeguro(transactionSearchResult)); }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="result"></param> internal static void Read(XmlReader reader, TransactionSearchResult result, bool preApproval) { if (reader.IsEmptyElement) { XMLParserUtils.SkipNode(reader); return; } if (preApproval == true) { reader.ReadStartElement(TransactionSearchResultSerializer.PreApprovalSearchResult); } else { reader.ReadStartElement(TransactionSearchResultSerializer.TransactionSearchResult); } reader.MoveToContent(); while (!reader.EOF) { if (preApproval == true) { if (XMLParserUtils.IsEndElement(reader, TransactionSearchResultSerializer.PreApprovalSearchResult)) { XMLParserUtils.SkipNode(reader); break; } } else { if (XMLParserUtils.IsEndElement(reader, TransactionSearchResultSerializer.TransactionSearchResult)) { XMLParserUtils.SkipNode(reader); break; } } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case TransactionSearchResultSerializer.Date: result.Date = reader.ReadElementContentAsDateTime(); break; case TransactionSearchResultSerializer.CurrentPage: result.CurrentPage = reader.ReadElementContentAsInt(); break; case TransactionSearchResultSerializer.TotalPages: result.TotalPages = reader.ReadElementContentAsInt(); break; case TransactionSummaryListSerializer.Transactions: TransactionSummaryListSerializer.Read(reader, result.Transactions, preApproval); break; case TransactionSummaryListSerializer.PreApprovals: TransactionSummaryListSerializer.Read(reader, result.PreApprovals, preApproval); break; default: XMLParserUtils.SkipElement(reader); break; } } else { XMLParserUtils.SkipNode(reader); } } }