From 06ba3392657d8e20e587559cbaf2e2fa314b586e Mon Sep 17 00:00:00 2001 From: Vincent Kok Date: Tue, 9 Jul 2024 18:41:08 +0200 Subject: [PATCH] Add support for the payment billing/shipping address properties (#381) --- src/Mollie.Api/Models/AddressObject.cs | 2 +- .../Models/Payment/PaymentAddressDetails.cs | 35 +++++++++++++++++++ .../Models/Payment/Request/PaymentRequest.cs | 12 +++++++ .../Payment/Response/PaymentResponse.cs | 12 +++++++ .../Api/PaymentTests.cs | 19 +++++++++- 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/Mollie.Api/Models/Payment/PaymentAddressDetails.cs diff --git a/src/Mollie.Api/Models/AddressObject.cs b/src/Mollie.Api/Models/AddressObject.cs index 9b8d5f96..be0e67c8 100644 --- a/src/Mollie.Api/Models/AddressObject.cs +++ b/src/Mollie.Api/Models/AddressObject.cs @@ -30,4 +30,4 @@ public record AddressObject { /// public string? Country { get; set; } } -} \ No newline at end of file +} diff --git a/src/Mollie.Api/Models/Payment/PaymentAddressDetails.cs b/src/Mollie.Api/Models/Payment/PaymentAddressDetails.cs new file mode 100644 index 00000000..b23af7d9 --- /dev/null +++ b/src/Mollie.Api/Models/Payment/PaymentAddressDetails.cs @@ -0,0 +1,35 @@ +namespace Mollie.Api.Models.Payment; + +public record PaymentAddressDetails : AddressObject { + /// + /// The person’s organization, if applicable. + /// + public string? OrganizationName { get; set; } + + /// + /// The title of the person, for example Mr. or Mrs.. + /// + public string? Title { get; set; } + + /// + /// The given name (first name) of the person. + /// + public string? GivenName { get; set; } + + /// + /// The family name (surname) of the person. + /// + public string? FamilyName { get; set; } + + /// + /// The email address of the person. + /// + public string? Email { get; set; } + + /// + /// The phone number of the person. Some payment methods require this information. If you have it, you + /// should pass it so that your customer does not have to enter it again in the checkout. Must be in + /// the E.164 format. For example +31208202070. + /// + public string? Phone { get; set; } +} diff --git a/src/Mollie.Api/Models/Payment/Request/PaymentRequest.cs b/src/Mollie.Api/Models/Payment/Request/PaymentRequest.cs index 518230c9..578fca18 100644 --- a/src/Mollie.Api/Models/Payment/Request/PaymentRequest.cs +++ b/src/Mollie.Api/Models/Payment/Request/PaymentRequest.cs @@ -47,6 +47,18 @@ public record PaymentRequest /// public List? Lines { get; set; } + /// + /// The customer's billing address details. We advise to provide these details to improve fraud protection and conversion. This is + /// particularly relevant for card payments. + /// + public PaymentAddressDetails? BillingAddress { get; set; } + + /// + /// The customer's shipping address details. We advise to provide these details to improve fraud protection and conversion. This is + /// particularly relevant for card payments. + /// + public PaymentAddressDetails? ShippingAddress { get; set; } + /// /// 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 diff --git a/src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs b/src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs index 022d37d8..023d2269 100644 --- a/src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs +++ b/src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs @@ -133,6 +133,18 @@ public record PaymentResponse /// public List? Lines { get; set; } + /// + /// The customer's billing address details. We advise to provide these details to improve fraud protection and conversion. This is + /// particularly relevant for card payments. + /// + public PaymentAddressDetails? BillingAddress { get; set; } + + /// + /// The customer's shipping address details. We advise to provide these details to improve fraud protection and conversion. This is + /// particularly relevant for card payments. + /// + public PaymentAddressDetails? ShippingAddress { get; set; } + /// /// 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. diff --git a/tests/Mollie.Tests.Integration/Api/PaymentTests.cs b/tests/Mollie.Tests.Integration/Api/PaymentTests.cs index bc760671..41e9447c 100644 --- a/tests/Mollie.Tests.Integration/Api/PaymentTests.cs +++ b/tests/Mollie.Tests.Integration/Api/PaymentTests.cs @@ -363,6 +363,19 @@ public async Task CanCreatePaymentWithCustomMetaDataClass() { [DefaultRetryFact] public async Task CanCreatePaymentWithLines() { // Arrange + var address = new PaymentAddressDetails { + Title = "Mr", + GivenName = "John", + FamilyName = "Doe", + OrganizationName = "Mollie", + StreetAndNumber = "Keizersgracht 126", + Email = "johndoe@mollie.com", + City = "Amsterdam", + Country = "NL", + Phone = "+31600000000", + Region = "Zuid-Holland", + PostalCode = "1015CW" + }; PaymentRequest paymentRequest = new PaymentRequest() { Amount = new Amount(Currency.EUR, 90m), Description = "Description", @@ -382,7 +395,9 @@ public async Task CanCreatePaymentWithLines() { VatAmount = new Amount(Currency.EUR, 15.62m), VatRate = "21.00" } - } + }, + ShippingAddress = address, + BillingAddress = address }; // Act @@ -390,6 +405,8 @@ public async Task CanCreatePaymentWithLines() { // Assert result.Lines.Should().BeEquivalentTo(paymentRequest.Lines); + result.BillingAddress.Should().BeEquivalentTo(paymentRequest.BillingAddress); + result.ShippingAddress.Should().BeEquivalentTo(paymentRequest.ShippingAddress); } [DefaultRetryFact]