Skip to content

Commit

Permalink
Add support for payment lines (#370)
Browse files Browse the repository at this point in the history
* #368 Add models for payment lines

* #368 Add integration test for payment with order line
  • Loading branch information
Viincenttt authored Jun 13, 2024
1 parent 2417d09 commit 6e37edc
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/Mollie.Api/Models/Payment/PaymentLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
namespace Mollie.Api.Models.Payment;

public record PaymentLine {
/// <summary>
/// The type of product purchased. For example, a physical or a digital product.
/// Use the Mollie.Api.Models.Order.Request.OrderLineDetailsType class for a full list of known values.
/// </summary>
public required string Type { get; init; }

/// <summary>
/// A description of the line item. For example LEGO 4440 Forest Police Station.
/// </summary>
public required string Description { get; init; }

/// <summary>
/// The number of items.
/// </summary>
public required int Quantity { get; init; }

/// <summary>
/// The unit for the quantity. For example pcs, kg, or cm.
/// </summary>
public string? QuantityUnit { get; init; }

/// <summary>
/// The price of a single item including VAT. The unit price can be zero in case of free items.
/// </summary>
public required Amount UnitPrice { get; init; }

/// <summary>
/// Any line-specific discounts, as a positive amount. Not relevant if the line itself is already a discount type.
/// </summary>
public Amount? DiscountAmount { get; set; }

/// <summary>
/// The total amount of the line, including VAT and discounts.
/// </summary>
public required Amount TotalAmount { get; init; }

/// <summary>
/// The VAT rate applied to the line, for example 21.00 for 21%. The vatRate should be passed as a string and not
/// as a float, to ensure the correct number of decimals are passed.
/// </summary>
public string? VatRate { get; set; } // TODO: make it decimal?

/// <summary>
/// The amount of value-added tax on the line. The totalAmount field includes VAT, so the vatAmount can be
/// calculated with the formula totalAmount × (vatRate / (100 + vatRate)).
/// </summary>
public Amount? VatAmount { get; set; }

/// <summary>
/// The SKU, EAN, ISBN or UPC of the product sold.
/// </summary>
public string? Sku { get; set; }

/// <summary>
/// A link pointing to an image of the product sold.
/// </summary>
public string? ImageUrl { get; set; }

/// <summary>
/// A link pointing to the product page in your web shop of the product sold.
/// </summary>
public string? ProductUrl { get; set; }
}
6 changes: 6 additions & 0 deletions src/Mollie.Api/Models/Payment/Request/PaymentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public record PaymentRequest
/// </summary>
public string? WebhookUrl { get; set; }

/// <summary>
/// Optionally provide the order lines for the payment. Each line contains details such as a description of the item ordered and its price.
/// All lines must have the same currency as the payment.
/// </summary>
public List<PaymentLine>? Lines { get; set; }

/// <summary>
/// Allows you to preset the language to be used in the payment screens shown to the consumer. Setting a locale is highly
/// recommended and will greatly improve your conversion rate. When this parameter is omitted, the browser language will
Expand Down
6 changes: 6 additions & 0 deletions src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public record PaymentResponse
/// </summary>
public required string WebhookUrl { get; set; }

/// <summary>
/// Optionally provide the order lines for the payment. Each line contains details such as a description of the item ordered and its price.
/// All lines must have the same currency as the payment.
/// </summary>
public List<PaymentLine>? Lines { get; set; }

/// <summary>
/// An optional routing configuration that you provided, which enables you to route a successful payment, or part of the payment, to one or more connected accounts.
/// Additionally, you can schedule (parts of) the payment to become available on the connected account on a future date.
Expand Down
33 changes: 33 additions & 0 deletions tests/Mollie.Tests.Integration/Api/PaymentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Mollie.Api.Models.Customer.Response;
using Mollie.Api.Models.List.Response;
using Mollie.Api.Models.Mandate.Response;
using Mollie.Api.Models.Order.Request;
using Mollie.Api.Models.Payment.Request.PaymentSpecificParameters;
using Mollie.Api.Models.Payment.Response.PaymentSpecificParameters;
using Mollie.Api.Models.Terminal.Response;
Expand Down Expand Up @@ -360,6 +361,38 @@ public async Task CanCreatePaymentWithCustomMetaDataClass() {
metadataResponse.Description.Should().Be(metadataRequest.Description);
}

[DefaultRetryFact]
public async Task CanCreatePaymentWithLines() {
// Arrange
PaymentRequest paymentRequest = new PaymentRequest() {
Amount = new Amount(Currency.EUR, 90m),
Description = "Description",
RedirectUrl = DefaultRedirectUrl,
Lines = new List<PaymentLine>() {
new() {
Type = OrderLineDetailsType.Digital,
Description = "Star wars lego",
Quantity = 1,
QuantityUnit = "pcs",
UnitPrice = new Amount(Currency.EUR, 100m),
TotalAmount = new Amount(Currency.EUR, 90m),
DiscountAmount = new Amount(Currency.EUR, 10m),
ProductUrl = "http://www.lego.com/starwars",
ImageUrl = "http://www.lego.com/starwars.jpg",
Sku = "my-sku",
VatAmount = new Amount(Currency.EUR, 15.62m),
VatRate = "21.00"
}
}
};

// Act
PaymentResponse result = await _paymentClient.CreatePaymentAsync(paymentRequest);

// Assert
result.Lines.Should().BeEquivalentTo(paymentRequest.Lines);
}

[DefaultRetryFact]
public async Task CanCreatePaymentWithMandate() {
// When: We create a payment with a mandate id
Expand Down

0 comments on commit 6e37edc

Please sign in to comment.