-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProducerPaymentDetailsViewComponent.cs
More file actions
74 lines (66 loc) · 4.45 KB
/
ProducerPaymentDetailsViewComponent.cs
File metadata and controls
74 lines (66 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using EPR.RegulatorService.Frontend.Core.Models.RegistrationSubmissions;
using EPR.RegulatorService.Frontend.Core.Services;
using EPR.RegulatorService.Frontend.Web.Configs;
using EPR.RegulatorService.Frontend.Web.Helpers;
using EPR.RegulatorService.Frontend.Web.ViewModels.RegistrationSubmissions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.Extensions.Options;
namespace EPR.RegulatorService.Frontend.Web.ViewComponents.RegistrationSubmissions;
public class ProducerPaymentDetailsViewComponent(IOptions<PaymentDetailsOptions> options,
IPaymentFacadeService paymentFacadeService, ILogger<ProducerPaymentDetailsViewComponent> logger) : ViewComponent
{
private static readonly Action<ILogger, string, Exception?> _logViewComponentError =
LoggerMessage.Define<string>(
LogLevel.Error,
new EventId(1001, nameof(ProducerPaymentDetailsViewComponent)),
"An error occurred while retrieving the payment details: {ErrorMessage}");
public async Task<ViewViewComponentResult> InvokeAsync(RegistrationSubmissionDetailsViewModel viewModel)
{
try
{
var producerPaymentResponse = await paymentFacadeService.GetProducerPaymentDetailsAsync(new ProducerPaymentRequest
{
ApplicationReferenceNumber = viewModel.ReferenceNumber,
FileId = viewModel.IsResubmission ? viewModel.ResubmissionFileId : null,
NoOfSubsidiariesOnlineMarketplace = viewModel.ProducerDetails.NoOfSubsidiariesOnlineMarketPlace,
NumberOfSubsidiaries = viewModel.ProducerDetails.NoOfSubsidiaries,
IsLateFeeApplicable = viewModel.ProducerDetails.IsLateFeeApplicable,
IsProducerOnlineMarketplace = viewModel.ProducerDetails.IsProducerOnlineMarketplace,
ProducerType = viewModel.ProducerDetails.ProducerType,
Regulator = viewModel.NationCode,
SubmissionDate = TimeZoneInfo.ConvertTimeToUtc(viewModel.IsResubmission
? viewModel.SubmissionDetails.TimeAndDateOfResubmission.Value
: viewModel.SubmissionDetails.TimeAndDateOfSubmission)
});
if (producerPaymentResponse is null)
{
return View(default(ProducerPaymentDetailsViewModel));
}
var producerPaymentDetailsViewModel = new ProducerPaymentDetailsViewModel
{
ApplicationProcessingFee = ConvertToPoundsFromPence(producerPaymentResponse.ApplicationProcessingFee),
LateRegistrationFee = ConvertToPoundsFromPence(producerPaymentResponse.LateRegistrationFee),
OnlineMarketplaceFee = ConvertToPoundsFromPence(producerPaymentResponse.OnlineMarketplaceFee),
PreviousPaymentsReceived = ConvertToPoundsFromPence(producerPaymentResponse.PreviousPaymentsReceived),
SubsidiaryFee = ConvertToPoundsFromPence(producerPaymentResponse.SubsidiaryFee - producerPaymentResponse.SubsidiariesFeeBreakdown.SubsidiaryOnlineMarketPlaceFee),
SubsidiaryOnlineMarketPlaceFee = ConvertToPoundsFromPence(producerPaymentResponse.SubsidiariesFeeBreakdown.SubsidiaryOnlineMarketPlaceFee),
SubTotal = ConvertToPoundsFromPence(producerPaymentResponse.TotalChargeableItems),
TotalOutstanding = ConvertToPoundsFromPence(PaymentHelper.GetUpdatedTotalOutstanding(producerPaymentResponse.TotalOutstanding, options.Value.ShowZeroFeeForTotalOutstanding)),
ProducerSize = $"{char.ToUpperInvariant(viewModel.ProducerDetails.ProducerType[0])}{viewModel.ProducerDetails.ProducerType[1..]}",
NumberOfSubsidiaries = viewModel.ProducerDetails.NoOfSubsidiaries,
NumberOfSubsidiariesBeingOnlineMarketplace = producerPaymentResponse.SubsidiariesFeeBreakdown.OnlineMarketPlaceSubsidiariesCount,
ResubmissionStatus = viewModel.ResubmissionStatus,
Status = viewModel.Status,
};
return View(producerPaymentDetailsViewModel);
}
catch (Exception ex)
{
_logViewComponentError.Invoke(logger,
$"Unable to retrieve the producer payment details for {viewModel.SubmissionId} in {nameof(ProducerPaymentDetailsViewComponent)}.{nameof(InvokeAsync)}", ex);
return View(default(ProducerPaymentDetailsViewModel));
}
}
private static decimal ConvertToPoundsFromPence(decimal amount) => amount / 100;
}