diff --git a/README.md b/README.md index c2fe13bb..8dec75c8 100644 --- a/README.md +++ b/README.md @@ -49,21 +49,21 @@ Source: https://docs.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-s ## Supported API's This library currently supports the following API's: -- Payments API +- Payment API - PaymentMethod API - PaymentLink API -- Customers API -- Mandates API -- Subscriptions API +- Customer API +- Mandate API +- Subscription API - Refund API - Connect API -- Chargebacks API -- Invoices API +- Chargeback API +- Invoice API - Permissions API -- Profiles API +- Profile API - Organizations API - Order API -- Captures API +- Capture API - Onboarding API - Balances API - Terminal API diff --git a/src/Mollie.Api/Client/Abstract/IBalanceClient.cs b/src/Mollie.Api/Client/Abstract/IBalanceClient.cs index 2b5d7539..6df4ec69 100644 --- a/src/Mollie.Api/Client/Abstract/IBalanceClient.cs +++ b/src/Mollie.Api/Client/Abstract/IBalanceClient.cs @@ -38,14 +38,14 @@ public interface IBalanceClient : IBaseMollieClient { /// Currency filter that will make it so only balances in given currency are returned. /// For example EUR. /// - Task> ListBalancesAsync(string? from = null, int? limit = null, string? currency = null); + Task> GetBalanceListAsync(string? from = null, int? limit = null, string? currency = null); /// /// Retrieve all the organization’s balances by URL /// /// The URL of the balance objects /// - Task> ListBalancesAsync(UrlObjectLink> url); + Task> GetBalanceListAsync(UrlObjectLink> url); /// /// With the Get balance report endpoint you can retrieve a summarized report for all movements on a given @@ -87,7 +87,7 @@ public interface IBalanceClient : IBaseMollieClient { /// with this ID is included in the result set as well. /// The number of balance transactions to return (with a maximum of 250). /// - Task ListBalanceTransactionsAsync(string balanceId, string? from = null, int? limit = null); + Task GetBalanceTransactionListAsync(string balanceId, string? from = null, int? limit = null); /// /// With the List primary balance transactions endpoint you can retrieve a list of all the movements on your @@ -97,6 +97,6 @@ public interface IBalanceClient : IBaseMollieClient { /// with this ID is included in the result set as well. /// The number of balance transactions to return (with a maximum of 250). /// - Task ListPrimaryBalanceTransactionsAsync(string? from = null, int? limit = null); + Task GetPrimaryBalanceTransactionListAsync(string? from = null, int? limit = null); } } diff --git a/src/Mollie.Api/Client/Abstract/ICaptureClient.cs b/src/Mollie.Api/Client/Abstract/ICaptureClient.cs index d62a4e63..da0623a0 100644 --- a/src/Mollie.Api/Client/Abstract/ICaptureClient.cs +++ b/src/Mollie.Api/Client/Abstract/ICaptureClient.cs @@ -8,8 +8,8 @@ namespace Mollie.Api.Client.Abstract { public interface ICaptureClient : IBaseMollieClient { Task GetCaptureAsync(string paymentId, string captureId, bool testmode = false); Task GetCaptureAsync(UrlObjectLink url); - Task> GetCapturesListAsync(string paymentId, bool testmode = false); - Task> GetCapturesListAsync(UrlObjectLink> url); + Task> GetCaptureListAsync(string paymentId, bool testmode = false); + Task> GetCaptureListAsync(UrlObjectLink> url); Task CreateCapture(string paymentId, CaptureRequest captureRequest, bool testmode = false); } } diff --git a/src/Mollie.Api/Client/Abstract/IChargebackClient.cs b/src/Mollie.Api/Client/Abstract/IChargebackClient.cs new file mode 100644 index 00000000..12111f09 --- /dev/null +++ b/src/Mollie.Api/Client/Abstract/IChargebackClient.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using Mollie.Api.Models.Chargeback.Response; +using Mollie.Api.Models.List.Response; +using Mollie.Api.Models.Url; + +namespace Mollie.Api.Client.Abstract { + public interface IChargebackClient : IBaseMollieClient { + Task GetChargebackAsync(string paymentId, string chargebackId, bool testmode = false); + Task> GetChargebackListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false); + Task> GetChargebackListAsync(string? profileId = null, bool testmode = false); + Task> GetChargebackListAsync(UrlObjectLink> url); + } +} diff --git a/src/Mollie.Api/Client/Abstract/IChargebacksClient.cs b/src/Mollie.Api/Client/Abstract/IChargebacksClient.cs deleted file mode 100644 index 7f14b1f1..00000000 --- a/src/Mollie.Api/Client/Abstract/IChargebacksClient.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Threading.Tasks; -using Mollie.Api.Models.Chargeback.Response; -using Mollie.Api.Models.List.Response; -using Mollie.Api.Models.Url; - -namespace Mollie.Api.Client.Abstract { - public interface IChargebacksClient : IBaseMollieClient { - Task GetChargebackAsync(string paymentId, string chargebackId, bool testmode = false); - Task> GetChargebacksListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false); - Task> GetChargebacksListAsync(string? profileId = null, bool testmode = false); - Task> GetChargebacksListAsync(UrlObjectLink> url); - } -} diff --git a/src/Mollie.Api/Client/Abstract/IInvoicesClient.cs b/src/Mollie.Api/Client/Abstract/IInvoiceClient.cs similarity index 91% rename from src/Mollie.Api/Client/Abstract/IInvoicesClient.cs rename to src/Mollie.Api/Client/Abstract/IInvoiceClient.cs index 3d6d487d..72d9ab80 100644 --- a/src/Mollie.Api/Client/Abstract/IInvoicesClient.cs +++ b/src/Mollie.Api/Client/Abstract/IInvoiceClient.cs @@ -4,7 +4,7 @@ using Mollie.Api.Models.Url; namespace Mollie.Api.Client.Abstract { - public interface IInvoicesClient : IBaseMollieClient { + public interface IInvoiceClient : IBaseMollieClient { Task GetInvoiceAsync(string invoiceId); Task GetInvoiceAsync(UrlObjectLink url); Task> GetInvoiceListAsync( diff --git a/src/Mollie.Api/Client/Abstract/IOrderClient.cs b/src/Mollie.Api/Client/Abstract/IOrderClient.cs index c5c3f9a6..c2f730c0 100644 --- a/src/Mollie.Api/Client/Abstract/IOrderClient.cs +++ b/src/Mollie.Api/Client/Abstract/IOrderClient.cs @@ -5,7 +5,6 @@ using Mollie.Api.Models.Order.Request.ManageOrderLines; using Mollie.Api.Models.Order.Response; using Mollie.Api.Models.Payment.Response; -using Mollie.Api.Models.Refund.Response; using Mollie.Api.Models.Url; namespace Mollie.Api.Client.Abstract { @@ -22,8 +21,5 @@ Task> GetOrderListAsync( Task> GetOrderListAsync(UrlObjectLink> url); Task CancelOrderLinesAsync(string orderId, OrderLineCancellationRequest cancelationRequest); Task CreateOrderPaymentAsync(string orderId, OrderPaymentRequest createOrderPaymentRequest); - Task CreateOrderRefundAsync(string orderId, OrderRefundRequest createOrderRefundRequest); - Task> GetOrderRefundListAsync( - string orderId, string? from = null, int? limit = null, bool testmode = false); } } diff --git a/src/Mollie.Api/Client/Abstract/IOrganizationsClient.cs b/src/Mollie.Api/Client/Abstract/IOrganizationClient.cs similarity index 75% rename from src/Mollie.Api/Client/Abstract/IOrganizationsClient.cs rename to src/Mollie.Api/Client/Abstract/IOrganizationClient.cs index 7d23efd4..07c8baaf 100644 --- a/src/Mollie.Api/Client/Abstract/IOrganizationsClient.cs +++ b/src/Mollie.Api/Client/Abstract/IOrganizationClient.cs @@ -4,11 +4,11 @@ using Mollie.Api.Models.Url; namespace Mollie.Api.Client.Abstract { - public interface IOrganizationsClient : IBaseMollieClient { + public interface IOrganizationClient : IBaseMollieClient { Task GetCurrentOrganizationAsync(); Task GetOrganizationAsync(string organizationId); - Task> GetOrganizationsListAsync(string? from = null, int? limit = null); - Task> GetOrganizationsListAsync(UrlObjectLink> url); + Task> GetOrganizationListAsync(string? from = null, int? limit = null); + Task> GetOrganizationListAsync(UrlObjectLink> url); Task GetOrganizationAsync(UrlObjectLink url); } } diff --git a/src/Mollie.Api/Client/Abstract/IPaymentClient.cs b/src/Mollie.Api/Client/Abstract/IPaymentClient.cs index 07fea5d7..484cc7be 100644 --- a/src/Mollie.Api/Client/Abstract/IPaymentClient.cs +++ b/src/Mollie.Api/Client/Abstract/IPaymentClient.cs @@ -38,7 +38,7 @@ Task GetPaymentAsync( /// /// Oauth - Optional – Set this to true to cancel a test mode payment. /// - Task DeletePaymentAsync(string paymentId, bool testmode = false); + Task CancelPaymentAsync(string paymentId, bool testmode = false); /// /// Retrieve all payments created with the current payment profile, ordered from newest to oldest. diff --git a/src/Mollie.Api/Client/Abstract/IPermissionsClient.cs b/src/Mollie.Api/Client/Abstract/IPermissionClient.cs similarity index 87% rename from src/Mollie.Api/Client/Abstract/IPermissionsClient.cs rename to src/Mollie.Api/Client/Abstract/IPermissionClient.cs index 10129161..3869a16b 100644 --- a/src/Mollie.Api/Client/Abstract/IPermissionsClient.cs +++ b/src/Mollie.Api/Client/Abstract/IPermissionClient.cs @@ -4,7 +4,7 @@ using Mollie.Api.Models.Url; namespace Mollie.Api.Client.Abstract { - public interface IPermissionsClient : IBaseMollieClient { + public interface IPermissionClient : IBaseMollieClient { Task GetPermissionAsync(string permissionId); Task GetPermissionAsync(UrlObjectLink url); Task> GetPermissionListAsync(); diff --git a/src/Mollie.Api/Client/Abstract/IRefundClient.cs b/src/Mollie.Api/Client/Abstract/IRefundClient.cs index 0e629262..56ca98ec 100644 --- a/src/Mollie.Api/Client/Abstract/IRefundClient.cs +++ b/src/Mollie.Api/Client/Abstract/IRefundClient.cs @@ -1,15 +1,19 @@ using System.Threading.Tasks; using Mollie.Api.Models.List.Response; +using Mollie.Api.Models.Order.Request; +using Mollie.Api.Models.Order.Response; using Mollie.Api.Models.Refund.Request; using Mollie.Api.Models.Refund.Response; using Mollie.Api.Models.Url; namespace Mollie.Api.Client.Abstract { public interface IRefundClient : IBaseMollieClient { - Task CancelRefundAsync(string paymentId, string refundId, bool testmode = false); - Task CreateRefundAsync(string paymentId, RefundRequest refundRequest); - Task GetRefundAsync(string paymentId, string refundId, bool testmode = false); - Task> GetRefundListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false); + Task CreatePaymentRefundAsync(string paymentId, RefundRequest refundRequest); + Task GetPaymentRefundAsync(string paymentId, string refundId, bool testmode = false); + Task CancelPaymentRefundAsync(string paymentId, string refundId, bool testmode = false); + Task> GetPaymentRefundListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false); + Task CreateOrderRefundAsync(string orderId, OrderRefundRequest createOrderRefundRequest); + Task> GetOrderRefundListAsync(string orderId, string? from = null, int? limit = null, bool testmode = false); Task> GetRefundListAsync(UrlObjectLink> url); Task GetRefundAsync(UrlObjectLink url); } diff --git a/src/Mollie.Api/Client/Abstract/ISettlementClient.cs b/src/Mollie.Api/Client/Abstract/ISettlementClient.cs new file mode 100644 index 00000000..80f6d48a --- /dev/null +++ b/src/Mollie.Api/Client/Abstract/ISettlementClient.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; +using Mollie.Api.Models.Capture.Response; +using Mollie.Api.Models.Chargeback.Response; +using Mollie.Api.Models.List.Response; +using Mollie.Api.Models.Payment.Response; +using Mollie.Api.Models.Refund.Response; +using Mollie.Api.Models.Settlement.Response; +using Mollie.Api.Models.Url; + +namespace Mollie.Api.Client.Abstract { + public interface ISettlementClient : IBaseMollieClient { + Task GetSettlementAsync(string settlementId); + Task GetNextSettlement(); + Task GetOpenSettlement(); + Task> GetSettlementListAsync(string? reference = null, string? from = null, int? limit = null); + Task> GetSettlementListAsync(UrlObjectLink> url); + Task> GetSettlementPaymentListAsync(string settlementId, string? from = null, int? limit = null); + Task> GetSettlementPaymentListAsync(UrlObjectLink> url); + Task> GetSettlementRefundListAsync(string settlementId, string? from = null, int? limit = null); + Task> GetSettlementRefundListAsync(UrlObjectLink> url); + Task> GetSettlementChargebackListAsync(string settlementId, string? from = null, int? limit = null); + Task> GetSettlementChargebackListAsync(UrlObjectLink> url); + Task> GetSettlementCaptureListAsync(string settlementId, string? offset = null, int? count = null); + Task> GetSettlementCaptureListAsync(UrlObjectLink> url); + Task GetSettlementAsync(UrlObjectLink url); + } +} diff --git a/src/Mollie.Api/Client/Abstract/ISettlementsClient.cs b/src/Mollie.Api/Client/Abstract/ISettlementsClient.cs deleted file mode 100644 index cb44bffa..00000000 --- a/src/Mollie.Api/Client/Abstract/ISettlementsClient.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Threading.Tasks; -using Mollie.Api.Models.Capture.Response; -using Mollie.Api.Models.Chargeback.Response; -using Mollie.Api.Models.List.Response; -using Mollie.Api.Models.Payment.Response; -using Mollie.Api.Models.Refund.Response; -using Mollie.Api.Models.Settlement.Response; -using Mollie.Api.Models.Url; - -namespace Mollie.Api.Client.Abstract { - public interface ISettlementsClient : IBaseMollieClient { - Task GetSettlementAsync(string settlementId); - Task GetNextSettlement(); - Task GetOpenSettlement(); - Task> GetSettlementsListAsync(string? reference = null, string? from = null, int? limit = null); - Task> GetSettlementsListAsync(UrlObjectLink> url); - Task> GetSettlementPaymentsListAsync(string settlementId, string? from = null, int? limit = null); - Task> GetSettlementPaymentsListAsync(UrlObjectLink> url); - Task> GetSettlementRefundsListAsync(string settlementId, string? from = null, int? limit = null); - Task> GetSettlementRefundsListAsync(UrlObjectLink> url); - Task> GetSettlementChargebacksListAsync(string settlementId, string? from = null, int? limit = null); - Task> GetSettlementChargebacksListAsync(UrlObjectLink> url); - Task> GetSettlementCapturesListAsync(string settlementId, string? offset = null, int? count = null); - Task> GetSettlementCapturesListAsync(UrlObjectLink> url); - Task GetSettlementAsync(UrlObjectLink url); - - [Obsolete("Use GetSettlementCapturesListAsync instead")] - Task> ListSettlementCapturesAsync(string settlementId); - } -} diff --git a/src/Mollie.Api/Client/Abstract/IShipmentClient.cs b/src/Mollie.Api/Client/Abstract/IShipmentClient.cs index 9df71ab5..1af15f99 100644 --- a/src/Mollie.Api/Client/Abstract/IShipmentClient.cs +++ b/src/Mollie.Api/Client/Abstract/IShipmentClient.cs @@ -9,8 +9,8 @@ public interface IShipmentClient : IBaseMollieClient { Task CreateShipmentAsync(string orderId, ShipmentRequest shipmentRequest); Task GetShipmentAsync(string orderId, string shipmentId, bool testmode = false); Task GetShipmentAsync(UrlObjectLink url); - Task> GetShipmentsListAsync(string orderId, bool testmode = false); - Task> GetShipmentsListAsync(UrlObjectLink> url); + Task> GetShipmentListAsync(string orderId, bool testmode = false); + Task> GetShipmentListAsync(UrlObjectLink> url); Task UpdateShipmentAsync(string orderId, string shipmentId, ShipmentUpdateRequest shipmentUpdateRequest); } } diff --git a/src/Mollie.Api/Client/BalanceClient.cs b/src/Mollie.Api/Client/BalanceClient.cs index f9a98406..791b42d3 100644 --- a/src/Mollie.Api/Client/BalanceClient.cs +++ b/src/Mollie.Api/Client/BalanceClient.cs @@ -29,12 +29,12 @@ public async Task GetPrimaryBalanceAsync() { return await GetAsync("balances/primary").ConfigureAwait(false); } - public async Task> ListBalancesAsync(string? from = null, int? limit = null, string? currency = null) { + public async Task> GetBalanceListAsync(string? from = null, int? limit = null, string? currency = null) { var queryParameters = BuildListBalanceQueryParameters(currency); return await GetListAsync>($"balances", from, limit, queryParameters).ConfigureAwait(false); } - public async Task> ListBalancesAsync(UrlObjectLink> url) { + public async Task> GetBalanceListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } @@ -49,13 +49,13 @@ public async Task GetPrimaryBalanceReportAsync(DateTime f return await GetAsync($"balances/primary/report{queryParameters.ToQueryString()}").ConfigureAwait(false); } - public async Task ListBalanceTransactionsAsync(string balanceId, string? from = null, int? limit = null) { + public async Task GetBalanceTransactionListAsync(string balanceId, string? from = null, int? limit = null) { ValidateRequiredUrlParameter(nameof(balanceId), balanceId); var queryParameters = BuildListBalanceTransactionsQueryParameters(from, limit); return await GetAsync($"balances/{balanceId}/transactions{queryParameters.ToQueryString()}").ConfigureAwait(false); } - public async Task ListPrimaryBalanceTransactionsAsync(string? from = null, int? limit = null) { + public async Task GetPrimaryBalanceTransactionListAsync(string? from = null, int? limit = null) { var queryParameters = BuildListBalanceTransactionsQueryParameters(from, limit); return await GetAsync($"balances/primary/transactions{queryParameters.ToQueryString()}").ConfigureAwait(false); } diff --git a/src/Mollie.Api/Client/CaptureClient.cs b/src/Mollie.Api/Client/CaptureClient.cs index c1cfecf3..bfcb5fb1 100644 --- a/src/Mollie.Api/Client/CaptureClient.cs +++ b/src/Mollie.Api/Client/CaptureClient.cs @@ -26,14 +26,14 @@ public async Task GetCaptureAsync(UrlObjectLink> GetCapturesListAsync(string paymentId, bool testmode = false) { + public async Task> GetCaptureListAsync(string paymentId, bool testmode = false) { ValidateRequiredUrlParameter(nameof(paymentId), paymentId); var queryParameters = BuildQueryParameters(testmode); return await GetAsync>($"payments/{paymentId}/captures{queryParameters.ToQueryString()}") .ConfigureAwait(false); } - public async Task> GetCapturesListAsync(UrlObjectLink> url) { + public async Task> GetCaptureListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } diff --git a/src/Mollie.Api/Client/ChargebacksClient.cs b/src/Mollie.Api/Client/ChargebackClient.cs similarity index 83% rename from src/Mollie.Api/Client/ChargebacksClient.cs rename to src/Mollie.Api/Client/ChargebackClient.cs index d7c5d052..1e3ea12a 100644 --- a/src/Mollie.Api/Client/ChargebacksClient.cs +++ b/src/Mollie.Api/Client/ChargebackClient.cs @@ -8,8 +8,8 @@ using Mollie.Api.Models.Url; namespace Mollie.Api.Client { - public class ChargebacksClient : BaseMollieClient, IChargebacksClient { - public ChargebacksClient(string apiKey, HttpClient? httpClient = null) : base(apiKey, httpClient) { + public class ChargebackClient : BaseMollieClient, IChargebackClient { + public ChargebackClient(string apiKey, HttpClient? httpClient = null) : base(apiKey, httpClient) { } public async Task GetChargebackAsync(string paymentId, string chargebackId, bool testmode = false) { @@ -20,7 +20,7 @@ public async Task GetChargebackAsync(string paymentId, strin .ConfigureAwait(false); } - public async Task> GetChargebacksListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false) { + public async Task> GetChargebackListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false) { ValidateRequiredUrlParameter(nameof(paymentId), paymentId); var queryParameters = BuildQueryParameters(testmode); return await this @@ -28,12 +28,12 @@ public async Task> GetChargebacksListAsync(stri .ConfigureAwait(false); } - public async Task> GetChargebacksListAsync(string? profileId = null, bool testmode = false) { + public async Task> GetChargebackListAsync(string? profileId = null, bool testmode = false) { var queryParameters = BuildQueryParameters(profileId, testmode); return await GetListAsync>($"chargebacks", null, null, queryParameters).ConfigureAwait(false); } - public async Task> GetChargebacksListAsync(UrlObjectLink> url) { + public async Task> GetChargebackListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } diff --git a/src/Mollie.Api/Client/InvoicesClient.cs b/src/Mollie.Api/Client/InvoiceClient.cs similarity index 88% rename from src/Mollie.Api/Client/InvoicesClient.cs rename to src/Mollie.Api/Client/InvoiceClient.cs index ad560769..8284e62e 100644 --- a/src/Mollie.Api/Client/InvoicesClient.cs +++ b/src/Mollie.Api/Client/InvoiceClient.cs @@ -9,8 +9,8 @@ using Mollie.Api.Models.Url; namespace Mollie.Api.Client { - public class InvoicesClient : OauthBaseMollieClient, IInvoicesClient { - public InvoicesClient(string oauthAccessToken, HttpClient? httpClient = null) : base(oauthAccessToken, httpClient) { + public class InvoiceClient : OauthBaseMollieClient, IInvoiceClient { + public InvoiceClient(string oauthAccessToken, HttpClient? httpClient = null) : base(oauthAccessToken, httpClient) { } public async Task GetInvoiceAsync(string invoiceId) { diff --git a/src/Mollie.Api/Client/OrderClient.cs b/src/Mollie.Api/Client/OrderClient.cs index 9ba3db38..97566c3d 100644 --- a/src/Mollie.Api/Client/OrderClient.cs +++ b/src/Mollie.Api/Client/OrderClient.cs @@ -9,7 +9,6 @@ using Mollie.Api.Models.Order.Request.ManageOrderLines; using Mollie.Api.Models.Order.Response; using Mollie.Api.Models.Payment.Response; -using Mollie.Api.Models.Refund.Response; using Mollie.Api.Models.Url; namespace Mollie.Api.Client { @@ -69,17 +68,6 @@ public async Task CreateOrderPaymentAsync(string orderId, Order return await PostAsync($"orders/{orderId}/payments", createOrderPaymentRequest).ConfigureAwait(false); } - public async Task CreateOrderRefundAsync(string orderId, OrderRefundRequest createOrderRefundRequest) { - ValidateRequiredUrlParameter(nameof(orderId), orderId); - return await PostAsync($"orders/{orderId}/refunds", createOrderRefundRequest); - } - - public async Task> GetOrderRefundListAsync(string orderId, string? from = null, int? limit = null, bool testmode = false) { - ValidateRequiredUrlParameter(nameof(orderId), orderId); - var queryParameters = BuildQueryParameters(null, testmode); - return await GetListAsync>($"orders/{orderId}/refunds", from, limit, queryParameters).ConfigureAwait(false); - } - private Dictionary BuildQueryParameters(string? profileId = null, bool testmode = false, SortDirection? sort = null) { var result = new Dictionary(); result.AddValueIfNotNullOrEmpty(nameof(profileId), profileId); diff --git a/src/Mollie.Api/Client/OrganizationsClient.cs b/src/Mollie.Api/Client/OrganizationClient.cs similarity index 77% rename from src/Mollie.Api/Client/OrganizationsClient.cs rename to src/Mollie.Api/Client/OrganizationClient.cs index 75a25e8b..f9e86853 100644 --- a/src/Mollie.Api/Client/OrganizationsClient.cs +++ b/src/Mollie.Api/Client/OrganizationClient.cs @@ -6,8 +6,8 @@ using Mollie.Api.Models.Url; namespace Mollie.Api.Client { - public class OrganizationsClient : OauthBaseMollieClient, IOrganizationsClient { - public OrganizationsClient(string oauthAccessToken, HttpClient? httpClient = null) : base(oauthAccessToken, httpClient) { + public class OrganizationClient : OauthBaseMollieClient, IOrganizationClient { + public OrganizationClient(string oauthAccessToken, HttpClient? httpClient = null) : base(oauthAccessToken, httpClient) { } public async Task GetCurrentOrganizationAsync() { @@ -23,11 +23,11 @@ public async Task GetOrganizationAsync(UrlObjectLink> GetOrganizationsListAsync(string? from = null, int? limit = null) { + public async Task> GetOrganizationListAsync(string? from = null, int? limit = null) { return await GetListAsync>("organizations", from, limit).ConfigureAwait(false); } - public async Task> GetOrganizationsListAsync(UrlObjectLink> url) { + public async Task> GetOrganizationListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } } diff --git a/src/Mollie.Api/Client/PaymentClient.cs b/src/Mollie.Api/Client/PaymentClient.cs index 492c52d1..2f13e526 100644 --- a/src/Mollie.Api/Client/PaymentClient.cs +++ b/src/Mollie.Api/Client/PaymentClient.cs @@ -49,7 +49,7 @@ public async Task GetPaymentAsync( return await GetAsync($"payments/{paymentId}{queryParameters.ToQueryString()}").ConfigureAwait(false); } - public async Task DeletePaymentAsync(string paymentId, bool testmode = false) { + public async Task CancelPaymentAsync(string paymentId, bool testmode = false) { ValidateRequiredUrlParameter(nameof(paymentId), paymentId); var data = TestmodeModel.Create(testmode); diff --git a/src/Mollie.Api/Client/PermissionsClient.cs b/src/Mollie.Api/Client/PermissionClient.cs similarity index 81% rename from src/Mollie.Api/Client/PermissionsClient.cs rename to src/Mollie.Api/Client/PermissionClient.cs index 9f871a4d..7034dede 100644 --- a/src/Mollie.Api/Client/PermissionsClient.cs +++ b/src/Mollie.Api/Client/PermissionClient.cs @@ -6,8 +6,8 @@ using Mollie.Api.Models.Url; namespace Mollie.Api.Client { - public class PermissionsClient : OauthBaseMollieClient, IPermissionsClient { - public PermissionsClient(string oauthAccessToken, HttpClient? httpClient = null) : base(oauthAccessToken, httpClient) { + public class PermissionClient : OauthBaseMollieClient, IPermissionClient { + public PermissionClient(string oauthAccessToken, HttpClient? httpClient = null) : base(oauthAccessToken, httpClient) { } public async Task GetPermissionAsync(string permissionId) { diff --git a/src/Mollie.Api/Client/RefundClient.cs b/src/Mollie.Api/Client/RefundClient.cs index b771ffd0..cf23b322 100644 --- a/src/Mollie.Api/Client/RefundClient.cs +++ b/src/Mollie.Api/Client/RefundClient.cs @@ -4,6 +4,8 @@ using Mollie.Api.Client.Abstract; using Mollie.Api.Extensions; using Mollie.Api.Models.List.Response; +using Mollie.Api.Models.Order.Request; +using Mollie.Api.Models.Order.Response; using Mollie.Api.Models.Refund.Request; using Mollie.Api.Models.Refund.Response; using Mollie.Api.Models.Url; @@ -13,7 +15,7 @@ public class RefundClient : BaseMollieClient, IRefundClient { public RefundClient(string apiKey, HttpClient? httpClient = null) : base(apiKey, httpClient) { } - public async Task CreateRefundAsync(string paymentId, RefundRequest refundRequest) { + public async Task CreatePaymentRefundAsync(string paymentId, RefundRequest refundRequest) { ValidateRequiredUrlParameter(nameof(paymentId), paymentId); if (refundRequest.Testmode.HasValue) @@ -30,7 +32,7 @@ public async Task> GetRefundListAsync(string? from return await GetListAsync>($"refunds", from, limit, queryParameters).ConfigureAwait(false); } - public async Task> GetRefundListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false) { + public async Task> GetPaymentRefundListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false) { ValidateRequiredUrlParameter(nameof(paymentId), paymentId); var queryParameters = BuildQueryParameters(testmode: testmode); @@ -46,20 +48,31 @@ public async Task GetRefundAsync(UrlObjectLink u return await GetAsync(url).ConfigureAwait(false); } - public async Task GetRefundAsync(string paymentId, string refundId, bool testmode = false) { + public async Task GetPaymentRefundAsync(string paymentId, string refundId, bool testmode = false) { ValidateRequiredUrlParameter(nameof(paymentId), paymentId); ValidateRequiredUrlParameter(nameof(refundId), refundId); var queryParameters = BuildQueryParameters(testmode: testmode); return await GetAsync($"payments/{paymentId}/refunds/{refundId}{queryParameters.ToQueryString()}").ConfigureAwait(false); } - public async Task CancelRefundAsync(string paymentId, string refundId, bool testmode = default) { + public async Task CancelPaymentRefundAsync(string paymentId, string refundId, bool testmode = default) { ValidateRequiredUrlParameter(nameof(paymentId), paymentId); ValidateRequiredUrlParameter(nameof(refundId), refundId); var queryParameters = BuildQueryParameters(testmode: testmode); await DeleteAsync($"payments/{paymentId}/refunds/{refundId}{queryParameters.ToQueryString()}").ConfigureAwait(false); } + public async Task CreateOrderRefundAsync(string orderId, OrderRefundRequest createOrderRefundRequest) { + ValidateRequiredUrlParameter(nameof(orderId), orderId); + return await PostAsync($"orders/{orderId}/refunds", createOrderRefundRequest); + } + + public async Task> GetOrderRefundListAsync(string orderId, string? from = null, int? limit = null, bool testmode = false) { + ValidateRequiredUrlParameter(nameof(orderId), orderId); + var queryParameters = BuildQueryParameters(testmode); + return await GetListAsync>($"orders/{orderId}/refunds", from, limit, queryParameters).ConfigureAwait(false); + } + private Dictionary BuildQueryParameters(bool testmode = false) { var result = new Dictionary(); result.AddValueIfTrue(nameof(testmode), testmode); diff --git a/src/Mollie.Api/Client/SettlementsClient.cs b/src/Mollie.Api/Client/SettlementClient.cs similarity index 77% rename from src/Mollie.Api/Client/SettlementsClient.cs rename to src/Mollie.Api/Client/SettlementClient.cs index 022cff0a..c8a60555 100644 --- a/src/Mollie.Api/Client/SettlementsClient.cs +++ b/src/Mollie.Api/Client/SettlementClient.cs @@ -10,8 +10,8 @@ using Mollie.Api.Models.Url; namespace Mollie.Api.Client { - public class SettlementsClient : BaseMollieClient, ISettlementsClient { - public SettlementsClient(string oauthAccessToken, HttpClient? httpClient = null) : base(oauthAccessToken, httpClient) { + public class SettlementClient : BaseMollieClient, ISettlementClient { + public SettlementClient(string oauthAccessToken, HttpClient? httpClient = null) : base(oauthAccessToken, httpClient) { } public async Task GetSettlementAsync(string settlementId) { @@ -27,53 +27,53 @@ public async Task GetOpenSettlement() { return await GetAsync($"settlements/open").ConfigureAwait(false); } - public async Task> GetSettlementsListAsync(string? reference = null, string? offset = null, int? count = null) { + public async Task> GetSettlementListAsync(string? reference = null, string? offset = null, int? count = null) { var queryString = !string.IsNullOrWhiteSpace(reference) ? $"?reference={reference}" : string.Empty; return await GetListAsync>($"settlements{queryString}", offset, count).ConfigureAwait(false); } - public async Task> GetSettlementsListAsync(UrlObjectLink> url) + public async Task> GetSettlementListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } - public async Task> GetSettlementPaymentsListAsync(string settlementId, string? offset = null, int? count = null) { + public async Task> GetSettlementPaymentListAsync(string settlementId, string? offset = null, int? count = null) { ValidateRequiredUrlParameter(nameof(settlementId), settlementId); return await GetListAsync>($"settlements/{settlementId}/payments", offset, count).ConfigureAwait(false); } - public async Task> GetSettlementPaymentsListAsync(UrlObjectLink> url) + public async Task> GetSettlementPaymentListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } - public async Task> GetSettlementRefundsListAsync(string settlementId, string? offset = null, int? count = null) { + public async Task> GetSettlementRefundListAsync(string settlementId, string? offset = null, int? count = null) { ValidateRequiredUrlParameter(nameof(settlementId), settlementId); return await GetListAsync>($"settlements/{settlementId}/refunds", offset, count).ConfigureAwait(false); } - public async Task> GetSettlementRefundsListAsync(UrlObjectLink> url) + public async Task> GetSettlementRefundListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } - public async Task> GetSettlementChargebacksListAsync(string settlementId, string? offset = null, int? count = null) { + public async Task> GetSettlementChargebackListAsync(string settlementId, string? offset = null, int? count = null) { ValidateRequiredUrlParameter(nameof(settlementId), settlementId); return await GetListAsync>($"settlements/{settlementId}/chargebacks", offset, count).ConfigureAwait(false); } - public async Task> GetSettlementChargebacksListAsync(UrlObjectLink> url) + public async Task> GetSettlementChargebackListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } - public async Task> GetSettlementCapturesListAsync(string settlementId, string? offset = null, int? count = null) + public async Task> GetSettlementCaptureListAsync(string settlementId, string? offset = null, int? count = null) { ValidateRequiredUrlParameter(nameof(settlementId), settlementId); return await GetListAsync>($"settlements/{settlementId}/captures", offset, count).ConfigureAwait(false); } - public async Task> GetSettlementCapturesListAsync(UrlObjectLink> url) + public async Task> GetSettlementCaptureListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } @@ -84,7 +84,7 @@ public async Task GetSettlementAsync(UrlObjectLink> ListSettlementCapturesAsync(string settlementId) { - return await GetSettlementCapturesListAsync(settlementId); + return await GetSettlementCaptureListAsync(settlementId); } } } diff --git a/src/Mollie.Api/Client/ShipmentClient.cs b/src/Mollie.Api/Client/ShipmentClient.cs index e3146c16..d8551c09 100644 --- a/src/Mollie.Api/Client/ShipmentClient.cs +++ b/src/Mollie.Api/Client/ShipmentClient.cs @@ -32,14 +32,14 @@ public async Task GetShipmentAsync(UrlObjectLink> GetShipmentsListAsync(string orderId, bool testmode = false) { + public async Task> GetShipmentListAsync(string orderId, bool testmode = false) { ValidateRequiredUrlParameter(nameof(orderId), orderId); var queryParameters = BuildQueryParameters(testmode); return await GetAsync>($"orders/{orderId}/shipments{queryParameters.ToQueryString()}") .ConfigureAwait(false); } - public async Task> GetShipmentsListAsync(UrlObjectLink> url) { + public async Task> GetShipmentListAsync(UrlObjectLink> url) { return await GetAsync(url).ConfigureAwait(false); } diff --git a/src/Mollie.Api/DependencyInjection.cs b/src/Mollie.Api/DependencyInjection.cs index d1a815aa..91665c8d 100644 --- a/src/Mollie.Api/DependencyInjection.cs +++ b/src/Mollie.Api/DependencyInjection.cs @@ -19,36 +19,36 @@ public static IServiceCollection AddMollieApi( new BalanceClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new CaptureClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); - RegisterMollieApiClient(services, httpClient => - new ChargebacksClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); + RegisterMollieApiClient(services, httpClient => + new ChargebackClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new ConnectClient(mollieOptions.ClientId, mollieOptions.ClientSecret, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new CustomerClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); - RegisterMollieApiClient(services, httpClient => - new InvoicesClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); + RegisterMollieApiClient(services, httpClient => + new InvoiceClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new MandateClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new OnboardingClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new OrderClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); - RegisterMollieApiClient(services, httpClient => - new OrganizationsClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); + RegisterMollieApiClient(services, httpClient => + new OrganizationClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new PaymentClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new PaymentLinkClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new PaymentMethodClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); - RegisterMollieApiClient(services, httpClient => - new PermissionsClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); + RegisterMollieApiClient(services, httpClient => + new PermissionClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new ProfileClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new RefundClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); - RegisterMollieApiClient(services, httpClient => - new SettlementsClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); + RegisterMollieApiClient(services, httpClient => + new SettlementClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => new ShipmentClient(mollieOptions.ApiKey, httpClient), mollieOptions.RetryPolicy); RegisterMollieApiClient(services, httpClient => diff --git a/tests/Mollie.Tests.Integration/Api/BalanceTests.cs b/tests/Mollie.Tests.Integration/Api/BalanceTests.cs index 7eaf7580..a3d6b4cc 100644 --- a/tests/Mollie.Tests.Integration/Api/BalanceTests.cs +++ b/tests/Mollie.Tests.Integration/Api/BalanceTests.cs @@ -41,7 +41,7 @@ public async Task GetPrimaryBalanceAsync_IsParsedCorrectly() { [DefaultRetryFact] public async Task GetBalanceAsync_IsParsedCorrectly() { // Given: We get a balance id from the list balances endpoint - var balanceList = await _balanceClient.ListBalancesAsync(); + var balanceList = await _balanceClient.GetBalanceListAsync(); if (balanceList.Count == 0) { Assert.Fail("No balance found to retrieve"); } @@ -67,7 +67,7 @@ public async Task GetBalanceAsync_IsParsedCorrectly() { [DefaultRetryFact] public async Task ListBalancesAsync_IsParsedCorrectly() { // When: We retrieve the list of balances - var result = await _balanceClient.ListBalancesAsync(); + var result = await _balanceClient.GetBalanceListAsync(); // Then: Make sure we can parse the result result.Should().NotBeNull(); @@ -108,7 +108,7 @@ public async Task ListBalanceTransactionsAsync_IsParsedCorrectly() { var limit = 250; // When: We list the balance transactions - var result = await _balanceClient.ListBalanceTransactionsAsync(balanceId, from, limit); + var result = await _balanceClient.GetBalanceTransactionListAsync(balanceId, from, limit); // Then: Make sure we can parse the result result.Should().NotBeNull(); @@ -125,7 +125,7 @@ public async Task ListPrimaryBalanceTransactionsAsync_IsParsedCorrectly() { var limit = 250; // When: We list the balance transactions - var result = await _balanceClient.ListPrimaryBalanceTransactionsAsync(from, limit); + var result = await _balanceClient.GetPrimaryBalanceTransactionListAsync(from, limit); // Then: Make sure we can parse the result result.Should().NotBeNull(); diff --git a/tests/Mollie.Tests.Integration/Api/CaptureTests.cs b/tests/Mollie.Tests.Integration/Api/CaptureTests.cs index c54b5fef..afabc5ec 100644 --- a/tests/Mollie.Tests.Integration/Api/CaptureTests.cs +++ b/tests/Mollie.Tests.Integration/Api/CaptureTests.cs @@ -73,7 +73,7 @@ public async Task CanRetrieveCaptureListForPayment() await _captureClient.CreateCapture(payment.Id, captureRequest); // When: we retrieve the captures of the payment - var captureList = await _captureClient.GetCapturesListAsync(payment.Id); + var captureList = await _captureClient.GetCaptureListAsync(payment.Id); // Then captureList.Count.Should().Be(1); diff --git a/tests/Mollie.Tests.Integration/Api/RefundTests.cs b/tests/Mollie.Tests.Integration/Api/RefundTests.cs index dde3c3a1..3ba9f7a7 100644 --- a/tests/Mollie.Tests.Integration/Api/RefundTests.cs +++ b/tests/Mollie.Tests.Integration/Api/RefundTests.cs @@ -38,7 +38,7 @@ public async Task CanCreateRefund() { RefundRequest refundRequest = new RefundRequest() { Amount = new Amount(Currency.EUR, amount) }; - RefundResponse refundResponse = await _refundClient.CreateRefundAsync(payment.Id, refundRequest); + RefundResponse refundResponse = await _refundClient.CreatePaymentRefundAsync(payment.Id, refundRequest); // Then refundResponse.Should().NotBeNull(); @@ -57,7 +57,7 @@ public async Task CanCreatePartialRefund() { RefundRequest refundRequest = new RefundRequest() { Amount = new Amount(Currency.EUR, "50.00") }; - RefundResponse refundResponse = await _refundClient.CreateRefundAsync(payment.Id, refundRequest); + RefundResponse refundResponse = await _refundClient.CreatePaymentRefundAsync(payment.Id, refundRequest); // Then refundResponse.Amount.Should().Be(refundRequest.Amount); @@ -74,10 +74,10 @@ public async Task CanRetrieveSingleRefund() { RefundRequest refundRequest = new RefundRequest() { Amount = new Amount(Currency.EUR, "50.00") }; - RefundResponse refundResponse = await _refundClient.CreateRefundAsync(payment.Id, refundRequest); + RefundResponse refundResponse = await _refundClient.CreatePaymentRefundAsync(payment.Id, refundRequest); // When: We attempt to retrieve this refund - RefundResponse result = await _refundClient.GetRefundAsync(payment.Id, refundResponse.Id); + RefundResponse result = await _refundClient.GetPaymentRefundAsync(payment.Id, refundResponse.Id); // Then result.Should().NotBeNull(); @@ -91,7 +91,7 @@ public async Task CanRetrieveRefundList() { PaymentResponse payment = await CreatePayment(); // When: Retrieve refund list for this payment - ListResponse refundList = await _refundClient.GetRefundListAsync(payment.Id); + ListResponse refundList = await _refundClient.GetPaymentRefundListAsync(payment.Id); // Then refundList.Should().NotBeNull(); @@ -114,7 +114,7 @@ public async Task CanCreateRefundWithMetaData() { Amount = new Amount(Currency.EUR, amount), Metadata = metadata }; - RefundResponse refundResponse = await _refundClient.CreateRefundAsync(payment.Id, refundRequest); + RefundResponse refundResponse = await _refundClient.CreatePaymentRefundAsync(payment.Id, refundRequest); // Then: Make sure we get the same json result as metadata refundResponse.Metadata.Should().Be(metadata); diff --git a/tests/Mollie.Tests.Integration/Api/ShipmentTests.cs b/tests/Mollie.Tests.Integration/Api/ShipmentTests.cs index b17023e8..1210ac0a 100644 --- a/tests/Mollie.Tests.Integration/Api/ShipmentTests.cs +++ b/tests/Mollie.Tests.Integration/Api/ShipmentTests.cs @@ -33,7 +33,7 @@ public async Task CanCreateShipmentWithOnlyRequiredFields() { [DefaultRetryFact(Skip = "For manual testing only")] public async Task CanListShipmentsForOrder(){ string validOrderId = "XXXXX"; - ListResponse result = await _shipmentClient.GetShipmentsListAsync(validOrderId); + ListResponse result = await _shipmentClient.GetShipmentListAsync(validOrderId); result.Should().NotBeNull(); result.Count.Should().BeGreaterThan(0); diff --git a/tests/Mollie.Tests.Unit/Client/BalanceClientTests.cs b/tests/Mollie.Tests.Unit/Client/BalanceClientTests.cs index 1d142999..be53d225 100644 --- a/tests/Mollie.Tests.Unit/Client/BalanceClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/BalanceClientTests.cs @@ -115,7 +115,7 @@ public async Task ListBalancesAsync_DefaultBehaviour_ResponseIsParsed() { BalanceClient balanceClient = new BalanceClient("api-key", httpClient); // When: We make the request - var balances = await balanceClient.ListBalancesAsync(); + var balances = await balanceClient.GetBalanceListAsync(); // Then: Response should be parsed mockHttp.VerifyNoOutstandingExpectation(); @@ -230,7 +230,7 @@ public async Task ListBalanceTransactionsAsync_StatusBalances_ResponseIsParsed() BalanceClient balanceClient = new BalanceClient("api-key", httpClient); // When: We make the request - var balanceTransactions = await balanceClient.ListBalanceTransactionsAsync(balanceId); + var balanceTransactions = await balanceClient.GetBalanceTransactionListAsync(balanceId); // Then: Response should be parsed mockHttp.VerifyNoOutstandingExpectation(); @@ -261,7 +261,7 @@ public async Task ListBalanceTransactionsAsync_NoBalanceIdIsGiven_ArgumentExcept BalanceClient balanceClient = new BalanceClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await balanceClient.ListBalanceTransactionsAsync(balanceId)); + var exception = await Assert.ThrowsAsync(async () => await balanceClient.GetBalanceTransactionListAsync(balanceId)); // Then exception.Message.Should().Be("Required URL argument 'balanceId' is null or empty"); @@ -276,7 +276,7 @@ public async Task ListPrimaryBalanceTransactionsAsync_StatusBalances_ResponseIsP BalanceClient balanceClient = new BalanceClient("api-key", httpClient); // When: We make the request - var balanceTransactions = await balanceClient.ListPrimaryBalanceTransactionsAsync(); + var balanceTransactions = await balanceClient.GetPrimaryBalanceTransactionListAsync(); // Then: Response should be parsed mockHttp.VerifyNoOutstandingExpectation(); diff --git a/tests/Mollie.Tests.Unit/Client/CaptureClientTests.cs b/tests/Mollie.Tests.Unit/Client/CaptureClientTests.cs index f35d71ec..1ef5d806 100644 --- a/tests/Mollie.Tests.Unit/Client/CaptureClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/CaptureClientTests.cs @@ -95,7 +95,7 @@ public async Task GetCapturesListAsync_CorrectQueryParametersAreAdded(bool testm CaptureClient captureClient = new CaptureClient("abcde", httpClient); // When: We send the request - await captureClient.GetCapturesListAsync(paymentId, testmode); + await captureClient.GetCaptureListAsync(paymentId, testmode); // Then mockHttp.VerifyNoOutstandingRequest(); @@ -132,7 +132,7 @@ public async Task GetCapturesListAsync_DefaultBehaviour_ResponseIsParsed() { CaptureClient captureClient = new CaptureClient("api-key", httpClient); // When: We make the request - ListResponse listCaptureResponse = await captureClient.GetCapturesListAsync(defaultPaymentId); + ListResponse listCaptureResponse = await captureClient.GetCaptureListAsync(defaultPaymentId); // Then: Response should be parsed mockHttp.VerifyNoOutstandingExpectation(); @@ -192,7 +192,7 @@ public async Task GetCapturesListAsync_NoPaymentIdIsGiven_ArgumentExceptionIsThr CaptureClient captureClient = new CaptureClient("abcde", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await captureClient.GetCapturesListAsync(paymentId)); + var exception = await Assert.ThrowsAsync(async () => await captureClient.GetCaptureListAsync(paymentId)); // Then exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty"); diff --git a/tests/Mollie.Tests.Unit/Client/ChargebacksClientTests.cs b/tests/Mollie.Tests.Unit/Client/ChargebackClientTests.cs similarity index 83% rename from tests/Mollie.Tests.Unit/Client/ChargebacksClientTests.cs rename to tests/Mollie.Tests.Unit/Client/ChargebackClientTests.cs index 52b654c6..2e0058d6 100644 --- a/tests/Mollie.Tests.Unit/Client/ChargebacksClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/ChargebackClientTests.cs @@ -8,7 +8,7 @@ using Xunit; namespace Mollie.Tests.Unit.Client { - public class ChargebacksClientTests : BaseClientTests { + public class ChargebackClientTests : BaseClientTests { private const string defaultPaymentId = "tr_WDqYK6vllg"; private const string defaultChargebackId = "chb_n9z0tp"; private const string defaultChargebackReasonCode = "AC01"; @@ -55,10 +55,10 @@ public async Task GetChargebackAsync_ResponseIsDeserializedInExpectedFormat() { mockHttp.When($"{BaseMollieClient.ApiEndPoint}*") .Respond("application/json", defaultGetChargebacksResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - ChargebacksClient chargebacksClient = new ChargebacksClient("abcde", httpClient); + ChargebackClient chargebackClient = new ChargebackClient("abcde", httpClient); // When: We send the request - ChargebackResponse chargebackResponse = await chargebacksClient.GetChargebackAsync(defaultPaymentId, defaultChargebackId); + ChargebackResponse chargebackResponse = await chargebackClient.GetChargebackAsync(defaultPaymentId, defaultChargebackId); // Then chargebackResponse.PaymentId.Should().Be(defaultPaymentId); @@ -77,10 +77,10 @@ public async Task GetOrderRefundListAsync_QueryParameterOptions_CorrectParameter mockHttp.When($"{BaseMollieClient.ApiEndPoint}payments/{defaultPaymentId}/chargebacks/{defaultChargebackId}{expectedQueryString}") .Respond("application/json", defaultGetChargebacksResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - ChargebacksClient chargebacksClient = new ChargebacksClient("abcde", httpClient); + ChargebackClient chargebackClient = new ChargebackClient("abcde", httpClient); // When: We send the request - await chargebacksClient.GetChargebackAsync(defaultPaymentId, defaultChargebackId, testmode); + await chargebackClient.GetChargebackAsync(defaultPaymentId, defaultChargebackId, testmode); // Then mockHttp.VerifyNoOutstandingRequest(); @@ -97,10 +97,10 @@ public async Task GetChargebacksListAsync_FromLimitTestmodeQueryParameterOptions mockHttp.When($"{BaseMollieClient.ApiEndPoint}payments/{defaultPaymentId}/chargebacks{expectedQueryString}") .Respond("application/json", defaultGetChargebacksResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - ChargebacksClient chargebacksClient = new ChargebacksClient("abcde", httpClient); + ChargebackClient chargebackClient = new ChargebackClient("abcde", httpClient); // When: We send the request - await chargebacksClient.GetChargebacksListAsync(defaultPaymentId, from, limit, testmode); + await chargebackClient.GetChargebackListAsync(defaultPaymentId, from, limit, testmode); // Then mockHttp.VerifyNoOutstandingRequest(); @@ -116,10 +116,10 @@ public async Task GetChargebacksListAsync_ProfileTestModeQueryParameterOptions_C mockHttp.When($"{BaseMollieClient.ApiEndPoint}chargebacks{expectedQueryString}") .Respond("application/json", defaultGetChargebacksResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - ChargebacksClient chargebacksClient = new ChargebacksClient("abcde", httpClient); + ChargebackClient chargebackClient = new ChargebackClient("abcde", httpClient); // When: We send the request - await chargebacksClient.GetChargebacksListAsync(profileId, testmode); + await chargebackClient.GetChargebackListAsync(profileId, testmode); // Then mockHttp.VerifyNoOutstandingRequest(); @@ -133,10 +133,10 @@ public async Task GetChargebackAsync_NoPaymentIdIsGiven_ArgumentExceptionIsThrow // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - ChargebacksClient chargebacksClient = new ChargebacksClient("api-key", httpClient); + ChargebackClient chargebackClient = new ChargebackClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await chargebacksClient.GetChargebackAsync(paymentId, "chargeback-id")); + var exception = await Assert.ThrowsAsync(async () => await chargebackClient.GetChargebackAsync(paymentId, "chargeback-id")); // Then exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty"); @@ -150,10 +150,10 @@ public async Task GetChargebackAsync_NoChargeBackIdIsGiven_ArgumentExceptionIsTh // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - ChargebacksClient chargebacksClient = new ChargebacksClient("api-key", httpClient); + ChargebackClient chargebackClient = new ChargebackClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await chargebacksClient.GetChargebackAsync("payment-id", chargebackId)); + var exception = await Assert.ThrowsAsync(async () => await chargebackClient.GetChargebackAsync("payment-id", chargebackId)); // Then exception.Message.Should().Be("Required URL argument 'chargebackId' is null or empty"); @@ -167,10 +167,10 @@ public async Task GetChargebacksListAsync_NoPaymentIdIsGiven_ArgumentExceptionIs // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - ChargebacksClient chargebacksClient = new ChargebacksClient("api-key", httpClient); + ChargebackClient chargebackClient = new ChargebackClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await chargebacksClient.GetChargebacksListAsync(paymentId: paymentId)); + var exception = await Assert.ThrowsAsync(async () => await chargebackClient.GetChargebackListAsync(paymentId: paymentId)); // Then exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty"); diff --git a/tests/Mollie.Tests.Unit/Client/InvoiceClientTests.cs b/tests/Mollie.Tests.Unit/Client/InvoiceClientTests.cs index 1aba907a..07a46e4e 100644 --- a/tests/Mollie.Tests.Unit/Client/InvoiceClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/InvoiceClientTests.cs @@ -18,10 +18,10 @@ public async Task GetInvoiceAsync_DefaultBehaviour_ResponseIsParsed() mockHttp.When($"{BaseMollieClient.ApiEndPoint}invoices/{invoiceId}") .Respond("application/json", defaultInvoice); HttpClient httpClient = mockHttp.ToHttpClient(); - using InvoicesClient invoicesClient = new InvoicesClient("access_abcde", httpClient); + using InvoiceClient invoiceClient = new InvoiceClient("access_abcde", httpClient); // When - var result = await invoicesClient.GetInvoiceAsync(invoiceId); + var result = await invoiceClient.GetInvoiceAsync(invoiceId); // Then mockHttp.VerifyNoOutstandingExpectation(); @@ -46,10 +46,10 @@ public async Task GetInvoiceListAsync_WithVariousParameters_QueryStringMatchesEx mockHttp.When($"{BaseMollieClient.ApiEndPoint}invoices{expectedQueryString}") .Respond("application/json", defaultInvoiceList); HttpClient httpClient = mockHttp.ToHttpClient(); - using InvoicesClient invoicesClient = new InvoicesClient("access_abcde", httpClient); + using InvoiceClient invoiceClient = new InvoiceClient("access_abcde", httpClient); // When: We send the request - var result = await invoicesClient.GetInvoiceListAsync( + var result = await invoiceClient.GetInvoiceListAsync( reference, year, from, limit); // Then diff --git a/tests/Mollie.Tests.Unit/Client/OrderClientTests.cs b/tests/Mollie.Tests.Unit/Client/OrderClientTests.cs index 9320a5ce..2afdd856 100644 --- a/tests/Mollie.Tests.Unit/Client/OrderClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/OrderClientTests.cs @@ -103,25 +103,6 @@ public async Task GetOrderListAsync_QueryParameterOptions_CorrectParametersAreAd mockHttp.VerifyNoOutstandingRequest(); } - [Theory] - [InlineData(null, null, false, "")] - [InlineData("from", null, false, "?from=from")] - [InlineData("from", 50, false, "?from=from&limit=50")] - [InlineData(null, null, true, "?testmode=true")] - public async Task GetOrderRefundListAsync_QueryParameterOptions_CorrectParametersAreAdded(string from, int? limit, bool testmode, string expectedQueryString) { - // Given: We make a request to retrieve the list of orders - const string orderId = "abcde"; - var mockHttp = CreateMockHttpMessageHandler(HttpMethod.Get, $"{BaseMollieClient.ApiEndPoint}orders/{orderId}/refunds{expectedQueryString}", defaultOrderJsonResponse); - HttpClient httpClient = mockHttp.ToHttpClient(); - OrderClient orderClient = new OrderClient("abcde", httpClient); - - // When: We send the request - await orderClient.GetOrderRefundListAsync(orderId, from, limit, testmode); - - // Then - mockHttp.VerifyNoOutstandingRequest(); - } - [Fact] public async Task CreateOrderAsync_SinglePaymentMethod_RequestIsSerializedInExpectedFormat() { // Given: we create a order with a single payment method @@ -215,45 +196,6 @@ public async Task CreateOrderPaymentAsync_PaymentWithMultiplePaymentMethods_Requ mockHttp.VerifyNoOutstandingExpectation(); } - [Fact] - public async Task CreateOrderRefundAsync_WithRequiredParameters_ResponseIsDeserializedInExpectedFormat() - { - // Given: We create a refund request with only the required parameters - const string orderId = "ord_stTC2WHAuS"; - OrderRefundRequest orderRefundRequest = new OrderRefundRequest() - { - Description = "description", - Lines = new[] - { - new OrderLineDetails() - { - Id = "odl_dgtxyl", - Quantity = 1, - Amount = new Amount(Currency.EUR, "399.00") - } - }, - Metadata = "my-metadata" - }; - string url = $"{BaseMollieClient.ApiEndPoint}orders/{orderId}/refunds"; - var mockHttp = CreateMockHttpMessageHandler(HttpMethod.Post, url, defaultOrderRefundJsonResponse); - HttpClient httpClient = mockHttp.ToHttpClient(); - OrderClient orderClient = new OrderClient("abcde", httpClient); - - // When: We send the request - var response = await orderClient.CreateOrderRefundAsync(orderId, orderRefundRequest); - - // Then - mockHttp.VerifyNoOutstandingExpectation(); - response.Resource.Should().Be("refund"); - response.Id.Should().Be("re_4qqhO89gsT"); - response.Description.Should().Be("description"); - response.Status.Should().Be("pending"); - response.CreatedAt!.Value.ToUniversalTime().Should().Be(DateTime.SpecifyKind(14.March(2018).At(17, 09, 02), DateTimeKind.Utc)); - response.PaymentId.Should().Be("tr_WDqYK6vllg"); - response.OrderId.Should().Be(orderId); - response.Lines.Should().HaveCount(1); - } - [Theory] [InlineData("")] [InlineData(" ")] @@ -384,44 +326,6 @@ public async Task CreateOrderPaymentAsync_NoOrderIdIsGiven_ArgumentExceptionIsTh exception.Message.Should().Be("Required URL argument 'orderId' is null or empty"); } - [Theory] - [InlineData("")] - [InlineData(" ")] - [InlineData(null)] - public async Task CreateOrderRefundAsync_NoOrderIdIsGiven_ArgumentExceptionIsThrown(string orderId) { - // Arrange - var mockHttp = new MockHttpMessageHandler(); - HttpClient httpClient = mockHttp.ToHttpClient(); - OrderClient orderClient = new OrderClient("api-key", httpClient); - var request = new OrderRefundRequest() - { - Lines = new List() - }; - - // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await orderClient.CreateOrderRefundAsync(orderId, request)); - - // Then - exception.Message.Should().Be("Required URL argument 'orderId' is null or empty"); - } - - [Theory] - [InlineData("")] - [InlineData(" ")] - [InlineData(null)] - public async Task GetOrderRefundListAsync_NoOrderIdIsGiven_ArgumentExceptionIsThrown(string orderId) { - // Arrange - var mockHttp = new MockHttpMessageHandler(); - HttpClient httpClient = mockHttp.ToHttpClient(); - OrderClient orderClient = new OrderClient("api-key", httpClient); - - // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await orderClient.GetOrderRefundListAsync(orderId)); - - // Then - exception.Message.Should().Be("Required URL argument 'orderId' is null or empty"); - } - private OrderRequest CreateOrderRequestWithOnlyRequiredFields() { return new OrderRequest() { Amount = new Amount(Currency.EUR, "100.00"), @@ -451,82 +355,6 @@ private OrderRequest CreateOrderRequestWithOnlyRequiredFields() { }; } - private const string defaultOrderRefundJsonResponse = @"{ - ""resource"": ""refund"", - ""id"": ""re_4qqhO89gsT"", - ""amount"": { - ""currency"": ""EUR"", - ""value"": ""698.00"" - }, - ""status"": ""pending"", - ""createdAt"": ""2018-03-14T17:09:02.0Z"", - ""description"": ""description"", - ""metadata"": { - ""bookkeeping_id"": 12345 - }, - ""paymentId"": ""tr_WDqYK6vllg"", - ""orderId"": ""ord_stTC2WHAuS"", - ""lines"": [ - { - ""resource"": ""orderline"", - ""id"": ""odl_dgtxyl"", - ""orderId"": ""ord_stTC2WHAuS"", - ""name"": ""LEGO 42083 Bugatti Chiron"", - ""sku"": ""5702016116977"", - ""type"": ""physical"", - ""status"": ""paid"", - ""metadata"": null, - ""quantity"": 1, - ""unitPrice"": { - ""value"": ""399.00"", - ""currency"": ""EUR"" - }, - ""vatRate"": ""21.00"", - ""vatAmount"": { - ""value"": ""51.89"", - ""currency"": ""EUR"" - }, - ""discountAmount"": { - ""value"": ""100.00"", - ""currency"": ""EUR"" - }, - ""totalAmount"": { - ""value"": ""299.00"", - ""currency"": ""EUR"" - }, - ""createdAt"": ""2018-08-02T09:29:56+00:00"", - ""_links"": { - ""productUrl"": { - ""href"": ""https://shop.lego.com/nl-NL/Bugatti-Chiron-42083"", - ""type"": ""text/html"" - }, - ""imageUrl"": { - ""href"": ""https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$"", - ""type"": ""text/html"" - } - } - } - ], - ""_links"": { - ""self"": { - ""href"": ""https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT"", - ""type"": ""application/hal+json"" - }, - ""payment"": { - ""href"": ""https://api.mollie.com/v2/payments/tr_WDqYK6vllg"", - ""type"": ""application/hal+json"" - }, - ""order"": { - ""href"": ""https://api.mollie.com/v2/orders/ord_stTC2WHAuS"", - ""type"": ""application/hal+json"" - }, - ""documentation"": { - ""href"": ""https://docs.mollie.com/reference/v2/refunds-api/create-order-refund"", - ""type"": ""text/html"" - } - } -}"; - private const string defaultOrderJsonResponse = @"{ ""resource"": ""order"", ""id"": ""ord_kEn1PlbGa"", diff --git a/tests/Mollie.Tests.Unit/Client/OrganizationsClientTests.cs b/tests/Mollie.Tests.Unit/Client/OrganizationClientTests.cs similarity index 93% rename from tests/Mollie.Tests.Unit/Client/OrganizationsClientTests.cs rename to tests/Mollie.Tests.Unit/Client/OrganizationClientTests.cs index f0b2d35f..861d5b02 100644 --- a/tests/Mollie.Tests.Unit/Client/OrganizationsClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/OrganizationClientTests.cs @@ -8,7 +8,7 @@ namespace Mollie.Tests.Unit.Client; -public class OrganizationsClientTests : BaseClientTests +public class OrganizationClientTests : BaseClientTests { [Fact] public async Task GetCurrentOrganizationAsync_ResponseIsDeserializedInExpectedFormat() @@ -19,7 +19,7 @@ public async Task GetCurrentOrganizationAsync_ResponseIsDeserializedInExpectedFo .With(request => request.Headers.Contains("Idempotency-Key")) .Respond("application/json", defaultOrganizationResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - var organizationsClient = new OrganizationsClient("access_abcde", httpClient); + var organizationsClient = new OrganizationClient("access_abcde", httpClient); // Act var result = await organizationsClient.GetCurrentOrganizationAsync(); @@ -38,7 +38,7 @@ public async Task GetOrganizationAsync_ResponseIsDeserializedInExpectedFormat() .With(request => request.Headers.Contains("Idempotency-Key")) .Respond("application/json", defaultOrganizationResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - var organizationsClient = new OrganizationsClient("access_abcde", httpClient); + var organizationsClient = new OrganizationClient("access_abcde", httpClient); // Act var result = await organizationsClient.GetOrganizationAsync(organizationId); @@ -56,10 +56,10 @@ public async Task GetOrganizationsListAsync_ResponseIsDeserializedInExpectedForm .With(request => request.Headers.Contains("Idempotency-Key")) .Respond("application/json", defaultOrganizationListResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - var organizationsClient = new OrganizationsClient("access_abcde", httpClient); + var organizationsClient = new OrganizationClient("access_abcde", httpClient); // Act - var result = await organizationsClient.GetOrganizationsListAsync(); + var result = await organizationsClient.GetOrganizationListAsync(); // Assert result.Count.Should().Be(2); diff --git a/tests/Mollie.Tests.Unit/Client/PaymentClientTests.cs b/tests/Mollie.Tests.Unit/Client/PaymentClientTests.cs index 8e6232cc..f64ba406 100644 --- a/tests/Mollie.Tests.Unit/Client/PaymentClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/PaymentClientTests.cs @@ -1143,7 +1143,7 @@ public async Task DeletePaymentAsync_TestmodeIsTrue_RequestContainsTestmodeModel PaymentClient paymentClient = new PaymentClient("abcde", httpClient); // When: We send the request - await paymentClient.DeletePaymentAsync(paymentId, true); + await paymentClient.CancelPaymentAsync(paymentId, true); // Then mockHttp.VerifyNoOutstandingExpectation(); @@ -1160,7 +1160,7 @@ public async Task DeletePaymentAsync_NoPaymentIdIsGiven_ArgumentExceptionIsThrow PaymentClient paymentClient = new PaymentClient("abcde", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await paymentClient.DeletePaymentAsync(paymentId)); + var exception = await Assert.ThrowsAsync(async () => await paymentClient.CancelPaymentAsync(paymentId)); // Then exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty"); diff --git a/tests/Mollie.Tests.Unit/Client/PermissionClientTests.cs b/tests/Mollie.Tests.Unit/Client/PermissionClientTests.cs index c4d90094..cd0d322b 100644 --- a/tests/Mollie.Tests.Unit/Client/PermissionClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/PermissionClientTests.cs @@ -20,7 +20,7 @@ public async Task GetPermissionAsync_WithPermissionId_ResponseIsDeserializedInEx .With(request => request.Headers.Contains("Idempotency-Key")) .Respond("application/json", defaultGetPermissionResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - using var permissionClient = new PermissionsClient("access_abcde", httpClient); + using var permissionClient = new PermissionClient("access_abcde", httpClient); // Act var response = await permissionClient.GetPermissionAsync(permissionId); @@ -44,7 +44,7 @@ public async Task GetPermissionAsync_WithoutPermissionId_ThrowsArgumentException // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - using var permissionClient = new PermissionsClient("access_abcde", httpClient); + using var permissionClient = new PermissionClient("access_abcde", httpClient); // Act var exception = await Assert.ThrowsAsync(() => permissionClient.GetPermissionAsync(string.Empty)); @@ -62,7 +62,7 @@ public async Task GetPermissionListAsync_ResponseIsDeserializedInExpectedFormat( .With(request => request.Headers.Contains("Idempotency-Key")) .Respond("application/json", defaultListPermissionsResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - using var permissionClient = new PermissionsClient("access_abcde", httpClient); + using var permissionClient = new PermissionClient("access_abcde", httpClient); // Act var response = await permissionClient.GetPermissionListAsync(); diff --git a/tests/Mollie.Tests.Unit/Client/RefundClientTests.cs b/tests/Mollie.Tests.Unit/Client/RefundClientTests.cs index 268a636c..fb074000 100644 --- a/tests/Mollie.Tests.Unit/Client/RefundClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/RefundClientTests.cs @@ -1,9 +1,12 @@ using System; +using System.Collections.Generic; using Mollie.Api.Client; using System.Net.Http; using System.Threading.Tasks; using FluentAssertions; +using FluentAssertions.Extensions; using Mollie.Api.Models; +using Mollie.Api.Models.Order.Request; using Mollie.Api.Models.Refund.Request; using RichardSzalay.MockHttp; using Xunit; @@ -54,7 +57,7 @@ public async Task GetRefundAsync_TestModeParameterCase_QueryStringOnlyContainsTe RefundClient refundClient = new RefundClient("abcde", httpClient); // When: We send the request - var refundResponse = await refundClient.GetRefundAsync("paymentId", "refundId", testmode: testMode); + var refundResponse = await refundClient.GetPaymentRefundAsync("paymentId", "refundId", testmode: testMode); // Then mockHttp.VerifyNoOutstandingExpectation(); @@ -75,7 +78,7 @@ public async Task CreateRefundAsync_NoPaymentIdIsGiven_ArgumentExceptionIsThrown }; // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await refundClient.CreateRefundAsync(paymentId, refund)); + var exception = await Assert.ThrowsAsync(async () => await refundClient.CreatePaymentRefundAsync(paymentId, refund)); // Then exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty"); @@ -92,7 +95,7 @@ public async Task GetRefundListAsync_NoPaymentIdIsGiven_ArgumentExceptionIsThrow RefundClient refundClient = new RefundClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await refundClient.GetRefundListAsync(paymentId: paymentId)); + var exception = await Assert.ThrowsAsync(async () => await refundClient.GetPaymentRefundListAsync(paymentId: paymentId)); // Then exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty"); @@ -109,7 +112,7 @@ public async Task GetRefundAsync_NoPaymentIdIsGiven_ArgumentExceptionIsThrown(st RefundClient refundClient = new RefundClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await refundClient.GetRefundAsync(paymentId, "refund-id")); + var exception = await Assert.ThrowsAsync(async () => await refundClient.GetPaymentRefundAsync(paymentId, "refund-id")); // Then exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty"); @@ -126,7 +129,7 @@ public async Task GetRefundAsync_NoRefundIsGiven_ArgumentExceptionIsThrown(strin RefundClient refundClient = new RefundClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await refundClient.GetRefundAsync("payment-id", refundId)); + var exception = await Assert.ThrowsAsync(async () => await refundClient.GetPaymentRefundAsync("payment-id", refundId)); // Then exception.Message.Should().Be("Required URL argument 'refundId' is null or empty"); @@ -143,7 +146,7 @@ public async Task CancelRefundAsync_NoPaymentIdIsGiven_ArgumentExceptionIsThrown RefundClient refundClient = new RefundClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await refundClient.CancelRefundAsync(paymentId, "refund-id")); + var exception = await Assert.ThrowsAsync(async () => await refundClient.CancelPaymentRefundAsync(paymentId, "refund-id")); // Then exception.Message.Should().Be("Required URL argument 'paymentId' is null or empty"); @@ -160,10 +163,193 @@ public async Task CancelRefundAsync_NoRefundIsGiven_ArgumentExceptionIsThrown(st RefundClient refundClient = new RefundClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await refundClient.CancelRefundAsync("payment-id", refundId)); + var exception = await Assert.ThrowsAsync(async () => await refundClient.CancelPaymentRefundAsync("payment-id", refundId)); // Then exception.Message.Should().Be("Required URL argument 'refundId' is null or empty"); } + + [Theory] + [InlineData(null, null, false, "")] + [InlineData("from", null, false, "?from=from")] + [InlineData("from", 50, false, "?from=from&limit=50")] + [InlineData(null, null, true, "?testmode=true")] + public async Task GetOrderRefundListAsync_QueryParameterOptions_CorrectParametersAreAdded(string from, int? limit, bool testmode, string expectedQueryString) { + // Given: We make a request to retrieve the list of orders + const string orderId = "abcde"; + var mockHttp = CreateMockHttpMessageHandler(HttpMethod.Get, $"{BaseMollieClient.ApiEndPoint}orders/{orderId}/refunds{expectedQueryString}", defaultOrderJsonResponse); + HttpClient httpClient = mockHttp.ToHttpClient(); + RefundClient refundClient = new RefundClient("api-key", httpClient); + + // When: We send the request + await refundClient.GetOrderRefundListAsync(orderId, from, limit, testmode); + + // Then + mockHttp.VerifyNoOutstandingRequest(); + } + + [Fact] + public async Task CreateOrderRefundAsync_WithRequiredParameters_ResponseIsDeserializedInExpectedFormat() + { + // Given: We create a refund request with only the required parameters + const string orderId = "ord_stTC2WHAuS"; + OrderRefundRequest orderRefundRequest = new OrderRefundRequest() + { + Description = "description", + Lines = new[] + { + new OrderLineDetails() + { + Id = "odl_dgtxyl", + Quantity = 1, + Amount = new Amount(Currency.EUR, "399.00") + } + }, + Metadata = "my-metadata" + }; + string url = $"{BaseMollieClient.ApiEndPoint}orders/{orderId}/refunds"; + var mockHttp = CreateMockHttpMessageHandler(HttpMethod.Post, url, defaultOrderRefundJsonResponse); + HttpClient httpClient = mockHttp.ToHttpClient(); + RefundClient refundClient = new RefundClient("api-key", httpClient); + + // When: We send the request + var response = await refundClient.CreateOrderRefundAsync(orderId, orderRefundRequest); + + // Then + mockHttp.VerifyNoOutstandingExpectation(); + response.Resource.Should().Be("refund"); + response.Id.Should().Be("re_4qqhO89gsT"); + response.Description.Should().Be("description"); + response.Status.Should().Be("pending"); + response.CreatedAt!.Value.ToUniversalTime().Should().Be(DateTime.SpecifyKind(14.March(2018).At(17, 09, 02), DateTimeKind.Utc)); + response.PaymentId.Should().Be("tr_WDqYK6vllg"); + response.OrderId.Should().Be(orderId); + response.Lines.Should().HaveCount(1); + } + + [Theory] + [InlineData("")] + [InlineData(" ")] + [InlineData(null)] + public async Task CreateOrderRefundAsync_NoOrderIdIsGiven_ArgumentExceptionIsThrown(string orderId) { + // Arrange + var mockHttp = new MockHttpMessageHandler(); + HttpClient httpClient = mockHttp.ToHttpClient(); + RefundClient refundClient = new RefundClient("api-key", httpClient); + var request = new OrderRefundRequest() + { + Lines = new List() + }; + + // When: We send the request + var exception = await Assert.ThrowsAsync(async () => await refundClient.CreateOrderRefundAsync(orderId, request)); + + // Then + exception.Message.Should().Be("Required URL argument 'orderId' is null or empty"); + } + + [Theory] + [InlineData("")] + [InlineData(" ")] + [InlineData(null)] + public async Task GetOrderRefundListAsync_NoOrderIdIsGiven_ArgumentExceptionIsThrown(string orderId) { + // Arrange + var mockHttp = new MockHttpMessageHandler(); + HttpClient httpClient = mockHttp.ToHttpClient(); + RefundClient refundClient = new RefundClient("api-key", httpClient); + + // When: We send the request + var exception = await Assert.ThrowsAsync(async () => await refundClient.GetOrderRefundListAsync(orderId)); + + // Then + exception.Message.Should().Be("Required URL argument 'orderId' is null or empty"); + } + + private const string defaultOrderJsonResponse = @"{ + ""resource"": ""order"", + ""id"": ""ord_kEn1PlbGa"", + ""profileId"": ""pfl_URR55HPMGx"", + ""method"": ""ideal"", + ""amount"": { + ""value"": ""1027.99"", + ""currency"": ""EUR"" + }, + }"; + + private const string defaultOrderRefundJsonResponse = @"{ + ""resource"": ""refund"", + ""id"": ""re_4qqhO89gsT"", + ""amount"": { + ""currency"": ""EUR"", + ""value"": ""698.00"" + }, + ""status"": ""pending"", + ""createdAt"": ""2018-03-14T17:09:02.0Z"", + ""description"": ""description"", + ""metadata"": { + ""bookkeeping_id"": 12345 + }, + ""paymentId"": ""tr_WDqYK6vllg"", + ""orderId"": ""ord_stTC2WHAuS"", + ""lines"": [ + { + ""resource"": ""orderline"", + ""id"": ""odl_dgtxyl"", + ""orderId"": ""ord_stTC2WHAuS"", + ""name"": ""LEGO 42083 Bugatti Chiron"", + ""sku"": ""5702016116977"", + ""type"": ""physical"", + ""status"": ""paid"", + ""metadata"": null, + ""quantity"": 1, + ""unitPrice"": { + ""value"": ""399.00"", + ""currency"": ""EUR"" + }, + ""vatRate"": ""21.00"", + ""vatAmount"": { + ""value"": ""51.89"", + ""currency"": ""EUR"" + }, + ""discountAmount"": { + ""value"": ""100.00"", + ""currency"": ""EUR"" + }, + ""totalAmount"": { + ""value"": ""299.00"", + ""currency"": ""EUR"" + }, + ""createdAt"": ""2018-08-02T09:29:56+00:00"", + ""_links"": { + ""productUrl"": { + ""href"": ""https://shop.lego.com/nl-NL/Bugatti-Chiron-42083"", + ""type"": ""text/html"" + }, + ""imageUrl"": { + ""href"": ""https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$"", + ""type"": ""text/html"" + } + } + } + ], + ""_links"": { + ""self"": { + ""href"": ""https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT"", + ""type"": ""application/hal+json"" + }, + ""payment"": { + ""href"": ""https://api.mollie.com/v2/payments/tr_WDqYK6vllg"", + ""type"": ""application/hal+json"" + }, + ""order"": { + ""href"": ""https://api.mollie.com/v2/orders/ord_stTC2WHAuS"", + ""type"": ""application/hal+json"" + }, + ""documentation"": { + ""href"": ""https://docs.mollie.com/reference/v2/refunds-api/create-order-refund"", + ""type"": ""text/html"" + } + } +}"; } } diff --git a/tests/Mollie.Tests.Unit/Client/SettlementClientTests.cs b/tests/Mollie.Tests.Unit/Client/SettlementClientTests.cs index 36629cf6..c0b23b25 100644 --- a/tests/Mollie.Tests.Unit/Client/SettlementClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/SettlementClientTests.cs @@ -18,10 +18,10 @@ public async Task ListSettlementCaptures_DefaultBehaviour_ResponseIsParsed() { string expectedUrl = $"{BaseMollieClient.ApiEndPoint}settlements/{defaultSettlementId}/captures"; var mockHttp = CreateMockHttpMessageHandler(HttpMethod.Get, expectedUrl, defaultCaptureListJsonResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - SettlementsClient settlementsClient = new SettlementsClient("api-key", httpClient); + SettlementClient settlementClient = new SettlementClient("api-key", httpClient); // When: We make the request - ListResponse listCaptureResponse = await settlementsClient.GetSettlementCapturesListAsync(defaultSettlementId); + ListResponse listCaptureResponse = await settlementClient.GetSettlementCaptureListAsync(defaultSettlementId); // Then: Response should be parsed mockHttp.VerifyNoOutstandingExpectation(); @@ -56,10 +56,10 @@ public async Task GetOpenSettlement_DefaultBehaviour_ResponseIsParsed() { string expectedUrl = $"{BaseMollieClient.ApiEndPoint}settlements/open"; var mockHttp = CreateMockHttpMessageHandler(HttpMethod.Get, expectedUrl, defaultGetSettlementResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - SettlementsClient settlementsClient = new SettlementsClient("api-key", httpClient); + SettlementClient settlementClient = new SettlementClient("api-key", httpClient); // When: We make the request - SettlementResponse settlementResponse = await settlementsClient.GetOpenSettlement(); + SettlementResponse settlementResponse = await settlementClient.GetOpenSettlement(); // Then: Response should be parsed mockHttp.VerifyNoOutstandingExpectation(); @@ -123,10 +123,10 @@ public async Task GetOpenSettlement_ResponseWithEmptyPeriods_ResponseIsParsed() string expectedUrl = $"{BaseMollieClient.ApiEndPoint}settlements/open"; var mockHttp = CreateMockHttpMessageHandler(HttpMethod.Get, expectedUrl, emptyPeriodsSettlementResponse); HttpClient httpClient = mockHttp.ToHttpClient(); - SettlementsClient settlementsClient = new SettlementsClient("api-key", httpClient); + SettlementClient settlementClient = new SettlementClient("api-key", httpClient); // When: We make the request - SettlementResponse settlementResponse = await settlementsClient.GetOpenSettlement(); + SettlementResponse settlementResponse = await settlementClient.GetOpenSettlement(); // Then: Response should be parsed mockHttp.VerifyNoOutstandingExpectation(); @@ -142,10 +142,10 @@ public async Task GetSettlementAsync_NoSettlementIdIsGiven_ArgumentExceptionIsTh // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - SettlementsClient settlementsClient = new SettlementsClient("api-key", httpClient); + SettlementClient settlementClient = new SettlementClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await settlementsClient.GetSettlementAsync(settlementId)); + var exception = await Assert.ThrowsAsync(async () => await settlementClient.GetSettlementAsync(settlementId)); // Then exception.Message.Should().Be("Required URL argument 'settlementId' is null or empty"); @@ -159,10 +159,10 @@ public async Task GetSettlementPaymentsListAsync_NoSettlementIdIsGiven_ArgumentE // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - SettlementsClient settlementsClient = new SettlementsClient("api-key", httpClient); + SettlementClient settlementClient = new SettlementClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await settlementsClient.GetSettlementPaymentsListAsync(settlementId)); + var exception = await Assert.ThrowsAsync(async () => await settlementClient.GetSettlementPaymentListAsync(settlementId)); // Then exception.Message.Should().Be("Required URL argument 'settlementId' is null or empty"); @@ -176,10 +176,10 @@ public async Task GetSettlementRefundsListAsync_NoSettlementIdIsGiven_ArgumentEx // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - SettlementsClient settlementsClient = new SettlementsClient("api-key", httpClient); + SettlementClient settlementClient = new SettlementClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await settlementsClient.GetSettlementRefundsListAsync(settlementId)); + var exception = await Assert.ThrowsAsync(async () => await settlementClient.GetSettlementRefundListAsync(settlementId)); // Then exception.Message.Should().Be("Required URL argument 'settlementId' is null or empty"); @@ -193,10 +193,10 @@ public async Task GetSettlementChargebacksListAsync_NoSettlementIdIsGiven_Argume // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - SettlementsClient settlementsClient = new SettlementsClient("api-key", httpClient); + SettlementClient settlementClient = new SettlementClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await settlementsClient.GetSettlementChargebacksListAsync(settlementId)); + var exception = await Assert.ThrowsAsync(async () => await settlementClient.GetSettlementChargebackListAsync(settlementId)); // Then exception.Message.Should().Be("Required URL argument 'settlementId' is null or empty"); @@ -210,10 +210,10 @@ public async Task GetSettlementCapturesListAsync_NoSettlementIdIsGiven_ArgumentE // Arrange var mockHttp = new MockHttpMessageHandler(); HttpClient httpClient = mockHttp.ToHttpClient(); - SettlementsClient settlementsClient = new SettlementsClient("api-key", httpClient); + SettlementClient settlementClient = new SettlementClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await settlementsClient.GetSettlementCapturesListAsync(settlementId)); + var exception = await Assert.ThrowsAsync(async () => await settlementClient.GetSettlementCaptureListAsync(settlementId)); // Then exception.Message.Should().Be("Required URL argument 'settlementId' is null or empty"); diff --git a/tests/Mollie.Tests.Unit/Client/ShipmentClientTests.cs b/tests/Mollie.Tests.Unit/Client/ShipmentClientTests.cs index ba967cae..1790c82f 100644 --- a/tests/Mollie.Tests.Unit/Client/ShipmentClientTests.cs +++ b/tests/Mollie.Tests.Unit/Client/ShipmentClientTests.cs @@ -89,7 +89,7 @@ public async Task GetShipmentsListAsync_TestModeParameterCase_QueryStringOnlyCon ShipmentClient shipmentClient = new ShipmentClient("abcde", httpClient); // When: We send the request - var shipmentListResponse = await shipmentClient.GetShipmentsListAsync(orderId, testModeParameter); + var shipmentListResponse = await shipmentClient.GetShipmentListAsync(orderId, testModeParameter); // Then mockHttp.VerifyNoOutstandingExpectation(); @@ -192,7 +192,7 @@ public async Task GetShipmentsListAsync_NoOrderIdIsGiven_ArgumentExceptionIsThro ShipmentClient shipmentClient = new ShipmentClient("api-key", httpClient); // When: We send the request - var exception = await Assert.ThrowsAsync(async () => await shipmentClient.GetShipmentsListAsync(orderId)); + var exception = await Assert.ThrowsAsync(async () => await shipmentClient.GetShipmentListAsync(orderId)); // Then exception.Message.Should().Be("Required URL argument 'orderId' is null or empty");