Skip to content

Commit

Permalink
Merge branch '4.0.0.0' of https://github.com/Viincenttt/MollieApi int…
Browse files Browse the repository at this point in the history
…o 4.0.0.0
  • Loading branch information
Viincenttt committed Jun 7, 2024
2 parents c3f9227 + 0be6959 commit ac82f98
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 142 deletions.
11 changes: 9 additions & 2 deletions src/Mollie.Api/Client/Abstract/IBalanceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public interface IBalanceClient : IBaseMollieClient {
/// with this ID is included in the result set as well.</param>
/// <param name="limit">The number of balance transactions to return (with a maximum of 250).</param>
/// <returns></returns>
Task<BalanceTransactionResponse> GetBalanceTransactionListAsync(string balanceId, string? from = null, int? limit = null);
Task<ListResponse<BalanceTransactionResponse>> GetBalanceTransactionListAsync(string balanceId, string? from = null, int? limit = null);

/// <summary>
/// With the List primary balance transactions endpoint you can retrieve a list of all the movements on your
Expand All @@ -97,6 +97,13 @@ public interface IBalanceClient : IBaseMollieClient {
/// with this ID is included in the result set as well.</param>
/// <param name="limit">The number of balance transactions to return (with a maximum of 250).</param>
/// <returns></returns>
Task<BalanceTransactionResponse> GetPrimaryBalanceTransactionListAsync(string? from = null, int? limit = null);
Task<ListResponse<BalanceTransactionResponse>> GetPrimaryBalanceTransactionListAsync(string? from = null, int? limit = null);

/// <summary>
/// Retrieve a list of balance transactions by URL
/// </summary>
/// <param name="url">The URL from which to retrieve the balance transactions</param>
/// <returns></returns>
Task<ListResponse<BalanceTransactionResponse>> GetBalanceTransactionListAsync(UrlObjectLink<ListResponse<BalanceTransactionResponse>> url);
}
}
16 changes: 10 additions & 6 deletions src/Mollie.Api/Client/BalanceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ public async Task<BalanceReportResponse> GetPrimaryBalanceReportAsync(DateTime f
return await GetAsync<BalanceReportResponse>($"balances/primary/report{queryParameters.ToQueryString()}").ConfigureAwait(false);
}

