private async Task <ICollection <PaymentDetails> > GetPayments(string periodEnd, long employerAccountId)
        {
            var paymentDetails = new List <PaymentDetails>();

            try
            {
                var totalPages = 1;

                for (var index = 0; index < totalPages; index++)
                {
                    var payments = await _paymentsEventsApiClient.GetPayments(periodEnd, employerAccountId.ToString(), index + 1);

                    if (payments == null)
                    {
                        return(paymentDetails);
                    }

                    paymentDetails.AddRange(payments.Items.Select(x => _mapper.Map <PaymentDetails>(x)));

                    totalPages = payments.TotalNumberOfPages;
                }
            }
            catch (WebException ex)
            {
                _logger.Error(ex, $"Unable to get payment information for {periodEnd} accountid {employerAccountId}");
            }

            return(paymentDetails);
        }
Esempio n. 2
0
        private async Task <PageOfResults <Payment> > GetPaymentsPage(long employerAccountId, string periodEnd, int page)
        {
            try
            {
                return(await _paymentsEventsApiClient.GetPayments(periodEnd, employerAccountId.ToString(), page, null));
            }
            catch (WebException ex)
            {
                _logger.Error(ex, $"Unable to get payment information for {periodEnd} accountid {employerAccountId}");
            }

            return(null);
        }
        public async Task <List <EarningDetails> > PaymentForPeriod(string periodId, long employerAccountId)
        {
            var result   = new List <EarningDetails>();
            var maxPages = 10000;

            for (int i = 1; i < maxPages; i++)
            {
                var page = await _paymentsEventsApiClient.GetPayments(periodId, employerAccountId.ToString(), i);

                if (!page.Items.Any())
                {
                    _logger.Info($"No payments returned for page {i}.");
                    break;
                }

                _logger.Debug($"Got {page.Items.Length} payments for page {i}.");
                var paymentEarningDetails = page.Items
                                            .Where(p => p.EarningDetails.Any())
                                            .SelectMany(p => p.EarningDetails, (p, e) =>
                                                        new EarningDetails
                {
                    ActualEndDate      = e.ActualEndDate,
                    PlannedEndDate     = e.PlannedEndDate,
                    EndpointAssessorId = e.EndpointAssessorId,
                    CompletionAmount   = e.CompletionAmount,
                    CompletionStatus   = e.CompletionStatus,
                    MonthlyInstallment = e.MonthlyInstallment,
                    RequiredPaymentId  = e.RequiredPaymentId,
                    ApprenticeshipId   = p.ApprenticeshipId ?? 0,
                    PaymentId          = p.Id,
                    StartDate          = e.StartDate,
                    TotalInstallments  = e.TotalInstallments
                })
                                            .ToList();
                _logger.Debug($"Got {paymentEarningDetails.Count} payments for page {i}.");
                result.AddRange(paymentEarningDetails);
                if (page.PageNumber == page.TotalNumberOfPages)
                {
                    break;
                }
            }
            return(result);
        }
Esempio n. 4
0
 public async Task <PageOfResults <Payment> > GetPayments(string periodId, int pageNumber)
 {
     return(await _eventsApi.GetPayments(periodId, null, pageNumber));
 }