Ejemplo n.º 1
0
        public async Task <List <TransactionDetail> > GetTransactionsAsync()
        {
            var nowDate = _configuration["ToDay"] != null?
                          DateTime.ParseExact(_configuration["ToDay"], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture) :
                              DateTime.UtcNow;

            var fromDate = _configuration["FromDay"] != null?
                           DateTime.ParseExact(_configuration["FromDay"], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture) :
                               nowDate.AddDays(-1);

            _token = await GetPaypalTokenAsync();

            var pageCounter = 0;
            var totalPages  = 1;
            var details     = new List <TransactionDetail>();
            var sb          = new StringBuilder();

            _restClient.AddHeaders("Authorization", _token);
            sb.Append("?fields=all");
            sb.Append($"&page_size={_configuration["PaypalTransactionPageSize"]}");
            sb.Append($"&start_date={fromDate:yyyy-MM-dd}T00:00:00-0000");
            sb.Append($"&end_date={nowDate:yyyy-MM-dd}T23:59:59-0000");
            var queryParam = sb.ToString();

            while (pageCounter < totalPages)
            {
                var page     = $"&page={pageCounter+1}";
                var response = await _restClient.GetAsync <TransactionDetails>($"{_configuration["PaypalTransactionUrl"]}{queryParam}{page}");

                details.AddRange(response.TransactionDetailsTransactionDetails);
                totalPages = response.TotalPages;
                pageCounter++;
            }

            return(details);
        }