diff --git a/src/Altinn.App.Api/Controllers/PaymentController.cs b/src/Altinn.App.Api/Controllers/PaymentController.cs
index 4167847d2..935ce810f 100644
--- a/src/Altinn.App.Api/Controllers/PaymentController.cs
+++ b/src/Altinn.App.Api/Controllers/PaymentController.cs
@@ -29,15 +29,15 @@ public class PaymentController : ControllerBase
/// Initializes a new instance of the class.
///
public PaymentController(
+ IServiceProvider serviceProvider,
IInstanceClient instanceClient,
IProcessReader processReader,
- IPaymentService paymentService,
IOrderDetailsCalculator? orderDetailsCalculator = null
)
{
_instanceClient = instanceClient;
_processReader = processReader;
- _paymentService = paymentService;
+ _paymentService = serviceProvider.GetRequiredService();
_orderDetailsCalculator = orderDetailsCalculator;
}
@@ -71,9 +71,11 @@ public async Task GetPaymentInformation(
throw new PaymentException("Payment configuration not found in AltinnTaskExtension");
}
+ var validPaymentConfiguration = paymentConfiguration.Validate();
+
PaymentInformation paymentInformation = await _paymentService.CheckAndStorePaymentStatus(
instance,
- paymentConfiguration,
+ validPaymentConfiguration,
language
);
diff --git a/src/Altinn.App.Core/Features/Action/PaymentUserAction.cs b/src/Altinn.App.Core/Features/Action/PaymentUserAction.cs
index 3e5100567..58d46240a 100644
--- a/src/Altinn.App.Core/Features/Action/PaymentUserAction.cs
+++ b/src/Altinn.App.Core/Features/Action/PaymentUserAction.cs
@@ -68,7 +68,7 @@ is not ProcessTask currentTask
(PaymentInformation paymentInformation, bool alreadyPaid) = await _paymentService.StartPayment(
context.Instance,
- paymentConfiguration,
+ paymentConfiguration.Validate(),
context.Language
);
diff --git a/src/Altinn.App.Core/Features/Payment/Services/IPaymentService.cs b/src/Altinn.App.Core/Features/Payment/Services/IPaymentService.cs
index 7d87dcb15..da5219fe2 100644
--- a/src/Altinn.App.Core/Features/Payment/Services/IPaymentService.cs
+++ b/src/Altinn.App.Core/Features/Payment/Services/IPaymentService.cs
@@ -7,14 +7,14 @@ namespace Altinn.App.Core.Features.Payment.Services
///
/// Service for handling payment.
///
- public interface IPaymentService
+ internal interface IPaymentService
{
///
/// Start payment for an instance. Will clean up any existing non-completed payment before starting a new payment.
///
Task<(PaymentInformation paymentInformation, bool alreadyPaid)> StartPayment(
Instance instance,
- AltinnPaymentConfiguration paymentConfiguration,
+ ValidAltinnPaymentConfiguration paymentConfiguration,
string? language
);
@@ -23,18 +23,18 @@ public interface IPaymentService
///
Task CheckAndStorePaymentStatus(
Instance instance,
- AltinnPaymentConfiguration paymentConfiguration,
+ ValidAltinnPaymentConfiguration paymentConfiguration,
string? language
);
///
/// Check our internal state to see if payment is complete.
///
- Task IsPaymentCompleted(Instance instance, AltinnPaymentConfiguration paymentConfiguration);
+ Task IsPaymentCompleted(Instance instance, ValidAltinnPaymentConfiguration paymentConfiguration);
///
/// Cancel payment with payment processor and delete internal payment information.
///
- Task CancelAndDeleteAnyExistingPayment(Instance instance, AltinnPaymentConfiguration paymentConfiguration);
+ Task CancelAndDeleteAnyExistingPayment(Instance instance, ValidAltinnPaymentConfiguration paymentConfiguration);
}
}
diff --git a/src/Altinn.App.Core/Features/Payment/Services/PaymentService.cs b/src/Altinn.App.Core/Features/Payment/Services/PaymentService.cs
index 5735a4194..7486f966f 100644
--- a/src/Altinn.App.Core/Features/Payment/Services/PaymentService.cs
+++ b/src/Altinn.App.Core/Features/Payment/Services/PaymentService.cs
@@ -1,7 +1,6 @@
using Altinn.App.Core.Features.Payment.Exceptions;
using Altinn.App.Core.Features.Payment.Models;
using Altinn.App.Core.Features.Payment.Processors;
-using Altinn.App.Core.Internal.App;
using Altinn.App.Core.Internal.Data;
using Altinn.App.Core.Internal.Process.Elements.AltinnExtensionProperties;
using Altinn.App.Core.Models;
@@ -39,7 +38,7 @@ public PaymentService(
///
public async Task<(PaymentInformation paymentInformation, bool alreadyPaid)> StartPayment(
Instance instance,
- AltinnPaymentConfiguration paymentConfiguration,
+ ValidAltinnPaymentConfiguration paymentConfiguration,
string? language
)
{
@@ -52,9 +51,7 @@ public PaymentService(
);
}
- ValidateConfig(paymentConfiguration);
- // ! TODO: restructure code to avoid assertion (it is validated above)
- string dataTypeId = paymentConfiguration.PaymentDataType!;
+ string dataTypeId = paymentConfiguration.PaymentDataType;
(Guid dataElementId, PaymentInformation? existingPaymentInformation) =
await _dataService.GetByType(instance, dataTypeId);
@@ -118,7 +115,7 @@ public PaymentService(
///
public async Task CheckAndStorePaymentStatus(
Instance instance,
- AltinnPaymentConfiguration paymentConfiguration,
+ ValidAltinnPaymentConfiguration paymentConfiguration,
string? language
)
{
@@ -131,10 +128,7 @@ public async Task CheckAndStorePaymentStatus(
);
}
- ValidateConfig(paymentConfiguration);
-
- // ! TODO: restructure code to avoid assertion (it is validated above)
- string dataTypeId = paymentConfiguration.PaymentDataType!;
+ string dataTypeId = paymentConfiguration.PaymentDataType;
(Guid dataElementId, PaymentInformation? paymentInformation) = await _dataService.GetByType(
instance,
dataTypeId
@@ -204,12 +198,9 @@ await _dataService.UpdateJsonObject(
}
///
- public async Task IsPaymentCompleted(Instance instance, AltinnPaymentConfiguration paymentConfiguration)
+ public async Task IsPaymentCompleted(Instance instance, ValidAltinnPaymentConfiguration paymentConfiguration)
{
- ValidateConfig(paymentConfiguration);
-
- // ! TODO: restructure code to avoid assertion (it is validated above)
- string dataTypeId = paymentConfiguration.PaymentDataType!;
+ string dataTypeId = paymentConfiguration.PaymentDataType;
(Guid _, PaymentInformation? paymentInformation) = await _dataService.GetByType(
instance,
dataTypeId
@@ -226,13 +217,10 @@ public async Task IsPaymentCompleted(Instance instance, AltinnPaymentConfi
///
public async Task CancelAndDeleteAnyExistingPayment(
Instance instance,
- AltinnPaymentConfiguration paymentConfiguration
+ ValidAltinnPaymentConfiguration paymentConfiguration
)
{
- ValidateConfig(paymentConfiguration);
-
- // ! TODO: restructure code to avoid assertion (it is validated above)
- string dataTypeId = paymentConfiguration.PaymentDataType!;
+ string dataTypeId = paymentConfiguration.PaymentDataType;
(Guid dataElementId, PaymentInformation? paymentInformation) = await _dataService.GetByType(
instance,
dataTypeId
@@ -275,21 +263,4 @@ private async Task CancelAndDelete(Instance instance, Guid dataElementId, Paymen
await _dataService.DeleteById(new InstanceIdentifier(instance), dataElementId);
_logger.LogDebug("Payment information for deleted for instance {InstanceId}.", instance.Id);
}
-
- private static void ValidateConfig(AltinnPaymentConfiguration paymentConfiguration)
- {
- List errorMessages = [];
-
- if (string.IsNullOrWhiteSpace(paymentConfiguration.PaymentDataType))
- {
- errorMessages.Add("PaymentDataType is missing.");
- }
-
- if (errorMessages.Count != 0)
- {
- throw new ApplicationConfigException(
- "Payment process task configuration is not valid: " + string.Join(",\n", errorMessages)
- );
- }
- }
}
diff --git a/src/Altinn.App.Core/Internal/Process/Elements/AltinnExtensionProperties/AltinnPaymentConfiguration.cs b/src/Altinn.App.Core/Internal/Process/Elements/AltinnExtensionProperties/AltinnPaymentConfiguration.cs
index 3ec5f1bc4..ed1746997 100644
--- a/src/Altinn.App.Core/Internal/Process/Elements/AltinnExtensionProperties/AltinnPaymentConfiguration.cs
+++ b/src/Altinn.App.Core/Internal/Process/Elements/AltinnExtensionProperties/AltinnPaymentConfiguration.cs
@@ -1,4 +1,6 @@
+using System.Diagnostics.CodeAnalysis;
using System.Xml.Serialization;
+using Altinn.App.Core.Internal.App;
namespace Altinn.App.Core.Internal.Process.Elements.AltinnExtensionProperties
{
@@ -12,5 +14,45 @@ public class AltinnPaymentConfiguration
///
[XmlElement("paymentDataType", Namespace = "http://altinn.no/process")]
public string? PaymentDataType { get; set; }
+
+ internal ValidAltinnPaymentConfiguration Validate()
+ {
+ List? errorMessages = null;
+
+ var paymentDataType = PaymentDataType;
+
+ if (paymentDataType.IsNullOrWhitespace(ref errorMessages, "PaymentDataType is missing."))
+ ThrowApplicationConfigException(errorMessages);
+
+ return new ValidAltinnPaymentConfiguration(paymentDataType);
+ }
+
+ [DoesNotReturn]
+ private static void ThrowApplicationConfigException(List errorMessages)
+ {
+ throw new ApplicationConfigException(
+ "Payment process task configuration is not valid: " + string.Join(",\n", errorMessages)
+ );
+ }
+ }
+
+ internal readonly record struct ValidAltinnPaymentConfiguration(string PaymentDataType);
+
+ file static class ValidationExtensions
+ {
+ internal static bool IsNullOrWhitespace(
+ [NotNullWhen(false)] this string? value,
+ [NotNullWhen(true)] ref List? errors,
+ string error
+ )
+ {
+ var result = string.IsNullOrWhiteSpace(value);
+ if (result)
+ {
+ errors ??= new List(1);
+ errors.Add(error);
+ }
+ return result;
+ }
}
}
diff --git a/src/Altinn.App.Core/Internal/Process/ProcessTasks/PaymentProcessTask.cs b/src/Altinn.App.Core/Internal/Process/ProcessTasks/PaymentProcessTask.cs
index 56b9be233..bd4ab9591 100644
--- a/src/Altinn.App.Core/Internal/Process/ProcessTasks/PaymentProcessTask.cs
+++ b/src/Altinn.App.Core/Internal/Process/ProcessTasks/PaymentProcessTask.cs
@@ -44,7 +44,7 @@ IPaymentService paymentService
public async Task Start(string taskId, Instance instance)
{
AltinnPaymentConfiguration paymentConfiguration = GetAltinnPaymentConfiguration(taskId);
- await _paymentService.CancelAndDeleteAnyExistingPayment(instance, paymentConfiguration);
+ await _paymentService.CancelAndDeleteAnyExistingPayment(instance, paymentConfiguration.Validate());
}
///
@@ -52,17 +52,16 @@ public async Task End(string taskId, Instance instance)
{
AltinnPaymentConfiguration paymentConfiguration = GetAltinnPaymentConfiguration(taskId);
- if (!await _paymentService.IsPaymentCompleted(instance, paymentConfiguration))
+ if (!await _paymentService.IsPaymentCompleted(instance, paymentConfiguration.Validate()))
throw new PaymentException("The payment is not completed.");
Stream pdfStream = await _pdfService.GeneratePdf(instance, taskId, CancellationToken.None);
- // ! TODO: restructure code to avoid assertion. Codepaths above have already validated this field
- var paymentDataType = paymentConfiguration.PaymentDataType!;
+ var validatedPaymentConfiguration = paymentConfiguration.Validate();
await _dataClient.InsertBinaryData(
instance.Id,
- paymentDataType,
+ validatedPaymentConfiguration.PaymentDataType,
PdfContentType,
ReceiptFileName,
pdfStream,
@@ -74,7 +73,7 @@ await _dataClient.InsertBinaryData(
public async Task Abandon(string taskId, Instance instance)
{
AltinnPaymentConfiguration paymentConfiguration = GetAltinnPaymentConfiguration(taskId);
- await _paymentService.CancelAndDeleteAnyExistingPayment(instance, paymentConfiguration);
+ await _paymentService.CancelAndDeleteAnyExistingPayment(instance, paymentConfiguration.Validate());
}
private AltinnPaymentConfiguration GetAltinnPaymentConfiguration(string taskId)
@@ -90,12 +89,7 @@ private AltinnPaymentConfiguration GetAltinnPaymentConfiguration(string taskId)
);
}
- if (string.IsNullOrWhiteSpace(paymentConfiguration.PaymentDataType))
- {
- throw new ApplicationConfigException(
- "PaymentDataType is missing in the payment process task configuration."
- );
- }
+ _ = paymentConfiguration.Validate();
return paymentConfiguration;
}
diff --git a/test/Altinn.App.Core.Tests/Features/Action/PaymentUserActionTests.cs b/test/Altinn.App.Core.Tests/Features/Action/PaymentUserActionTests.cs
index 88cec9965..8090d14f0 100644
--- a/test/Altinn.App.Core.Tests/Features/Action/PaymentUserActionTests.cs
+++ b/test/Altinn.App.Core.Tests/Features/Action/PaymentUserActionTests.cs
@@ -55,7 +55,7 @@ public async Task HandleAction_returns_redirect_result_correctly()
_paymentServiceMock
.Setup(x =>
- x.StartPayment(It.IsAny(), It.IsAny(), It.IsAny())
+ x.StartPayment(It.IsAny(), It.IsAny(), It.IsAny())
)
.ReturnsAsync((paymentInformation, false));
@@ -94,7 +94,7 @@ public async Task HandleAction_returns_success_result_when_no_redirect_url()
_paymentServiceMock
.Setup(x =>
- x.StartPayment(It.IsAny(), It.IsAny(), It.IsAny())
+ x.StartPayment(It.IsAny(), It.IsAny(), It.IsAny())
)
.ReturnsAsync((paymentInformation, false));
@@ -131,7 +131,7 @@ public async Task HandleAction_returns_failure_result_when_already_paid()
_paymentServiceMock
.Setup(x =>
- x.StartPayment(It.IsAny(), It.IsAny(), It.IsAny())
+ x.StartPayment(It.IsAny(), It.IsAny(), It.IsAny())
)
.ReturnsAsync((paymentInformation, true));
diff --git a/test/Altinn.App.Core.Tests/Features/Payment/AltinnPaymentConfigurationTests.cs b/test/Altinn.App.Core.Tests/Features/Payment/AltinnPaymentConfigurationTests.cs
new file mode 100644
index 000000000..94a03af2c
--- /dev/null
+++ b/test/Altinn.App.Core.Tests/Features/Payment/AltinnPaymentConfigurationTests.cs
@@ -0,0 +1,32 @@
+using Altinn.App.Core.Internal.App;
+using Altinn.App.Core.Internal.Process.Elements.AltinnExtensionProperties;
+using FluentAssertions;
+
+namespace Altinn.App.Core.Tests.Features.Payment;
+
+public class AltinnPaymentConfigurationTests
+{
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData(" ")]
+ public void Validation_ThrowsException_When_PaymentDataType_Is_Invalid(string? paymentDataType)
+ {
+ AltinnPaymentConfiguration paymentConfiguration = new() { PaymentDataType = paymentDataType };
+
+ var action = () => paymentConfiguration.Validate();
+
+ action.Should().Throw();
+ }
+
+ [Fact]
+ public void Validation_Succeeds()
+ {
+ var paymentDataType = "paymentDataType";
+ AltinnPaymentConfiguration paymentConfiguration = new() { PaymentDataType = paymentDataType };
+ paymentConfiguration.PaymentDataType.Should().Be(paymentDataType);
+
+ var validPaymentConfiguration = paymentConfiguration.Validate();
+ validPaymentConfiguration.PaymentDataType.Should().Be(paymentDataType);
+ }
+}
diff --git a/test/Altinn.App.Core.Tests/Features/Payment/PaymentServiceTests.cs b/test/Altinn.App.Core.Tests/Features/Payment/PaymentServiceTests.cs
index e7ce4c8ea..6a872ffed 100644
--- a/test/Altinn.App.Core.Tests/Features/Payment/PaymentServiceTests.cs
+++ b/test/Altinn.App.Core.Tests/Features/Payment/PaymentServiceTests.cs
@@ -10,7 +10,6 @@
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Moq;
-using Xunit;
namespace Altinn.App.Core.Tests.Features.Payment;
@@ -37,7 +36,7 @@ public async Task StartPayment_ReturnsRedirectUrl_WhenPaymentStartedSuccessfully
{
Instance instance = CreateInstance();
OrderDetails orderDetails = CreateOrderDetails();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
PaymentInformation paymentInformation = CreatePaymentInformation();
PaymentDetails paymentDetails =
paymentInformation.PaymentDetails ?? throw new NullReferenceException("PaymentDetails should not be null");
@@ -88,7 +87,7 @@ public async Task StartPayment_ReturnsAlreadyPaidTrue_WhenPaymentIsAlreadyPaid()
{
Instance instance = CreateInstance();
OrderDetails orderDetails = CreateOrderDetails();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
const string language = "nb";
_paymentProcessor.Setup(pp => pp.PaymentProcessorId).Returns(orderDetails.PaymentProcessorId);
@@ -124,7 +123,7 @@ public async Task StartPayment_ReturnsAlreadyPaidTrue_WhenPaymentIsAlreadyPaid()
public async Task StartPayment_ThrowsException_WhenOrderDetailsCannotBeRetrieved()
{
Instance instance = CreateInstance();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
const string language = "nb";
_dataService
@@ -148,7 +147,7 @@ public async Task StartPayment_ThrowsException_WhenPaymentCannotBeStarted()
{
Instance instance = CreateInstance();
OrderDetails orderDetails = CreateOrderDetails();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
const string language = "nb";
_dataService
@@ -170,7 +169,7 @@ public async Task StartPayment_ThrowsException_WhenPaymentInformationCannotBeSto
{
Instance instance = CreateInstance();
OrderDetails orderDetails = CreateOrderDetails();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
PaymentInformation paymentInformation = CreatePaymentInformation();
PaymentDetails paymentDetails =
paymentInformation.PaymentDetails ?? throw new NullReferenceException("PaymentDetails should not be null");
@@ -197,7 +196,7 @@ public async Task CheckAndStorePaymentInformation_ReturnsNull_WhenNoPaymentInfor
{
Instance instance = CreateInstance();
OrderDetails orderDetails = CreateOrderDetails();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
const string language = "nb";
_orderDetailsCalculator.Setup(p => p.CalculateOrderDetails(instance, language)).ReturnsAsync(orderDetails);
@@ -225,7 +224,7 @@ public async Task CheckAndStorePaymentInformation_ThrowsException_WhenUnableToCh
{
Instance instance = CreateInstance();
OrderDetails orderDetails = CreateOrderDetails();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
PaymentInformation paymentInformation = CreatePaymentInformation();
const string language = "nb";
@@ -259,7 +258,7 @@ public async Task CheckAndStorePaymentInformation_ReturnsPaymentInformation_When
{
Instance instance = CreateInstance();
OrderDetails orderDetails = CreateOrderDetails();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
PaymentInformation paymentInformation = CreatePaymentInformation();
const string language = "nb";
@@ -313,7 +312,7 @@ public async Task CancelPayment_ShouldCallCancelAndDelete_WhenPaymentIsNotPaid()
{
// Arrange
Instance instance = CreateInstance();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
OrderDetails orderDetails = CreateOrderDetails();
PaymentInformation paymentInformation = CreatePaymentInformation();
PaymentDetails paymentDetails =
@@ -365,7 +364,7 @@ public async Task CancelPayment_ShouldNotDelete_WhenPaymentCancellationFails()
// Arrange
Instance instance = CreateInstance();
OrderDetails orderDetails = CreateOrderDetails();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
PaymentInformation paymentInformation = CreatePaymentInformation();
PaymentDetails paymentDetails =
paymentInformation.PaymentDetails ?? throw new NullReferenceException("PaymentDetails should not be null");
@@ -403,7 +402,7 @@ public async Task StartPayment_ShouldThrowPaymentException_WhenOrderDetailsCalcu
{
// Arrange
Instance instance = CreateInstance();
- AltinnPaymentConfiguration paymentConfiguration = new() { PaymentDataType = "paymentDataType" };
+ ValidAltinnPaymentConfiguration paymentConfiguration = new() { PaymentDataType = "paymentDataType" };
IPaymentProcessor[] paymentProcessors = []; //No payment processor added.
var paymentService = new PaymentService(paymentProcessors, _dataService.Object, _logger.Object);
@@ -430,7 +429,7 @@ public async Task CheckAndStorePaymentStatus_ShouldThrowPaymentException_WhenOrd
// Act
Func act = async () =>
- await paymentService.CheckAndStorePaymentStatus(instance, paymentConfiguration, "en");
+ await paymentService.CheckAndStorePaymentStatus(instance, paymentConfiguration.Validate(), "en");
// Assert
await act.Should()
@@ -445,7 +444,7 @@ public async Task IsPaymentCompleted_ShouldThrowPaymentException_WhenPaymentInfo
{
// Arrange
Instance instance = CreateInstance();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
string paymentDataType =
paymentConfiguration.PaymentDataType
@@ -467,7 +466,7 @@ public async Task IsPaymentCompleted_ShouldReturnTrue_WhenPaymentStatusIsPaidOrS
{
// Arrange
Instance instance = CreateInstance();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
PaymentInformation paymentInformation = CreatePaymentInformation();
paymentInformation.Status = PaymentStatus.Paid;
@@ -491,7 +490,7 @@ public async Task IsPaymentCompleted_ShouldReturnFalse_WhenPaymentStatusIsNotPai
{
// Arrange
Instance instance = CreateInstance();
- AltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
+ ValidAltinnPaymentConfiguration paymentConfiguration = CreatePaymentConfiguration();
PaymentInformation paymentInformation = CreatePaymentInformation();
string paymentDataType =
@@ -559,8 +558,8 @@ private static OrderDetails CreateOrderDetails()
};
}
- private static AltinnPaymentConfiguration CreatePaymentConfiguration()
+ private static ValidAltinnPaymentConfiguration CreatePaymentConfiguration()
{
- return new AltinnPaymentConfiguration { PaymentDataType = "paymentInformation" };
+ return new AltinnPaymentConfiguration { PaymentDataType = "paymentInformation" }.Validate();
}
}
diff --git a/test/Altinn.App.Core.Tests/Internal/Process/ProcessTasks/PaymentProcessTaskTests.cs b/test/Altinn.App.Core.Tests/Internal/Process/ProcessTasks/PaymentProcessTaskTests.cs
index 091793c92..0e0f7b291 100644
--- a/test/Altinn.App.Core.Tests/Internal/Process/ProcessTasks/PaymentProcessTaskTests.cs
+++ b/test/Altinn.App.Core.Tests/Internal/Process/ProcessTasks/PaymentProcessTaskTests.cs
@@ -56,7 +56,7 @@ public async Task Start_ShouldCancelAndDelete()
// Assert
_paymentServiceMock.Verify(x =>
- x.CancelAndDeleteAnyExistingPayment(instance, altinnTaskExtension.PaymentConfiguration)
+ x.CancelAndDeleteAnyExistingPayment(instance, altinnTaskExtension.PaymentConfiguration.Validate())
);
}
@@ -74,7 +74,7 @@ public async Task End_PaymentCompleted_ShouldGeneratePdfReceipt()
_processReaderMock.Setup(x => x.GetAltinnTaskExtension(It.IsAny())).Returns(altinnTaskExtension);
_paymentServiceMock
- .Setup(x => x.IsPaymentCompleted(It.IsAny(), It.IsAny()))
+ .Setup(x => x.IsPaymentCompleted(It.IsAny(), It.IsAny()))
.ReturnsAsync(true);
// Act
@@ -108,7 +108,7 @@ public async Task End_PaymentNotCompleted_ShouldThrowException()
_processReaderMock.Setup(x => x.GetAltinnTaskExtension(It.IsAny())).Returns(altinnTaskExtension);
_paymentServiceMock
- .Setup(x => x.IsPaymentCompleted(It.IsAny(), It.IsAny()))
+ .Setup(x => x.IsPaymentCompleted(It.IsAny(), It.IsAny()))
.ReturnsAsync(false);
// Act and assert
@@ -147,7 +147,7 @@ public async Task Abandon_ShouldCancelAndDelete()
// Assert
_paymentServiceMock.Verify(x =>
- x.CancelAndDeleteAnyExistingPayment(instance, altinnTaskExtension.PaymentConfiguration)
+ x.CancelAndDeleteAnyExistingPayment(instance, altinnTaskExtension.PaymentConfiguration.Validate())
);
}
@@ -193,7 +193,7 @@ public async Task End_ValidConfiguration_ShouldNotThrow()
);
_paymentServiceMock
- .Setup(ps => ps.IsPaymentCompleted(It.IsAny(), It.IsAny()))
+ .Setup(ps => ps.IsPaymentCompleted(It.IsAny(), It.IsAny()))
.ReturnsAsync(true);
using var memoryStream = new MemoryStream();