Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow null values for the Amount property in PaymentLinkRequest #360

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading