-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/392-metadata-fields-on-data-element
- Loading branch information
Showing
4 changed files
with
144 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Altinn.App.Core.Internal.App; | ||
using Azure.Identity; | ||
|
||
namespace Altinn.App.Api.Extensions; | ||
|
||
/// <summary> | ||
/// Class for defining extensions to IHostBuilder for AltinnApps | ||
/// </summary> | ||
public static class HostBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Add KeyVault as a configuration provider. Requires that the kvSetting section is present in the configuration and throws an exception if not. See documentation for secret handling in Altinn apps. | ||
/// </summary> | ||
/// <remarks>Use </remarks> | ||
/// <param name="builder"></param> | ||
/// <exception cref="ApplicationConfigException"></exception> | ||
public static void AddAzureKeyVaultAsConfigProvider(this IHostApplicationBuilder builder) | ||
{ | ||
IConfigurationManager configuration = builder.Configuration; | ||
IConfigurationSection section = configuration.GetSection("kvSetting"); | ||
|
||
var keyVaultUri = section.GetValue<string>("SecretUri"); | ||
var clientId = section.GetValue<string>("ClientId"); | ||
var clientSecret = section.GetValue<string>("ClientSecret"); | ||
var tenantId = section.GetValue<string>("TenantId"); | ||
|
||
if ( | ||
string.IsNullOrWhiteSpace(keyVaultUri) | ||
|| string.IsNullOrWhiteSpace(clientId) | ||
|| string.IsNullOrWhiteSpace(clientSecret) | ||
|| string.IsNullOrWhiteSpace(tenantId) | ||
) | ||
{ | ||
throw new ApplicationConfigException( | ||
"Attempted to add KeyVault as a configuration provider, but the required settings for authenticating with KeyVault are missing. Please check the configuration." | ||
); | ||
} | ||
|
||
builder.Configuration.AddAzureKeyVault( | ||
new Uri(keyVaultUri), | ||
new ClientSecretCredential(tenantId, clientId, clientSecret) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/Altinn.App.Core/Features/Payment/Processors/FakePaymentProcessor/FakePaymentProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Altinn.App.Core.Configuration; | ||
using Altinn.App.Core.Features.Payment.Models; | ||
using Altinn.App.Core.Models; | ||
using Altinn.Platform.Storage.Interface.Models; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Altinn.App.Core.Features.Payment.Processors.FakePaymentProcessor; | ||
|
||
/// <summary> | ||
/// This class is a fake payment processor that can be used for testing purposes. | ||
/// </summary> | ||
internal sealed class FakePaymentProcessor : IPaymentProcessor | ||
{ | ||
private readonly GeneralSettings _generalSettings; | ||
public string PaymentProcessorId => "Fake Payment Processor"; | ||
|
||
public FakePaymentProcessor(IOptions<GeneralSettings> generalSettings) | ||
{ | ||
_generalSettings = generalSettings.Value; | ||
} | ||
|
||
public Task<PaymentDetails> StartPayment(Instance instance, OrderDetails orderDetails, string? language) | ||
{ | ||
return Task.FromResult( | ||
new PaymentDetails { PaymentId = "fake-payment-id", RedirectUrl = GetAltinnAppUrl(instance) } | ||
); | ||
} | ||
|
||
public Task<bool> TerminatePayment(Instance instance, PaymentInformation paymentInformation) | ||
{ | ||
return Task.FromResult(true); | ||
} | ||
|
||
public Task<(PaymentStatus status, PaymentDetails paymentDetails)> GetPaymentStatus( | ||
Instance instance, | ||
string paymentId, | ||
decimal expectedTotalIncVat, | ||
string? language | ||
) | ||
{ | ||
return Task.FromResult( | ||
( | ||
PaymentStatus.Paid, | ||
new PaymentDetails | ||
{ | ||
PaymentId = paymentId, | ||
RedirectUrl = GetAltinnAppUrl(instance), | ||
Payer = new Payer | ||
{ | ||
PrivatePerson = new PayerPrivatePerson | ||
{ | ||
FirstName = "Test", | ||
LastName = "Testersen", | ||
Email = "[email protected]", | ||
PhoneNumber = new PhoneNumber { Prefix = "+47", Number = "12345678" } | ||
} | ||
}, | ||
PaymentType = "CARD", | ||
PaymentMethod = "MasterCard", | ||
CreatedDate = new DateTime().ToLongDateString(), | ||
ChargedDate = new DateTime().ToLongDateString(), | ||
InvoiceDetails = null, | ||
CardDetails = new CardDetails | ||
{ | ||
ExpiryDate = new DateTime().AddYears(2).ToLongDateString(), | ||
MaskedPan = "1234********1234", | ||
} | ||
} | ||
) | ||
); | ||
} | ||
|
||
private string GetAltinnAppUrl(Instance instance) | ||
{ | ||
var instanceIdentifier = new InstanceIdentifier(instance); | ||
string baseUrl = _generalSettings.FormattedExternalAppBaseUrl(new AppIdentifier(instance)); | ||
var altinnAppUrl = $"{baseUrl}#/instance/{instanceIdentifier}"; | ||
return altinnAppUrl; | ||
} | ||
} |