-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPackagingCompliancePaymentDetailsViewComponent.cs
More file actions
84 lines (71 loc) · 3.88 KB
/
PackagingCompliancePaymentDetailsViewComponent.cs
File metadata and controls
84 lines (71 loc) · 3.88 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
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;
namespace EPR.RegulatorService.Frontend.Web.ViewComponents.Submissions;
public class PackagingCompliancePaymentDetailsViewComponent(IOptions<PaymentDetailsOptions> options, IPaymentFacadeService paymentFacadeService, ILogger<PackagingCompliancePaymentDetailsViewComponent> logger) : ViewComponent
{
private static readonly Action<ILogger, string, Exception?> _logViewComponentError =
LoggerMessage.Define<string>(
LogLevel.Error,
new EventId(1001, nameof(PackagingCompliancePaymentDetailsViewComponent)),
"An error occurred while retrieving the packaging payment details: {ErrorMessage}");
public async Task<ViewViewComponentResult> InvokeAsync(SubmissionDetailsViewModel viewModel)
{
try
{
if (viewModel.MemberCount == 0)
{
this.ViewBag.NoMemberCount = true;
return View(default(PackagingCompliancePaymentDetailsViewModel));
}
if (viewModel.ReferenceFieldNotAvailable)
{
this.ViewBag.NoReferenceField = this.ViewBag.NoReferenceNumber = true;
return View(default(PackagingCompliancePaymentDetailsViewModel));
}
if (viewModel.ReferenceNotAvailable)
{
this.ViewBag.NoReferenceNumber = true;
return View(default(PackagingCompliancePaymentDetailsViewModel));
}
var compliancePaymentResponse = await paymentFacadeService.GetCompliancePaymentDetailsForResubmissionAsync(
new PackagingCompliancePaymentRequest
{
ReferenceNumber = viewModel.ReferenceNumber,
MemberCount = viewModel.MemberCount,
Regulator = viewModel.NationCode,
ResubmissionDate = TimeZoneInfo.ConvertTimeToUtc(viewModel.SubmittedDate), //payment facade in utc format
FileId = viewModel.FileId
});
if (compliancePaymentResponse is null)
{
return View(default(PackagingCompliancePaymentDetailsViewModel));
}
var compliancePaymentDetailsViewModel = new PackagingCompliancePaymentDetailsViewModel
{
SubmissionHash = viewModel.SubmissionHash,
MemberCount = compliancePaymentResponse.MemberCount,
PreviousPaymentReceived = ConvertToPoundsFromPence(compliancePaymentResponse.PreviousPaymentsReceived),
ResubmissionFee = ConvertToPoundsFromPence(compliancePaymentResponse.ResubmissionFee),
TotalOutstanding = ConvertToPoundsFromPence(PaymentHelper.GetUpdatedTotalOutstanding(compliancePaymentResponse.TotalOutstanding, options.Value.ShowZeroFeeForTotalOutstanding)),
ReferenceNumber = viewModel.ReferenceNumber,
NationCode = viewModel.NationCode
};
return View(compliancePaymentDetailsViewModel);
}
catch (Exception ex)
{
_logViewComponentError.Invoke(logger,
$"Unable to retrieve the packaging compliance scheme payment details for " +
$"{viewModel.SubmissionId} in {nameof(PackagingCompliancePaymentDetailsViewComponent)}.{nameof(InvokeAsync)}", ex);
ViewBag.ReferenceNumber = viewModel.ReferenceNumber;
return View(default(PackagingCompliancePaymentDetailsViewModel));
}
}
private static decimal ConvertToPoundsFromPence(decimal amount) => amount / 100;
}