From 6e33de0523b160ceec749908dbb4190f9c1a4ddc Mon Sep 17 00:00:00 2001 From: Lex Goudriaan Date: Wed, 13 Feb 2019 14:11:49 +0100 Subject: [PATCH 1/7] Add missing payment method endpoints --- .../Client/Abstract/IPaymentMethodClient.cs | 6 +- Mollie.Api/Client/PaymentMethodClient.cs | 79 ++++++++++++++----- Mollie.Api/Models/Payment/PaymentMethod.cs | 2 + .../PaymentMethod/PaymentMethodResponse.cs | 12 ++- .../Pricing/FixedPricingResponse.cs | 15 ++++ .../PaymentMethod/Pricing/PricingResponse.cs | 20 +++++ .../Api/PaymentMethodTests.cs | 64 ++++++++++++++- 7 files changed, 172 insertions(+), 26 deletions(-) create mode 100644 Mollie.Api/Models/PaymentMethod/Pricing/FixedPricingResponse.cs create mode 100644 Mollie.Api/Models/PaymentMethod/Pricing/PricingResponse.cs diff --git a/Mollie.Api/Client/Abstract/IPaymentMethodClient.cs b/Mollie.Api/Client/Abstract/IPaymentMethodClient.cs index 89bc6e82..8edd3134 100644 --- a/Mollie.Api/Client/Abstract/IPaymentMethodClient.cs +++ b/Mollie.Api/Client/Abstract/IPaymentMethodClient.cs @@ -1,15 +1,15 @@ using System.Threading.Tasks; using Mollie.Api.Models; using Mollie.Api.Models.List; - using Mollie.Api.Models.Payment; using Mollie.Api.Models.PaymentMethod; using Mollie.Api.Models.Url; namespace Mollie.Api.Client.Abstract { public interface IPaymentMethodClient { - Task GetPaymentMethodAsync(PaymentMethod paymentMethod, bool? includeIssuers = null, string locale = null); - Task> GetPaymentMethodListAsync(SequenceType? sequenceType = null, string locale = null, Amount amount = null); + Task GetPaymentMethodAsync(PaymentMethod paymentMethod, bool? includeIssuers = null, string locale = null, bool? includePricing = null, string profileId = null, bool? testmode = null); + Task> GetAllPaymentMethodListAsync(string locale = null, bool? includeIssuers = null, bool? includePricing = null); + Task> GetPaymentMethodListAsync(SequenceType? sequenceType = null, string locale = null, Amount amount = null, bool? includeIssuers = null, bool? includePricing = null, string profileId = null, bool? testmode = null); Task GetPaymentMethodAsync(UrlObjectLink url); } } \ No newline at end of file diff --git a/Mollie.Api/Client/PaymentMethodClient.cs b/Mollie.Api/Client/PaymentMethodClient.cs index b3c9a63a..a83523a6 100644 --- a/Mollie.Api/Client/PaymentMethodClient.cs +++ b/Mollie.Api/Client/PaymentMethodClient.cs @@ -5,43 +5,84 @@ using Mollie.Api.Extensions; using Mollie.Api.Models; using Mollie.Api.Models.List; - using Mollie.Api.Models.Payment; using Mollie.Api.Models.PaymentMethod; using Mollie.Api.Models.Url; -namespace Mollie.Api.Client { - public class PaymentMethodClient : BaseMollieClient, IPaymentMethodClient { - public PaymentMethodClient(string apiKey, HttpClient httpClient = null) : base(apiKey, httpClient) { +namespace Mollie.Api.Client +{ + public class PaymentMethodClient : BaseMollieClient, IPaymentMethodClient + { + public PaymentMethodClient(string apiKey, HttpClient httpClient = null) : base(apiKey, httpClient) + { + } + + public async Task GetPaymentMethodAsync(PaymentMethod paymentMethod, bool? includeIssuers = null, string locale = null, bool? includePricing = null, string profileId = null, bool? testmode = null) + { + Dictionary parameters = new Dictionary(); + + parameters.AddValueIfNotNullOrEmpty("locale", locale); + AddOauthParameters(parameters, profileId, testmode); + AddIncludeParameters(parameters, includeIssuers, includePricing); + + return await this.GetAsync($"methods/{paymentMethod.ToString().ToLower()}{parameters.ToQueryString()}").ConfigureAwait(false); } - public async Task> GetPaymentMethodListAsync(SequenceType? sequenceType = null, string locale = null, Amount amount = null) { + public async Task> GetAllPaymentMethodListAsync(string locale = null, bool? includeIssuers = null, bool? includePricing = null) + { + Dictionary parameters = new Dictionary(); + + parameters.AddValueIfNotNullOrEmpty("locale", locale); + AddIncludeParameters(parameters, includeIssuers, includePricing); + + return await this.GetListAsync>("methods/all", null, null, parameters).ConfigureAwait(false); + } + + public async Task> GetPaymentMethodListAsync(SequenceType? sequenceType = null, string locale = null, Amount amount = null, bool? includeIssuers = null, bool? includePricing = null, string profileId = null, bool? testmode = null) + { Dictionary parameters = new Dictionary() { - {nameof(sequenceType), sequenceType.ToString().ToLower()}, - {nameof(locale), locale}, + {"sequenceType", sequenceType.ToString().ToLower()}, + {"locale", locale}, {"amount[value]", amount?.Value}, {"amount[currency]", amount?.Currency} }; + AddOauthParameters(parameters, profileId, testmode); + AddIncludeParameters(parameters, includeIssuers, includePricing); + return await this.GetListAsync>("methods", null, null, parameters).ConfigureAwait(false); } - public async Task GetPaymentMethodAsync(UrlObjectLink url) { + public async Task GetPaymentMethodAsync(UrlObjectLink url) + { return await this.GetAsync(url).ConfigureAwait(false); } - public async Task GetPaymentMethodAsync(PaymentMethod paymentMethod, bool? includeIssuers = null, string locale = null) { - var parameters = new Dictionary(); - if (includeIssuers == true) { - parameters.Add("include", "issuers"); + private void AddOauthParameters(Dictionary parameters, string profileId = null, bool? testmode = null) + { + if (!string.IsNullOrWhiteSpace(profileId) || testmode.HasValue) + { + this.ValidateApiKeyIsOauthAccesstoken(); + + parameters.AddValueIfNotNullOrEmpty("profileId", profileId); + if (testmode.HasValue) + { + parameters.AddValueIfNotNullOrEmpty("testmode", testmode.Value.ToString().ToLower()); + } } - if (locale != null) { - parameters.Add(nameof(locale), locale); + } + + private void AddIncludeParameters(Dictionary parameters, bool? includeIssuers = null, bool? includePricing = null) + { + if (includeIssuers == true) + { + parameters.Add("include", "issuers"); } - - string queryString = parameters.ToQueryString(); - return await this.GetAsync($"methods/{paymentMethod.ToString().ToLower()}{queryString}").ConfigureAwait(false); - } - } + if (includePricing == true) + { + parameters.Add("include", "pricing"); + } + } + } } \ No newline at end of file diff --git a/Mollie.Api/Models/Payment/PaymentMethod.cs b/Mollie.Api/Models/Payment/PaymentMethod.cs index 12330070..e135ee91 100644 --- a/Mollie.Api/Models/Payment/PaymentMethod.cs +++ b/Mollie.Api/Models/Payment/PaymentMethod.cs @@ -21,5 +21,7 @@ public enum PaymentMethod { [EnumMember(Value = "paysafecard")] PaySafeCard, [EnumMember(Value = "sofort")] Sofort, [EnumMember(Value = "refund")] Refund, + [EnumMember(Value = "klarnapaylater")] KlarnaPayLater, + [EnumMember(Value = "klarnasliceit")] KlarnaSliceIt, } } \ No newline at end of file diff --git a/Mollie.Api/Models/PaymentMethod/PaymentMethodResponse.cs b/Mollie.Api/Models/PaymentMethod/PaymentMethodResponse.cs index e4a98679..2eaf4f6a 100644 --- a/Mollie.Api/Models/PaymentMethod/PaymentMethodResponse.cs +++ b/Mollie.Api/Models/PaymentMethod/PaymentMethodResponse.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; using Mollie.Api.Models.Issuer; +using Mollie.Api.Models.PaymentMethod.Pricing; namespace Mollie.Api.Models.PaymentMethod { public class PaymentMethodResponse : IResponseObject { @@ -15,20 +16,25 @@ public class PaymentMethodResponse : IResponseObject { public Payment.PaymentMethod Id { get; set; } /// - /// The full name of the payment method. + /// The full name of the payment method. /// public string Description { get; set; } /// - /// URLs of images representing the payment method. + /// URLs of images representing the payment method. /// public PaymentMethodResponseImage Image { get; set; } /// - /// List of Issuers + /// List of Issuers /// public List Issuers { get; set; } + /// + /// Pricing set of the payment method what will be include if you add the parameter. + /// + public List Pricing { get; set; } + /// /// An object with several URL objects relevant to the payment method. Every URL object will contain an href and a type field. /// diff --git a/Mollie.Api/Models/PaymentMethod/Pricing/FixedPricingResponse.cs b/Mollie.Api/Models/PaymentMethod/Pricing/FixedPricingResponse.cs new file mode 100644 index 00000000..2006fcf1 --- /dev/null +++ b/Mollie.Api/Models/PaymentMethod/Pricing/FixedPricingResponse.cs @@ -0,0 +1,15 @@ +namespace Mollie.Api.Models.PaymentMethod.Pricing +{ + public class FixedPricingResponse : IResponseObject + { + /// + /// The ISO 4217 currency code. + /// + public string Currency { get; set; } + + /// + /// A string containing the exact amount in the given currency. + /// + public decimal Value { get; set; } + } +} \ No newline at end of file diff --git a/Mollie.Api/Models/PaymentMethod/Pricing/PricingResponse.cs b/Mollie.Api/Models/PaymentMethod/Pricing/PricingResponse.cs new file mode 100644 index 00000000..d2022c76 --- /dev/null +++ b/Mollie.Api/Models/PaymentMethod/Pricing/PricingResponse.cs @@ -0,0 +1,20 @@ +namespace Mollie.Api.Models.PaymentMethod.Pricing +{ + public class PricingResponse : IResponseObject + { + /// + /// The area or product-type where the pricing is applied for, translated in the optional locale passed. + /// + public string Description { get; set; } + + /// + /// The fixed price per transaction + /// + public FixedPricingResponse Fixed { get; set; } + + /// + /// A string containing the percentage what will be charged over the payment amount besides the fixed price. + /// + public decimal Variable { get; set; } + } +} \ No newline at end of file diff --git a/Mollie.Tests.Integration/Api/PaymentMethodTests.cs b/Mollie.Tests.Integration/Api/PaymentMethodTests.cs index de63b1aa..06c2a193 100644 --- a/Mollie.Tests.Integration/Api/PaymentMethodTests.cs +++ b/Mollie.Tests.Integration/Api/PaymentMethodTests.cs @@ -1,7 +1,6 @@ using System.Linq; using System.Threading.Tasks; using Mollie.Api.Models.List; - using Mollie.Api.Models.Payment; using Mollie.Api.Models.PaymentMethod; using Mollie.Tests.Integration.Framework; @@ -10,6 +9,7 @@ namespace Mollie.Tests.Integration.Api { [TestFixture] public class PaymentMethodTests : BaseMollieApiTestClass { + [Test] public async Task CanRetrievePaymentMethodList() { // When: Retrieve payment list with default settings @@ -66,5 +66,67 @@ public async Task DoNotRetrieveIssuersWhenIncludeIsNull() { // Then: Issuers should not be included Assert.IsNull(paymentMethod.Issuers); } + + [Test] + public async Task CanRetrievePricing() + { + // When: retrieving the ideal method we can include the issuers + PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, includePricing: true); + + // Then: We should have one or multiple issuers + Assert.IsNotNull(paymentMethod); + Assert.IsTrue(paymentMethod.Pricing.Any()); + } + + [Test] + public async Task DoNotRetrievePricingWhenIncludeIsFalse() + { + // When: retrieving the ideal method with the include parameter set to false + PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, includePricing: false); + + // Then: Issuers should not be included + Assert.IsNull(paymentMethod.Pricing); + } + + [Test] + public async Task DoNotRetrievePricingWhenIncludeIsNull() + { + // When: retrieving the ideal method with the include parameter set to null + PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, includePricing: null); + + // Then: Issuers should not be included + Assert.IsNull(paymentMethod.Pricing); + } + + [Test] + public async Task CanRetrieveAllMethods() + { + // When: retrieving the all mollie payment methods + ListResponse paymentMethods = await this._paymentMethodClient.GetAllPaymentMethodListAsync(); + + // Then: We should have multiple issuers + Assert.IsNotNull(paymentMethods); + Assert.IsTrue(paymentMethods.Items.Any()); + } + + [Test] + public async Task CanRetrievePricingForAllMethods() + { + // When: retrieving the ideal method we can include the issuers + ListResponse paymentMethods = await this._paymentMethodClient.GetAllPaymentMethodListAsync(includePricing: true); + + // Then: We should have prices available + Assert.IsTrue(paymentMethods.Items.Any(x => x.Pricing != null && x.Pricing.Any(y => y.Fixed.Value > 0))); + } + + [Test] + public async Task CanRetrieveIssuersForAllMethods() + { + // When: retrieving the all mollie payment methods we can include the issuers + ListResponse paymentMethods = await this._paymentMethodClient.GetAllPaymentMethodListAsync(includeIssuers: true); + + // Then: We should have one or multiple issuers + Assert.IsTrue(paymentMethods.Items.Any(x => x.Issuers != null)); + } } } \ No newline at end of file From 35f5c6a90e2f56193559054978a741c5788510a1 Mon Sep 17 00:00:00 2001 From: Lex Goudriaan Date: Wed, 13 Feb 2019 14:14:03 +0100 Subject: [PATCH 2/7] Add dictionary extensions tests --- Mollie.Api/Extensions/DictionaryExtensions.cs | 2 + .../Extensions/DictionaryExtensionsTests.cs | 73 +++++++++++++++++++ .../Mollie.Tests.Integration.csproj | 1 + 3 files changed, 76 insertions(+) create mode 100644 Mollie.Tests.Integration/Extensions/DictionaryExtensionsTests.cs diff --git a/Mollie.Api/Extensions/DictionaryExtensions.cs b/Mollie.Api/Extensions/DictionaryExtensions.cs index 4581efaf..8c784bca 100644 --- a/Mollie.Api/Extensions/DictionaryExtensions.cs +++ b/Mollie.Api/Extensions/DictionaryExtensions.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; using System.Net; +using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Mollie.Tests.Integration")] namespace Mollie.Api.Extensions { internal static class DictionaryExtensions { public static string ToQueryString(this IDictionary parameters) { diff --git a/Mollie.Tests.Integration/Extensions/DictionaryExtensionsTests.cs b/Mollie.Tests.Integration/Extensions/DictionaryExtensionsTests.cs new file mode 100644 index 00000000..b27eb651 --- /dev/null +++ b/Mollie.Tests.Integration/Extensions/DictionaryExtensionsTests.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using System.Linq; +using Mollie.Api.Extensions; +using NUnit.Framework; + +namespace Mollie.Tests.Integration.Extensions +{ + [TestFixture] + public class DictionaryExtensionsTests + { + + [Test] + public void CanCreateUrlQueryFromDictionary() + { + // Arrange + var parameters = new Dictionary() + { + {"include", "issuers"}, + {"testmode", "true"} + }; + var expected = "?include=issuers&testmode=true"; + + // Act + var result = parameters.ToQueryString(); + + // Assert + Assert.AreEqual(expected, result); + } + + [Test] + public void CanCreateUrlQueryFromEmptyDictionary() + { + // Arrange + var parameters = new Dictionary(); + string expected = string.Empty; + + // Act + var result = parameters.ToQueryString(); + + // Assert + Assert.AreEqual(expected, result); + } + + [Test] + public void CanAddParameterToDictionaryIfNotEmptyDictionary() + { + // Arrange + var parameters = new Dictionary(); + var parameterName = "include"; + var parameterValue = "issuers"; + + // Act + parameters.AddValueIfNotNullOrEmpty(parameterName, parameterValue); + + // Assert + Assert.IsTrue(parameters.Any()); + Assert.AreEqual(parameterValue, parameters[parameterName]); + } + + [Test] + public void CannotAddParameterToDictionaryIfEmptyDictionary() + { + // Arrange + var parameters = new Dictionary(); + + // Act + parameters.AddValueIfNotNullOrEmpty("include", ""); + + // Assert + Assert.IsFalse(parameters.Any()); + } + } +} diff --git a/Mollie.Tests.Integration/Mollie.Tests.Integration.csproj b/Mollie.Tests.Integration/Mollie.Tests.Integration.csproj index d94f36a2..c0fa8a55 100644 --- a/Mollie.Tests.Integration/Mollie.Tests.Integration.csproj +++ b/Mollie.Tests.Integration/Mollie.Tests.Integration.csproj @@ -116,6 +116,7 @@ + From 0379913cd347dd5e06bbcaef9e41bd087728c683 Mon Sep 17 00:00:00 2001 From: Lex Goudriaan Date: Wed, 13 Feb 2019 14:43:28 +0100 Subject: [PATCH 3/7] Add przelewy24 payment method Closes #104 --- Mollie.Api/Models/Payment/PaymentMethod.cs | 1 + .../Payment/Request/Przelewy24PaymentRequest.cs | 15 +++++++++++++++ Mollie.Tests.Integration/Api/PaymentTests.cs | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Mollie.Api/Models/Payment/Request/Przelewy24PaymentRequest.cs diff --git a/Mollie.Api/Models/Payment/PaymentMethod.cs b/Mollie.Api/Models/Payment/PaymentMethod.cs index e135ee91..fb29a4b0 100644 --- a/Mollie.Api/Models/Payment/PaymentMethod.cs +++ b/Mollie.Api/Models/Payment/PaymentMethod.cs @@ -23,5 +23,6 @@ public enum PaymentMethod { [EnumMember(Value = "refund")] Refund, [EnumMember(Value = "klarnapaylater")] KlarnaPayLater, [EnumMember(Value = "klarnasliceit")] KlarnaSliceIt, + [EnumMember(Value = "przelewy24")] Przelewy24, } } \ No newline at end of file diff --git a/Mollie.Api/Models/Payment/Request/Przelewy24PaymentRequest.cs b/Mollie.Api/Models/Payment/Request/Przelewy24PaymentRequest.cs new file mode 100644 index 00000000..99af12e6 --- /dev/null +++ b/Mollie.Api/Models/Payment/Request/Przelewy24PaymentRequest.cs @@ -0,0 +1,15 @@ +namespace Mollie.Api.Models.Payment.Request +{ + public class Przelewy24PaymentRequest : PaymentRequest + { + public Przelewy24PaymentRequest() + { + this.Method = PaymentMethod.Przelewy24; + } + + /// + /// Consumer’s email address, this is required for Przelewy24 payments. + /// + public string BillingEmail { get; set; } + } +} \ No newline at end of file diff --git a/Mollie.Tests.Integration/Api/PaymentTests.cs b/Mollie.Tests.Integration/Api/PaymentTests.cs index a0357b91..ea5466f0 100644 --- a/Mollie.Tests.Integration/Api/PaymentTests.cs +++ b/Mollie.Tests.Integration/Api/PaymentTests.cs @@ -13,7 +13,6 @@ namespace Mollie.Tests.Integration.Api { using System.Linq; - using Mollie.Api.Models.Customer; using Mollie.Api.Models.Mandate; @@ -115,6 +114,7 @@ public async Task CanCreateDefaultPaymentWithAllFields() { [TestCase(typeof(PaymentRequest), PaymentMethod.Belfius, typeof(BelfiusPaymentResponse))] [TestCase(typeof(KbcPaymentRequest), PaymentMethod.Kbc, typeof(KbcPaymentResponse))] [TestCase(typeof(PaymentRequest), null, typeof(PaymentResponse))] + //[TestCase(typeof(Przelewy24PaymentRequest), PaymentMethod.Przelewy24, typeof(PaymentResponse))] // Payment option is not enabled in website profile public async Task CanCreateSpecificPaymentType(Type paymentType, PaymentMethod? paymentMethod, Type expectedResponseType) { // If: we create a specific payment type with some bank transfer specific values PaymentRequest paymentRequest = (PaymentRequest) Activator.CreateInstance(paymentType); @@ -123,6 +123,12 @@ public async Task CanCreateSpecificPaymentType(Type paymentType, PaymentMethod? paymentRequest.RedirectUrl = this.DefaultRedirectUrl; paymentRequest.Method = paymentMethod; + // Set required billing email for Przelewy24 + if (paymentRequest is Przelewy24PaymentRequest request) + { + request.BillingEmail = "example@example.com"; + } + // When: We send the payment request to Mollie PaymentResponse result = await this._paymentClient.CreatePaymentAsync(paymentRequest); From 823c7a0138adda36e4c6bec0f5b24db24113d787 Mon Sep 17 00:00:00 2001 From: Lex Goudriaan Date: Wed, 20 Feb 2019 17:29:23 +0100 Subject: [PATCH 4/7] Add list organizations functionality --- Mollie.Api/Client/Abstract/IOrganizationsClient.cs | 6 +++++- Mollie.Api/Client/OrganizationsClient.cs | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Mollie.Api/Client/Abstract/IOrganizationsClient.cs b/Mollie.Api/Client/Abstract/IOrganizationsClient.cs index 86b046ae..be428e7b 100644 --- a/Mollie.Api/Client/Abstract/IOrganizationsClient.cs +++ b/Mollie.Api/Client/Abstract/IOrganizationsClient.cs @@ -1,10 +1,14 @@ using System.Threading.Tasks; +using Mollie.Api.Models.List; using Mollie.Api.Models.Organization; using Mollie.Api.Models.Url; namespace Mollie.Api.Client.Abstract { - public interface IOrganizationsClient { + public interface IOrganizationsClient + { + Task GetCurrentOrganizationAsync(); Task GetOrganizationAsync(string organizationId); + Task> GetOrganizationsListAsync(string from = null, int? limit = null); Task GetOrganizationAsync(UrlObjectLink url); } } \ No newline at end of file diff --git a/Mollie.Api/Client/OrganizationsClient.cs b/Mollie.Api/Client/OrganizationsClient.cs index 2f533844..be4f710d 100644 --- a/Mollie.Api/Client/OrganizationsClient.cs +++ b/Mollie.Api/Client/OrganizationsClient.cs @@ -1,6 +1,7 @@ using System.Net.Http; using System.Threading.Tasks; using Mollie.Api.Client.Abstract; +using Mollie.Api.Models.List; using Mollie.Api.Models.Organization; using Mollie.Api.Models.Url; @@ -17,6 +18,11 @@ public async Task GetOrganizationAsync(string organization return await this.GetAsync($"organizations/{organizationId}").ConfigureAwait(false); } + public async Task> GetOrganizationsListAsync(string from = null, int? limit = null) + { + return await this.GetListAsync>("organizations", from, limit, null).ConfigureAwait(false); + } + public async Task GetOrganizationAsync(UrlObjectLink url) { return await this.GetAsync(url).ConfigureAwait(false); } From dc6d8caa3653224fe0862d97c409be907c3c029c Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 22 Feb 2019 13:45:14 +0100 Subject: [PATCH 5/7] Fixing code formatting inconsistencies --- Mollie.Api/Client/PaymentMethodClient.cs | 43 +++++++------------ .../Pricing/FixedPricingResponse.cs | 3 +- .../PaymentMethod/Pricing/PricingResponse.cs | 3 +- .../Api/PaymentMethodTests.cs | 18 +++----- 4 files changed, 24 insertions(+), 43 deletions(-) diff --git a/Mollie.Api/Client/PaymentMethodClient.cs b/Mollie.Api/Client/PaymentMethodClient.cs index a83523a6..14d0a0bb 100644 --- a/Mollie.Api/Client/PaymentMethodClient.cs +++ b/Mollie.Api/Client/PaymentMethodClient.cs @@ -13,33 +13,29 @@ namespace Mollie.Api.Client { public class PaymentMethodClient : BaseMollieClient, IPaymentMethodClient { - public PaymentMethodClient(string apiKey, HttpClient httpClient = null) : base(apiKey, httpClient) - { + public PaymentMethodClient(string apiKey, HttpClient httpClient = null) : base(apiKey, httpClient) { } - public async Task GetPaymentMethodAsync(PaymentMethod paymentMethod, bool? includeIssuers = null, string locale = null, bool? includePricing = null, string profileId = null, bool? testmode = null) - { + public async Task GetPaymentMethodAsync(PaymentMethod paymentMethod, bool? includeIssuers = null, string locale = null, bool? includePricing = null, string profileId = null, bool? testmode = null) { Dictionary parameters = new Dictionary(); parameters.AddValueIfNotNullOrEmpty("locale", locale); - AddOauthParameters(parameters, profileId, testmode); - AddIncludeParameters(parameters, includeIssuers, includePricing); + this.AddOauthParameters(parameters, profileId, testmode); + this.AddIncludeParameters(parameters, includeIssuers, includePricing); return await this.GetAsync($"methods/{paymentMethod.ToString().ToLower()}{parameters.ToQueryString()}").ConfigureAwait(false); } - public async Task> GetAllPaymentMethodListAsync(string locale = null, bool? includeIssuers = null, bool? includePricing = null) - { + public async Task> GetAllPaymentMethodListAsync(string locale = null, bool? includeIssuers = null, bool? includePricing = null) { Dictionary parameters = new Dictionary(); parameters.AddValueIfNotNullOrEmpty("locale", locale); - AddIncludeParameters(parameters, includeIssuers, includePricing); + this.AddIncludeParameters(parameters, includeIssuers, includePricing); return await this.GetListAsync>("methods/all", null, null, parameters).ConfigureAwait(false); } - public async Task> GetPaymentMethodListAsync(SequenceType? sequenceType = null, string locale = null, Amount amount = null, bool? includeIssuers = null, bool? includePricing = null, string profileId = null, bool? testmode = null) - { + public async Task> GetPaymentMethodListAsync(SequenceType? sequenceType = null, string locale = null, Amount amount = null, bool? includeIssuers = null, bool? includePricing = null, string profileId = null, bool? testmode = null) { Dictionary parameters = new Dictionary() { {"sequenceType", sequenceType.ToString().ToLower()}, {"locale", locale}, @@ -47,40 +43,33 @@ public async Task> GetPaymentMethodListAsync {"amount[currency]", amount?.Currency} }; - AddOauthParameters(parameters, profileId, testmode); - AddIncludeParameters(parameters, includeIssuers, includePricing); + this.AddOauthParameters(parameters, profileId, testmode); + this.AddIncludeParameters(parameters, includeIssuers, includePricing); return await this.GetListAsync>("methods", null, null, parameters).ConfigureAwait(false); } - public async Task GetPaymentMethodAsync(UrlObjectLink url) - { + public async Task GetPaymentMethodAsync(UrlObjectLink url) { return await this.GetAsync(url).ConfigureAwait(false); } - private void AddOauthParameters(Dictionary parameters, string profileId = null, bool? testmode = null) - { - if (!string.IsNullOrWhiteSpace(profileId) || testmode.HasValue) - { + private void AddOauthParameters(Dictionary parameters, string profileId = null, bool? testmode = null) { + if (!string.IsNullOrWhiteSpace(profileId) || testmode.HasValue) { this.ValidateApiKeyIsOauthAccesstoken(); parameters.AddValueIfNotNullOrEmpty("profileId", profileId); - if (testmode.HasValue) - { + if (testmode.HasValue) { parameters.AddValueIfNotNullOrEmpty("testmode", testmode.Value.ToString().ToLower()); } } } - private void AddIncludeParameters(Dictionary parameters, bool? includeIssuers = null, bool? includePricing = null) - { - if (includeIssuers == true) - { + private void AddIncludeParameters(Dictionary parameters, bool? includeIssuers = null, bool? includePricing = null) { + if (includeIssuers == true) { parameters.Add("include", "issuers"); } - if (includePricing == true) - { + if (includePricing == true) { parameters.Add("include", "pricing"); } } diff --git a/Mollie.Api/Models/PaymentMethod/Pricing/FixedPricingResponse.cs b/Mollie.Api/Models/PaymentMethod/Pricing/FixedPricingResponse.cs index 2006fcf1..ea466f04 100644 --- a/Mollie.Api/Models/PaymentMethod/Pricing/FixedPricingResponse.cs +++ b/Mollie.Api/Models/PaymentMethod/Pricing/FixedPricingResponse.cs @@ -1,7 +1,6 @@ namespace Mollie.Api.Models.PaymentMethod.Pricing { - public class FixedPricingResponse : IResponseObject - { + public class FixedPricingResponse : IResponseObject { /// /// The ISO 4217 currency code. /// diff --git a/Mollie.Api/Models/PaymentMethod/Pricing/PricingResponse.cs b/Mollie.Api/Models/PaymentMethod/Pricing/PricingResponse.cs index d2022c76..c7958d99 100644 --- a/Mollie.Api/Models/PaymentMethod/Pricing/PricingResponse.cs +++ b/Mollie.Api/Models/PaymentMethod/Pricing/PricingResponse.cs @@ -1,7 +1,6 @@ namespace Mollie.Api.Models.PaymentMethod.Pricing { - public class PricingResponse : IResponseObject - { + public class PricingResponse : IResponseObject { /// /// The area or product-type where the pricing is applied for, translated in the optional locale passed. /// diff --git a/Mollie.Tests.Integration/Api/PaymentMethodTests.cs b/Mollie.Tests.Integration/Api/PaymentMethodTests.cs index 06c2a193..957bdd01 100644 --- a/Mollie.Tests.Integration/Api/PaymentMethodTests.cs +++ b/Mollie.Tests.Integration/Api/PaymentMethodTests.cs @@ -68,8 +68,7 @@ public async Task DoNotRetrieveIssuersWhenIncludeIsNull() { } [Test] - public async Task CanRetrievePricing() - { + public async Task CanRetrievePricing() { // When: retrieving the ideal method we can include the issuers PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, includePricing: true); @@ -79,8 +78,7 @@ public async Task CanRetrievePricing() } [Test] - public async Task DoNotRetrievePricingWhenIncludeIsFalse() - { + public async Task DoNotRetrievePricingWhenIncludeIsFalse() { // When: retrieving the ideal method with the include parameter set to false PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, includePricing: false); @@ -89,8 +87,7 @@ public async Task DoNotRetrievePricingWhenIncludeIsFalse() } [Test] - public async Task DoNotRetrievePricingWhenIncludeIsNull() - { + public async Task DoNotRetrievePricingWhenIncludeIsNull() { // When: retrieving the ideal method with the include parameter set to null PaymentMethodResponse paymentMethod = await this._paymentMethodClient.GetPaymentMethodAsync(PaymentMethod.Ideal, includePricing: null); @@ -99,8 +96,7 @@ public async Task DoNotRetrievePricingWhenIncludeIsNull() } [Test] - public async Task CanRetrieveAllMethods() - { + public async Task CanRetrieveAllMethods() { // When: retrieving the all mollie payment methods ListResponse paymentMethods = await this._paymentMethodClient.GetAllPaymentMethodListAsync(); @@ -110,8 +106,7 @@ public async Task CanRetrieveAllMethods() } [Test] - public async Task CanRetrievePricingForAllMethods() - { + public async Task CanRetrievePricingForAllMethods() { // When: retrieving the ideal method we can include the issuers ListResponse paymentMethods = await this._paymentMethodClient.GetAllPaymentMethodListAsync(includePricing: true); @@ -120,8 +115,7 @@ public async Task CanRetrievePricingForAllMethods() } [Test] - public async Task CanRetrieveIssuersForAllMethods() - { + public async Task CanRetrieveIssuersForAllMethods() { // When: retrieving the all mollie payment methods we can include the issuers ListResponse paymentMethods = await this._paymentMethodClient.GetAllPaymentMethodListAsync(includeIssuers: true); From 42dae02cb649581a8de1ca12c0b5bfb86e1f9778 Mon Sep 17 00:00:00 2001 From: Lex Goudriaan Date: Thu, 28 Feb 2019 11:05:21 +0100 Subject: [PATCH 6/7] Added UnknownReason to CreditCardFailureReason Fixed CreditCardLabels JCB and laser --- .../Payment/Response/Specific/CreditCardPaymentResponse.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Mollie.Api/Models/Payment/Response/Specific/CreditCardPaymentResponse.cs b/Mollie.Api/Models/Payment/Response/Specific/CreditCardPaymentResponse.cs index 7c25e26c..ca2ddbab 100644 --- a/Mollie.Api/Models/Payment/Response/Specific/CreditCardPaymentResponse.cs +++ b/Mollie.Api/Models/Payment/Response/Specific/CreditCardPaymentResponse.cs @@ -101,7 +101,8 @@ public enum CreditCardFailureReason { [EnumMember(Value = "invalid_card_type")] InvalidCardType, [EnumMember(Value = "refused_by_issuer")] RefusedByIssuer, [EnumMember(Value = "insufficient_funds")] InsufficientFunds, - [EnumMember(Value = "inactive_card")] InactiveCard + [EnumMember(Value = "inactive_card")] InactiveCard, + [EnumMember(Value = "unknown_reason")] UnknownReason } /// @@ -114,7 +115,8 @@ public enum CreditCardLabel { Dankort, [EnumMember(Value = "Diners Club")] DinersClub, Discover, - [EnumMember(Value = "JCB Laser")] JcbLaser, + [EnumMember(Value = "JCB")] Jcb, + [EnumMember(Value = "Laser")] Laser, Maestro, Mastercard, Unionpay, From cc0d679eb5488213896be77c64715fad0d9f8d37 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 5 Mar 2019 19:25:08 +0100 Subject: [PATCH 7/7] Increased version number to 2.0.4.0 --- Mollie.Api/Mollie.Api.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Mollie.Api/Mollie.Api.csproj b/Mollie.Api/Mollie.Api.csproj index aa2ca407..5145369a 100644 --- a/Mollie.Api/Mollie.Api.csproj +++ b/Mollie.Api/Mollie.Api.csproj @@ -2,7 +2,7 @@ netstandard1.2;net45 - 2.0.3.0 + 2.0.4.0 True Vincent Kok This is a wrapper for the Mollie REST webservice. All payment methods and webservice calls are supported. @@ -10,8 +10,8 @@ Mollie Payment API https://github.com/Viincenttt/MollieApi Mollie - 2.0.3.0 - 2.0.3.0 + 2.0.4.0 + 2.0.4.0