-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPackagingProducerPaymentDetailsViewComponent.cs
More file actions
86 lines (74 loc) · 3.89 KB
/
PackagingProducerPaymentDetailsViewComponent.cs
File metadata and controls
86 lines (74 loc) · 3.89 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
75
76
77
78
79
80
81
82
83
84
85
86
using EPR.RegulatorService.Frontend.Core.Models.Submissions;
using EPR.RegulatorService.Frontend.Core.Services;
using EPR.RegulatorService.Frontend.Web.Configs;
using EPR.RegulatorService.Frontend.Web.Helpers;
using EPR.RegulatorService.Frontend.Web.ViewModels.Submissions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.Extensions.Options;
using Microsoft.FeatureManagement;
namespace EPR.RegulatorService.Frontend.Web.ViewComponents.Submissions;
public class PackagingProducerPaymentDetailsViewComponent(
IOptions<PaymentDetailsOptions> options,
IPaymentFacadeService paymentFacadeService,
IFeatureManager featureManager,
ILogger<PackagingProducerPaymentDetailsViewComponent> logger) : ViewComponent
{
private static readonly Action<ILogger, string, Exception?> _logViewComponentError =
LoggerMessage.Define<string>(
LogLevel.Error,
new EventId(1001, nameof(PackagingProducerPaymentDetailsViewComponent)),
"An error occurred while retrieving the packaging payment details: {ErrorMessage}");
public async Task<ViewViewComponentResult> InvokeAsync(SubmissionDetailsViewModel viewModel)
{
try
{
if (viewModel.ReferenceFieldNotAvailable)
{
this.ViewBag.NoReferenceField = this.ViewBag.NoReferenceNumber = true;
return View(default(PackagingProducerPaymentDetailsViewModel));
}
if (viewModel.ReferenceNotAvailable)
{
this.ViewBag.NoReferenceNumber = true;
return View(default(PackagingProducerPaymentDetailsViewModel));
}
int memberCount =
await featureManager.IsEnabledAsync(FeatureFlags.IncludeSubsidiariesInFeeCalculationsForRegulators)
? viewModel.MemberCount
: 1;
var producerPaymentResponse = await paymentFacadeService
.GetProducerPaymentDetailsForResubmissionAsync(new PackagingProducerPaymentRequest
{
ReferenceNumber = viewModel.ReferenceNumber,
Regulator = viewModel.NationCode,
MemberCount = memberCount,
ResubmissionDate = TimeZoneInfo.ConvertTimeToUtc(viewModel.SubmittedDate), //payment facade in utc format
FileId = viewModel.FileId
});
if (producerPaymentResponse is null)
{
return View(default(PackagingProducerPaymentDetailsViewModel));
}
var packagingProducerPaymentDetailsViewModel = new PackagingProducerPaymentDetailsViewModel
{
SubmissionHash = viewModel.SubmissionHash,
PreviousPaymentsReceived = ConvertToPoundsFromPence(producerPaymentResponse.PreviousPaymentsReceived),
ResubmissionFee = ConvertToPoundsFromPence(producerPaymentResponse.ResubmissionFee),
TotalOutstanding = ConvertToPoundsFromPence(PaymentHelper.GetUpdatedTotalOutstanding(producerPaymentResponse.TotalOutstanding, options.Value.ShowZeroFeeForTotalOutstanding)),
ReferenceNumber = viewModel.ReferenceNumber,
NationCode = viewModel.NationCode,
MemberCount = viewModel.MemberCount
};
return View(packagingProducerPaymentDetailsViewModel);
}
catch (Exception ex)
{
_logViewComponentError.Invoke(logger,
$"Unable to retrieve the packaging producer payment details for {viewModel.SubmissionId} in {nameof(PackagingProducerPaymentDetailsViewComponent)}.{nameof(InvokeAsync)}", ex);
ViewBag.ReferenceNumber = viewModel.ReferenceNumber;
return View(default(PackagingProducerPaymentDetailsViewModel));
}
}
private static decimal ConvertToPoundsFromPence(decimal amount) => amount / 100;
}