public async Task<BalanceTransactionResponse> GetBalanceTransactionListAsync(string balanceId, string? from = null, int? limit = null) {
public async Task<ListResponse<BalanceTransactionResponse>> GetBalanceTransactionListAsync(string balanceId, string? from = null, int? limit = null) {
ValidateRequiredUrlParameter(nameof(balanceId), balanceId);
var queryParameters = BuildListBalanceTransactionsQueryParameters(from, limit);
return await GetAsync<BalanceTransactionResponse>($"balances/{balanceId}/transactions{queryParameters.ToQueryString()}").ConfigureAwait(false);
return await GetListAsync<ListResponse<BalanceTransactionResponse>>($"balances/{balanceId}/transactions", from, limit)
.ConfigureAwait(false);
}

public async Task<BalanceTransactionResponse> GetPrimaryBalanceTransactionListAsync(string? from = null, int? limit = null) {
var queryParameters = BuildListBalanceTransactionsQueryParameters(from, limit);
return await GetAsync<BalanceTransactionResponse>($"balances/primary/transactions{queryParameters.ToQueryString()}").ConfigureAwait(false);
public async Task<ListResponse<BalanceTransactionResponse>> GetPrimaryBalanceTransactionListAsync(string? from = null, int? limit = null) {
return await GetListAsync<ListResponse<BalanceTransactionResponse>>($"balances/primary/transactions", from, limit)
.ConfigureAwait(false);
}

public async Task<ListResponse<BalanceTransactionResponse>> GetBalanceTransactionListAsync(UrlObjectLink<ListResponse<BalanceTransactionResponse>> url) {
return await GetAsync(url).ConfigureAwait(false);
}

private Dictionary<string, string> BuildListBalanceTransactionsQueryParameters(string? from, int? limit) {
Expand Down
18 changes: 9 additions & 9 deletions src/Mollie.Api/Framework/Factories/BalanceTransactionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Mollie.Api.Framework.Factories {
internal class BalanceTransactionFactory {
public BalanceTransaction Create(string? type) {
public BalanceTransactionResponse Create(string? type) {
if (string.IsNullOrEmpty(type)) {
return Activator.CreateInstance<BalanceTransaction>();
return Activator.CreateInstance<BalanceTransactionResponse>();
}

switch (type) {
Expand All @@ -16,24 +16,24 @@ public BalanceTransaction Create(string? type) {
case BalanceTransactionContextType.ChargebackReversal:
case BalanceTransactionContextType.ApplicationFee:
case BalanceTransactionContextType.SplitPayment:
return Activator.CreateInstance<PaymentBalanceTransaction>();
return Activator.CreateInstance<PaymentBalanceTransactionResponse>();
case BalanceTransactionContextType.Capture:
return Activator.CreateInstance<CaptureBalanceTransaction>();
return Activator.CreateInstance<CaptureBalanceTransactionResponse>();
case BalanceTransactionContextType.Refund:
case BalanceTransactionContextType.ReturnedRefund:
case BalanceTransactionContextType.PlatformPaymentRefund:
return Activator.CreateInstance<RefundBalanceTransaction>();
return Activator.CreateInstance<RefundBalanceTransactionResponse>();
case BalanceTransactionContextType.Chargeback:
case BalanceTransactionContextType.PlatformPaymentChargeback:
return Activator.CreateInstance<ChargebackBalanceTransaction>();
return Activator.CreateInstance<ChargebackBalanceTransactionResponse>();
case BalanceTransactionContextType.OutgoingTransfer:
case BalanceTransactionContextType.CanceledOutgoingTransfer:
case BalanceTransactionContextType.ReturnedTransfer:
return Activator.CreateInstance<SettlementBalanceTransaction>();
return Activator.CreateInstance<SettlementBalanceTransactionResponse>();
case BalanceTransactionContextType.InvoiceCompensation:
return Activator.CreateInstance<InvoiceBalanceTransaction>();
return Activator.CreateInstance<InvoiceBalanceTransactionResponse>();
default:
return Activator.CreateInstance<BalanceTransaction>();
return Activator.CreateInstance<BalanceTransactionResponse>();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
using Newtonsoft.Json.Linq;

namespace Mollie.Api.JsonConverters {
internal class BalanceTransactionJsonConverter : JsonCreationConverter<BalanceTransaction> {
internal class BalanceTransactionJsonConverter : JsonCreationConverter<BalanceTransactionResponse> {
private readonly BalanceTransactionFactory _balanceTransactionFactory;

public BalanceTransactionJsonConverter(BalanceTransactionFactory balanceTransactionFactory) {
_balanceTransactionFactory = balanceTransactionFactory;
}

protected override BalanceTransaction Create(Type objectType, JObject jObject) {
protected override BalanceTransactionResponse Create(Type objectType, JObject jObject) {
string? transactionType = GetTransactionType(jObject);

return _balanceTransactionFactory.Create(transactionType);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System;

namespace Mollie.Api.Models.Balance.Response.BalanceTransaction {
public class BalanceTransactionResponse {
/// <summary>
/// The number of transactions found in _embedded, which is either the requested number
/// (with a maximum of 250) or the default number.
/// Indicates the response contains a balance transaction object. Will always contain balance_transaction
/// for this endpoint.
/// </summary>
public required int Count { get; set; }
public required string Resource { get; set; }

/// <summary>
/// The object containing the queried data.
/// The identifier uniquely referring to this balance transaction. Mollie assigns this identifier at
/// transaction creation time. For example baltr_QM24QwzUWR4ev4Xfgyt29d.
/// </summary>
[JsonProperty("_embedded")]
public required BalanceTransactionEmbeddedResponse Embedded { get; set; }
public required string Id { get; set; }

/// <summary>
/// Links to help navigate through the lists of balance transactions. Every URL object will contain an href and a type field.
/// The type of movement, for example payment or refund. See Mollie docs for a full list of values
/// </summary>
[JsonProperty("_links")]
public required BalanceTransactionResponseLinks Links { get; set; }
}
public required string Type { get; set; }

/// <summary>
/// The final amount that was moved to or from the balance, e.g. {"currency":"EUR", "value":"100.00"}.
/// If the transaction moves funds away from the balance, for example when it concerns a refund, the
/// amount will be negative.
/// </summary>
public required Amount ResultAmount { get; set; }

/// <summary>
/// The amount that was to be moved to or from the balance, excluding deductions. If the transaction
/// moves funds away from the balance, for example when it concerns a refund, the amount will be negative.
/// </summary>
public required Amount InitialAmount { get; set; }

/// <summary>
/// The total amount of deductions withheld from the movement. For example, if a €10,00 payment comes in
/// with a €0,29 fee, the deductions amount will be {"currency":"EUR", "value":"-0.29"}. When moving funds
/// to a balance, we always round the deduction to a ‘real’ amount. Any differences between these realtime
/// rounded amounts and the final invoice will be compensated when the invoice is generated.
/// </summary>
public required Amount Deductions { get; set; }

public class BalanceTransactionEmbeddedResponse {
[JsonProperty("balance_transactions")]
public required IEnumerable<BalanceTransaction> BalanceTransactions { get; set; }
/// <summary>
/// The date and time of the movement, in ISO 8601 format.
/// </summary>
public required DateTime CreatedAt { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Mollie.Api.Models.Balance.Response.BalanceTransaction.Specific {
public class CaptureBalanceTransaction : BalanceTransaction {
public class CaptureBalanceTransactionResponse : BalanceTransactionResponse {
public required CaptureTransactionContext Context { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Mollie.Api.Models.Balance.Response.BalanceTransaction.Specific {
public class ChargebackBalanceTransaction : BalanceTransaction {
public class ChargebackBalanceTransactionResponse : BalanceTransactionResponse {
public required ChargebackTransactionContext Context { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Mollie.Api.Models.Balance.Response.BalanceTransaction.Specific {
public class InvoiceBalanceTransaction : BalanceTransaction {
public class InvoiceBalanceTransactionResponse : BalanceTransactionResponse {
public required InvoiceTransactionContext Context { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Mollie.Api.Models.Balance.Response.BalanceTransaction.Specific {
public class PaymentBalanceTransaction : BalanceTransaction {
public class PaymentBalanceTransactionResponse : BalanceTransactionResponse {
public required PaymentTransactionContext Context { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Mollie.Api.Models.Balance.Response.BalanceTransaction.Specific {
public class RefundBalanceTransaction : BalanceTransaction {
public class RefundBalanceTransactionResponse : BalanceTransactionResponse {
public required RefundTransactionContext Context { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Mollie.Api.Models.Balance.Response.BalanceTransaction.Specific {
public class SettlementBalanceTransaction : BalanceTransaction {
public class SettlementBalanceTransactionResponse : BalanceTransactionResponse {
public required SettlementTransactionContext Context { get; set; }
}

Expand Down
6 changes: 2 additions & 4 deletions tests/Mollie.Tests.Integration/Api/BalanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ public async Task ListBalanceTransactionsAsync_IsParsedCorrectly() {

// Then: Make sure we can parse the result
result.Should().NotBeNull();
result.Embedded.Should().NotBeNull();
result.Embedded.BalanceTransactions.Should().NotBeNull();
result.Items.Should().NotBeNull();
result.Links.Should().NotBeNull();
result.Links.Self.Href.Should().Be($"https://api.mollie.com/v2/balances/{balanceId}/transactions?from={from}&limit={limit}");
}
Expand All @@ -129,8 +128,7 @@ public async Task ListPrimaryBalanceTransactionsAsync_IsParsedCorrectly() {

// Then: Make sure we can parse the result
result.Should().NotBeNull();
result.Embedded.Should().NotBeNull();
result.Embedded.BalanceTransactions.Should().NotBeNull();
result.Items.Should().NotBeNull();
}

public void Dispose()
Expand Down
14 changes: 7 additions & 7 deletions tests/Mollie.Tests.Unit/Client/BalanceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,18 @@ public async Task ListBalanceTransactionsAsync_StatusBalances_ResponseIsParsed()

// Then: Response should be parsed
mockHttp.VerifyNoOutstandingExpectation();
balanceTransactions?.Embedded?.BalanceTransactions.Should().NotBeNull();
balanceTransactions.Count.Should().Be(balanceTransactions.Embedded.BalanceTransactions.Count());
var transaction = balanceTransactions.Embedded.BalanceTransactions.First();
balanceTransactions?.Items?.Should().NotBeNull();
balanceTransactions.Count.Should().Be(balanceTransactions.Items.Count());
var transaction = balanceTransactions.Items.First();
transaction.Resource.Should().Be("balance_transactions");
transaction.Id.Should().Be("baltr_9S8yk4FFqqi2Qm6K3rqRH");
transaction.Type.Should().Be("outgoing-transfer");
transaction.ResultAmount.Value.Should().Be("-7.76");
transaction.ResultAmount.Currency.Should().Be(Currency.EUR);
transaction.InitialAmount.Value.Should().Be("-7.76");
transaction.InitialAmount.Currency.Should().Be(Currency.EUR);
transaction.Should().BeOfType<SettlementBalanceTransaction>();
var transactionContext = (SettlementBalanceTransaction)transaction;
transaction.Should().BeOfType<SettlementBalanceTransactionResponse>();
var transactionContext = (SettlementBalanceTransactionResponse)transaction;
transactionContext.Context.SettlementId.Should().Be("stl_ma2vu8");
transactionContext.Context.TransferId.Should().Be("trf_ma2vu8");
}
Expand Down Expand Up @@ -280,8 +280,8 @@ public async Task ListPrimaryBalanceTransactionsAsync_StatusBalances_ResponseIsP

// Then: Response should be parsed
mockHttp.VerifyNoOutstandingExpectation();
balanceTransactions?.Embedded?.BalanceTransactions.Should().NotBeNull();
balanceTransactions.Count.Should().Be(balanceTransactions.Embedded.BalanceTransactions.Count());
balanceTransactions?.Items?.Should().NotBeNull();
balanceTransactions.Count.Should().Be(balanceTransactions.Items.Count());
}

private readonly string DefaultListBalanceTransactionsResponse = @"
Expand Down
Loading

0 comments on commit ac82f98

Please sign in to comment.