Skip to content

Commit

Permalink
Add support for the payment billing/shipping address properties (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed Jul 9, 2024
1 parent 7ba1bcb commit 06ba339
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Mollie.Api/Models/AddressObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ public record AddressObject {
/// </summary>
public string? Country { get; set; }
}
}
}
35 changes: 35 additions & 0 deletions src/Mollie.Api/Models/Payment/PaymentAddressDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Mollie.Api.Models.Payment;

public record PaymentAddressDetails : AddressObject {
/// <summary>
/// The person’s organization, if applicable.
/// </summary>
public string? OrganizationName { get; set; }

/// <summary>
/// The title of the person, for example Mr. or Mrs..
/// </summary>
public string? Title { get; set; }

/// <summary>
/// The given name (first name) of the person.
/// </summary>
public string? GivenName { get; set; }

/// <summary>
/// The family name (surname) of the person.
/// </summary>
public string? FamilyName { get; set; }

/// <summary>
/// The email address of the person.
/// </summary>
public string? Email { get; set; }

/// <summary>
/// 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.
/// </summary>
public string? Phone { get; set; }
}
12 changes: 12 additions & 0 deletions src/Mollie.Api/Models/Payment/Request/PaymentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public record PaymentRequest
/// </summary>
public List<PaymentLine>? Lines { get; set; }

/// <summary>
/// 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.
/// </summary>
public PaymentAddressDetails? BillingAddress { get; set; }

/// <summary>
/// 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.
/// </summary>
public PaymentAddressDetails? ShippingAddress { 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
12 changes: 12 additions & 0 deletions src/Mollie.Api/Models/Payment/Response/PaymentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ public record PaymentResponse
/// </summary>
public List<PaymentLine>? Lines { get; set; }

/// <summary>
/// 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.
/// </summary>
public PaymentAddressDetails? BillingAddress { get; set; }

/// <summary>
/// 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.
/// </summary>
public PaymentAddressDetails? ShippingAddress { 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
19 changes: 18 additions & 1 deletion tests/Mollie.Tests.Integration/Api/PaymentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]",
City = "Amsterdam",
Country = "NL",
Phone = "+31600000000",
Region = "Zuid-Holland",
PostalCode = "1015CW"
};
PaymentRequest paymentRequest = new PaymentRequest() {
Amount = new Amount(Currency.EUR, 90m),
Description = "Description",
Expand All @@ -382,14 +395,18 @@ public async Task CanCreatePaymentWithLines() {
VatAmount = new Amount(Currency.EUR, 15.62m),
VatRate = "21.00"
}
}
},
ShippingAddress = address,
BillingAddress = address
};

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

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

[DefaultRetryFact]
Expand Down

0 comments on commit 06ba339

Please sign in to comment.