From 59e04ea882d50fd240ca34f44b425b08cbb239e5 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 9 Jul 2024 18:36:18 +0200 Subject: [PATCH] Create PaymentAddressDetails record and add integration test --- src/Mollie.Api/Models/AddressObject.cs | 25 ------------- .../Models/Payment/PaymentAddressDetails.cs | 35 +++++++++++++++++++ .../Models/Payment/Request/PaymentRequest.cs | 4 +-- .../Payment/Response/PaymentResponse.cs | 4 +-- .../Api/PaymentTests.cs | 19 +++++++++- 5 files changed, 57 insertions(+), 30 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 f70ddd95..be0e67c8 100644 --- a/src/Mollie.Api/Models/AddressObject.cs +++ b/src/Mollie.Api/Models/AddressObject.cs @@ -1,25 +1,5 @@ namespace Mollie.Api.Models { public record AddressObject { - /// - /// The title of the person, for example Mr. or Mrs.. - /// - public string? Title { get; set; } - - /// - /// The given name (first name) of the person should be at least two characters and cannot contain only numbers. - /// - public string? GivenName { get; set; } - - /// - /// The given family name (surname) of the person should be at least two characters and cannot contain only numbers. - /// - public string? FamilyName { get; set; } - - /// - /// The name of the organization, in case the addressee is an organization. - /// - public string? OrganizationName { get; set; } - /// /// The card holder’s street and street number. /// @@ -35,11 +15,6 @@ public record AddressObject { /// public string? PostalCode { get; set; } - /// - /// Email address - /// - public string? Email { get; set; } - /// /// The card holder’s city. /// 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 c80dfc2b..578fca18 100644 --- a/src/Mollie.Api/Models/Payment/Request/PaymentRequest.cs +++ b/src/Mollie.Api/Models/Payment/Request/PaymentRequest.cs @@ -51,13 +51,13 @@ public record PaymentRequest /// 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 AddressObject? BillingAddress { get; set; } + 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 AddressObject? ShippingAddress { get; set; } + 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 diff --git a/src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs b/src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs index 3aa8a697..023d2269 100644 --- a/src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs +++ b/src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs @@ -137,13 +137,13 @@ public record PaymentResponse /// 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 AddressObject? BillingAddress { get; set; } + 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 AddressObject? ShippingAddress { get; set; } + 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. 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]