Skip to content

Commit

Permalink
Merge branch 'pr/70' into version-2.0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed Aug 28, 2018
2 parents 3bb04a0 + 2df07fc commit 31b41f9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Mollie.Api/Client/Abstract/IPaymentMethodClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Mollie.Api.Client.Abstract {
public interface IPaymentMethodClient {
Task<PaymentMethodResponse> GetPaymentMethodAsync(PaymentMethod paymentMethod, string locale = null);
Task<PaymentMethodResponse> GetPaymentMethodAsync(PaymentMethod paymentMethod, bool? includeIssuers = null, string locale = null);
Task<ListResponse<PaymentMethodResponse>> GetPaymentMethodListAsync(SequenceType? sequenceType = null, string locale = null, Amount amount = null);
Task<PaymentMethodResponse> GetPaymentMethodAsync(UrlObjectLink<PaymentMethodResponse> url);
}
Expand Down
21 changes: 13 additions & 8 deletions Mollie.Api/Client/PaymentMethodClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ public async Task<PaymentMethodResponse> GetPaymentMethodAsync(UrlObjectLink<Pay
return await this.GetAsync(url).ConfigureAwait(false);
}

public async Task<PaymentMethodResponse> GetPaymentMethodAsync(PaymentMethod paymentMethod, string locale = null) {
Dictionary<string, string> parameters = new Dictionary<string, string>() {
{nameof(locale), locale}
};
string queryString = parameters.ToQueryString();
public async Task<PaymentMethodResponse> GetPaymentMethodAsync(PaymentMethod paymentMethod, bool? includeIssuers = null, string locale = null) {
var parameters = new Dictionary<string, string>();
if (includeIssuers == true) {
parameters.Add("include", "issuers");
}
if (locale != null) {
parameters.Add(nameof(locale), locale);
}

string queryString = parameters.ToQueryString();

return await this.GetAsync<PaymentMethodResponse>($"methods/{paymentMethod.ToString().ToLower()}{queryString}").ConfigureAwait(false);
}
}
return await this.GetAsync<PaymentMethodResponse>($"methods/{paymentMethod.ToString().ToLower()}{queryString}").ConfigureAwait(false);
}
}
}
3 changes: 2 additions & 1 deletion Mollie.Api/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Mollie.Api.Extensions {
internal static class DictionaryExtensions {
public static string ToQueryString(this Dictionary<string, string> parameters) {
if (!parameters.Any())
if (!parameters.Any()) {
return string.Empty;
}

return "?" + string.Join("&", parameters.Select(x => $"{WebUtility.UrlEncode(x.Key)}={WebUtility.UrlEncode(x.Value)}"));
}
Expand Down
9 changes: 7 additions & 2 deletions Mollie.Api/Models/Issuer/IssuerResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
namespace Mollie.Api.Models.Issuer {
public class IssuerResponse : IResponseObject {
/// <summary>
/// Contains "issuer"
/// </summary>
public string Resource { get; set; }

/// <summary>
/// The issuer's unique identifier, for example ideal_ABNANL2A. When creating a payment, specify this ID as the issuer
/// parameter to forward
Expand All @@ -13,8 +18,8 @@ public class IssuerResponse : IResponseObject {
public string Name { get; set; }

/// <summary>
/// The payment method this issuer belongs to. The Issuers API currently only supports iDEAL.
/// Different Issuer Image icons (iDEAL).
/// </summary>
public string Method { get; set; }
public IssuerResponseImage Image { get; set; }
}
}
14 changes: 14 additions & 0 deletions Mollie.Api/Models/Issuer/IssuerResponseImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Mollie.Api.Models.Issuer {
/// <summary>
/// URLs of images representing the issuer.
/// </summary>
public class IssuerResponseImage {
public string Size1x { get; set; }
public string Size2x { get; set; }
public string Svg { get; set; }

public override string ToString() {
return this.Size1x;
}
}
}
15 changes: 11 additions & 4 deletions Mollie.Api/Models/PaymentMethod/PaymentMethodResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Mollie.Api.Models.Issuer;

namespace Mollie.Api.Models.PaymentMethod {
public class PaymentMethodResponse : IResponseObject {
Expand All @@ -22,10 +24,15 @@ public class PaymentMethodResponse : IResponseObject {
/// </summary>
public PaymentMethodResponseImage Image { get; set; }

/// <summary>
/// An object with several URL objects relevant to the payment method. Every URL object will contain an href and a type field.
/// </summary>
[JsonProperty("_links")]
/// <summary>
/// List of Issuers
/// </summary>
public List<IssuerResponse> Issuers { get; set; }

/// <summary>
/// An object with several URL objects relevant to the payment method. Every URL object will contain an href and a type field.
/// </summary>
[JsonProperty("_links")]
public PaymentMethodResponseLinks Links { get; set; }

public override string ToString() {
Expand Down
31 changes: 30 additions & 1 deletion Mollie.Tests.Integration/Api/PaymentMethodTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Mollie.Api.Models.List;

using Mollie.Api.Models.Payment;
Expand Down Expand Up @@ -37,5 +38,33 @@ public async Task CanRetrieveSinglePaymentMethod(PaymentMethod method) {
Assert.IsNotNull(paymentMethod.Id);
Assert.AreEqual(method, paymentMethod.Id);
}

[Test]
public async Task CanRetrieveIdealIssuers() {
// When: retrieving the ideal method we can include the issuers
PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, true);

// Then: We should have one or multiple issuers
Assert.IsNotNull(paymentMethod);
Assert.IsTrue(paymentMethod.Issuers.Any());
}

[Test]
public async Task DoNotRetrieveIssuersWhenIncludeIsFalse() {
// When: retrieving the ideal method with the include parameter set to false
PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, false);

// Then: Issuers should not be included
Assert.IsNull(paymentMethod.Issuers);
}

[Test]
public async Task DoNotRetrieveIssuersWhenIncludeIsNull() {
// When: retrieving the ideal method with the include parameter set to null
PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, null);

// Then: Issuers should not be included
Assert.IsNull(paymentMethod.Issuers);
}
}
}

0 comments on commit 31b41f9

Please sign in to comment.