Skip to content

Commit

Permalink
#266 Allow multiple payment methods to be passed in the OrderPaymentR…
Browse files Browse the repository at this point in the history
…equest object
  • Loading branch information
Viincenttt committed Jul 25, 2022
1 parent cd13a49 commit ffb3dfb
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 9 deletions.
42 changes: 35 additions & 7 deletions Mollie.Api/Models/Order/Request/OrderPaymentRequest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
namespace Mollie.Api.Models.Order {
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

namespace Mollie.Api.Models.Order {
public class OrderPaymentRequest {
/// <summary>
/// Normally, a payment method screen is shown. However, when using this parameter, you can choose a
/// specific payment method and your customer will skip the selection screen and is sent directly to
/// the chosen payment method. The parameter enables you to fully integrate the payment method
/// selection into your website. See the Mollie.Api.Models.Payment.PaymentMethod class for a full
/// list of known values.
/// Normally, a payment method selection screen is shown. However, when using this parameter, your customer will skip the
/// selection screen and will be sent directly to the chosen payment method. The parameter enables you to fully integrate
/// the payment method selection into your website, however note Mollie’s country based conversion optimization is lost.
/// See the Mollie.Api.Models.Payment.PaymentMethod class for a full list of known values.
/// </summary>
[JsonIgnore]
public string Method {
get {
return this.Methods.FirstOrDefault();
}
set {
if (value == null) {
this.Methods = null;
}
else {
this.Methods = new List<string>();
this.Methods.Add(value);
}
}
}

/// <summary>
/// Normally, a payment method screen is shown. However, when using this parameter, you can choose a specific payment method
/// and your customer will skip the selection screen and is sent directly to the chosen payment method. The parameter
/// enables you to fully integrate the payment method selection into your website.
/// You can also specify the methods in an array.By doing so we will still show the payment method selection screen but will
/// only show the methods specified in the array. For example, you can use this functionality to only show payment methods
/// from a specific country to your customer.
/// </summary>
public string Method { get; set; }
[JsonProperty("method")]
public IList<string> Methods { get; set; }

/// <summary>
/// The ID of the Customer for whom the payment is being created. This is used for recurring payments
Expand Down
65 changes: 63 additions & 2 deletions Mollie.Tests.Unit/Client/OrderClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Mollie.Api.Models.Payment.Response;

namespace Mollie.Tests.Unit.Client {
[TestFixture]
Expand All @@ -20,6 +21,14 @@ public class OrderClientTests : BaseClientTests {
""currency"": ""EUR""
},
}";

private const string defaultPaymentJsonResponse = @"{
""amount"":{
""currency"":""EUR"",
""value"":""100.00""
},
""description"":""Description"",
""redirectUrl"":""http://www.mollie.com""}";

[Test]
public async Task GetOrderAsync_NoEmbedParameters_QueryStringIsEmpty() {
Expand Down Expand Up @@ -106,8 +115,8 @@ public async Task CreateOrderAsync_MultiplePaymentMethods_RequestIsSerializedInE
OrderRequest orderRequest = this.CreateOrderRequestWithOnlyRequiredFields();
orderRequest.Methods = new List<string>() {
PaymentMethod.Ideal,
PaymentMethod.CreditCard,
PaymentMethod.DirectDebit
PaymentMethod.CreditCard,
PaymentMethod.DirectDebit
};
string expectedPaymentMethodJson = $"\"method\":[\"{PaymentMethod.Ideal}\",\"{PaymentMethod.CreditCard}\",\"{PaymentMethod.DirectDebit}\"]";
const string jsonResponse = defaultOrderJsonResponse;
Expand All @@ -121,6 +130,58 @@ public async Task CreateOrderAsync_MultiplePaymentMethods_RequestIsSerializedInE
// Then
mockHttp.VerifyNoOutstandingExpectation();
}

[Test]
public async Task CreateOrderPaymentAsync_PaymentWithSinglePaymentMethod_RequestIsSerializedInExpectedFormat() {
// Given: We create a payment request with multiple payment methods
OrderPaymentRequest orderPaymentRequest = new OrderPaymentRequest() {
CustomerId = "customer-id",
Testmode = true,
MandateId = "mandate-id",
Methods = new List<string>() {
PaymentMethod.Ideal
}
};
const string orderId = "order-id";
string url = $"{BaseMollieClient.ApiEndPoint}orders/{orderId}/payments";
string expectedPaymentMethodJson = $"\"method\":[\"{PaymentMethod.Ideal}\"]";
var mockHttp = this.CreateMockHttpMessageHandler(HttpMethod.Post, url, defaultPaymentJsonResponse, expectedPaymentMethodJson);
HttpClient httpClient = mockHttp.ToHttpClient();
OrderClient orderClient = new OrderClient("abcde", httpClient);

// When: We send the request
await orderClient.CreateOrderPaymentAsync(orderId, orderPaymentRequest);

// Then
mockHttp.VerifyNoOutstandingExpectation();
}

[Test]
public async Task CreateOrderPaymentAsync_PaymentWithMultiplePaymentMethods_RequestIsSerializedInExpectedFormat() {
// Given: We create a payment request with multiple payment methods
OrderPaymentRequest orderPaymentRequest = new OrderPaymentRequest() {
CustomerId = "customer-id",
Testmode = true,
MandateId = "mandate-id",
Methods = new List<string>() {
PaymentMethod.Ideal,
PaymentMethod.CreditCard,
PaymentMethod.DirectDebit
}
};
const string orderId = "order-id";
string url = $"{BaseMollieClient.ApiEndPoint}orders/{orderId}/payments";
string expectedPaymentMethodJson = $"\"method\":[\"{PaymentMethod.Ideal}\",\"{PaymentMethod.CreditCard}\",\"{PaymentMethod.DirectDebit}\"]";
var mockHttp = this.CreateMockHttpMessageHandler(HttpMethod.Post, url, defaultPaymentJsonResponse, expectedPaymentMethodJson);
HttpClient httpClient = mockHttp.ToHttpClient();
OrderClient orderClient = new OrderClient("abcde", httpClient);

// When: We send the request
await orderClient.CreateOrderPaymentAsync(orderId, orderPaymentRequest);

// Then
mockHttp.VerifyNoOutstandingExpectation();
}

private OrderRequest CreateOrderRequestWithOnlyRequiredFields() {
return new OrderRequest() {
Expand Down

0 comments on commit ffb3dfb

Please sign in to comment.