Skip to content

Commit

Permalink
Allow null values for the Amount property in PaymentLinkRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed May 20, 2024
1 parent 0eb334b commit 27de4f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public record PaymentLinkRequest
/// <summary>
/// The amount that you want to charge, e.g. {"currency":"EUR", "value":"1000.00"} if you would want to charge €1000.00.
/// </summary>
public required Amount Amount { get; init; }
public Amount? Amount { get; init; }

/// <summary>
/// This description will also be used as the payment description and will be shown to your customer on their card or bank
Expand Down
35 changes: 32 additions & 3 deletions tests/Mollie.Tests.Integration/Api/PaymentLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public async Task CanRetrievePaymentLinkList() {

[DefaultRetryFact]
public async Task CanCreatePaymentLinkAndRetrieveIt() {
// Given: We create a new payment
PaymentLinkRequest paymentLinkRequest = new PaymentLinkRequest() {
// Given: We create a new payment link
PaymentLinkRequest paymentLinkRequest = new() {
Description = "Test",
Amount = new Amount(Currency.EUR, 50),
WebhookUrl = DefaultWebhookUrl,
Expand All @@ -44,7 +44,7 @@ public async Task CanCreatePaymentLinkAndRetrieveIt() {
// When: We retrieve it
var retrievePaymentLinkResponse = await _paymentLinkClient.GetPaymentLinkAsync(createdPaymentLinkResponse.Id);

// Then: We expect a list with a single ideal payment
// Then: We expect a payment link with the expected properties
var verifyPaymentLinkResponse = new Action<PaymentLinkResponse>(response => {
var expiresAtWithoutMs = paymentLinkRequest.ExpiresAt.Value.Truncate(TimeSpan.FromSeconds(1));
Expand All @@ -58,6 +58,35 @@ public async Task CanCreatePaymentLinkAndRetrieveIt() {
verifyPaymentLinkResponse(retrievePaymentLinkResponse);
}

[DefaultRetryFact]
public async Task CanCreatePaymentLinkWithNullAmount() {
// Given: We create a new payment link
PaymentLinkRequest paymentLinkRequest = new() {
Description = "Test",
Amount = null,
WebhookUrl = DefaultWebhookUrl,
RedirectUrl = DefaultRedirectUrl,
ExpiresAt = DateTime.Now.AddDays(1)
};
var createdPaymentLinkResponse = await _paymentLinkClient.CreatePaymentLinkAsync(paymentLinkRequest);

// When: We retrieve it
var retrievePaymentLinkResponse = await _paymentLinkClient.GetPaymentLinkAsync(createdPaymentLinkResponse.Id);

// Then: We expect a payment link with the expected properties
var verifyPaymentLinkResponse = new Action<PaymentLinkResponse>(response => {
var expiresAtWithoutMs = paymentLinkRequest.ExpiresAt.Value.Truncate(TimeSpan.FromSeconds(1));
response.Amount.Should().BeNull();
response.ExpiresAt.Should().Be(expiresAtWithoutMs);
response.Description.Should().Be(paymentLinkRequest.Description);
response.RedirectUrl.Should().Be(paymentLinkRequest.RedirectUrl);
});

verifyPaymentLinkResponse(createdPaymentLinkResponse);
verifyPaymentLinkResponse(retrievePaymentLinkResponse);
}

public void Dispose()
{
_paymentLinkClient?.Dispose();
Expand Down

0 comments on commit 27de4f7

Please sign in to comment.