Skip to content

Commit

Permalink
Feat/749 nets easy configure payment methods (#754)
Browse files Browse the repository at this point in the history
* Add support for specifying the Nets Easy payment method/type configuration parameter.

* Verify that nets payment method/type config is mapped correctly into the create payment model.

* Default Enabled to true.

* Line break fix.
  • Loading branch information
bjorntore authored Sep 11, 2024
1 parent eca9a69 commit 5c250e6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 25 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public async Task<PaymentDetails> StartPayment(Instance instance, OrderDetails o
.ToList(),
},
MyReference = instance.Id.Split('/')[1],
PaymentMethodsConfiguration = _settings
.PaymentMethodsConfiguration?.Select(x => new NetsPaymentMethodConfiguration
{
Name = x.Name,
Enabled = x.Enabled
})
.ToList(),
Checkout = new NetsCheckout
{
IntegrationType = "HostedPaymentPage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,39 @@ public class NetsPaymentSettings
/// Allows you to initiate the checkout with customer data so that your customer only need to provide payment details. If set to true, information about the paying party must be supplied.
/// </summary>
public bool? MerchantHandlesConsumerData { get; set; }

/// <summary>
/// This is mapped directly into the Nets Easy PaymentMethodsConfiguration property on the create payment model.
///
/// Specifies payment methods configuration to be used for this payment, ignored if empty or null.
///
/// Name is the name of the payment method or payment type to be configured. If the specified payment method is not configured correctly in the merchant configurations then this won't take effect.
/// Payment type cannot be specified alongside payment methods that belong to it, if it happens the request will fail with an error.
///
/// Possible payment methods values: "Visa", "MasterCard", "Dankort", "AmericanExpress", "PayPal", "Vipps", "MobilePay", "Swish", "Arvato", "EasyInvoice", "EasyInstallment", "EasyCampaign", "RatePayInvoice", "RatePayInstallment", "RatePaySepa", "Sofort", "Trustly".
/// Possible payment types values: "Card", "Invoice", "Installment", "A2A", "Wallet".
///
/// Enabled indicates that the specified payment method/type is allowed to be used for this payment, defaults to true. If one or more payment method/type is configured in the parent array then this value will be considered false for any other payment method that the parent array doesn't cover.
/// </summary>
public List<PaymentMethodConfigurationItem>? PaymentMethodsConfiguration { get; set; }

/// <summary>
/// Represents a payment method setting.
/// </summary>
public class PaymentMethodConfigurationItem
{
/// <summary>
/// The name of the payment method or payment type to be configured, if the specified payment method is not configured correctly in the merchant configurations then this won't take effect.
/// Payment type cannot be specified alongside payment methods that belong to it, if it happens the request will fail with an error.
/// Possible payment methods values: "Visa", "MasterCard", "Dankort", "AmericanExpress", "PayPal", "Vipps", "MobilePay", "Swish", "Arvato", "EasyInvoice", "EasyInstallment", "EasyCampaign", "RatePayInvoice", "RatePayInstallment", "RatePaySepa", "Sofort", "Trustly".
/// Possible payment types values: "Card", "Invoice", "Installment", "A2A", "Wallet".
/// </summary>
public required string Name { get; set; }

/// <summary>
/// Indicates that the specified payment method/type is allowed to be used for this payment, defaults to true.
/// If one or more payment method/type is configured in the parent array then this value will be considered false for any other payment method that the parent array doesn't cover.
/// </summary>
public required bool Enabled { get; set; } = true;
}
}
17 changes: 17 additions & 0 deletions src/Altinn.App.Core/Features/Payment/Processors/Nets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Nets Easy integration

This folder contains the implementation of our Nets Easy payment api integration.

The client code and models are based on the following API documentation:
[Nets Easy Payment API reference](https://developer.nexigroup.com/nexi-checkout/en-EU/api/payment-v1/).

### API Models Information

The models used in API calls to Nets Easy were manually created based on the JSON examples in the Nets API
documentation. Since they were written by hand, there might be some unintentional differences from the actual API
objects (bugs).

Refer back to the official API docs for the most up-to-date information.



Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public NetsPaymentProcessorTests()
SecretApiKey = "secret",
BaseUrl = "baseUrl",
TermsUrl = "termsUrl",
PaymentMethodsConfiguration =
[
new NetsPaymentSettings.PaymentMethodConfigurationItem { Name = "Card", Enabled = true }
]
}
);
_generalSettings = Microsoft.Extensions.Options.Options.Create(new GeneralSettings());
Expand All @@ -46,8 +50,10 @@ public async Task StartPayment_WithValidOrderDetails_ReturnsPaymentInformation()
Receiver = new PaymentReceiver()
};

NetsCreatePayment? capturedNetsCreatePayment = null;
_netsClientMock
.Setup(x => x.CreatePayment(It.IsAny<NetsCreatePayment>()))
.Callback<NetsCreatePayment>(payment => capturedNetsCreatePayment = payment)
.ReturnsAsync(
new HttpApiResult<NetsCreatePaymentSuccess>
{
Expand All @@ -63,9 +69,14 @@ public async Task StartPayment_WithValidOrderDetails_ReturnsPaymentInformation()
PaymentDetails result = await _processor.StartPayment(instance, orderDetails, LanguageConst.Nb);

// Assert
Assert.NotNull(result);
Assert.Equal("12345", result.PaymentId);
Assert.Equal("https://payment-url.com?language=nb-NO", result.RedirectUrl);
result.Should().NotBeNull();
result.PaymentId.Should().Be("12345");
result.RedirectUrl.Should().Be("https://payment-url.com?language=nb-NO");

capturedNetsCreatePayment.Should().NotBeNull();
capturedNetsCreatePayment
?.PaymentMethodsConfiguration.Should()
.BeEquivalentTo(_settings.Value.PaymentMethodsConfiguration);
}

[Fact]
Expand Down Expand Up @@ -231,7 +242,7 @@ public async Task GetPaymentStatus_WithValidPaymentReferenceAndExpectedTotal_Ret
);

// Assert
Assert.Equal(PaymentStatus.Paid, result);
result.Should().Be(PaymentStatus.Paid);
paymentDetails.RedirectUrl.Should().Contain("language=nb-NO");
}

Expand Down

0 comments on commit 5c250e6

Please sign in to comment.