-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fake payment processor for use in automated GUI tests. (#705)
- Loading branch information
Showing
2 changed files
with
98 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
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 = "test@test.no", | ||
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; | ||
} | ||
} |