Skip to content

Commit

Permalink
Remove "this." from codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed May 12, 2024
1 parent 4afb810 commit ca02113
Show file tree
Hide file tree
Showing 79 changed files with 1,065 additions and 1,065 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using System.ComponentModel.DataAnnotations;
using System.Reflection;

namespace Mollie.WebApplication.Blazor.Framework.Validators;
namespace Mollie.WebApplication.Blazor.Framework.Validators;

public class StaticStringListAttribute : ValidationAttribute {
private readonly Type _staticClass;

public StaticStringListAttribute(Type staticClass) {
this._staticClass = staticClass;
_staticClass = staticClass;
}

protected override ValidationResult IsValid(object value, ValidationContext validationContext) {
IEnumerable<string> validValues = this._staticClass
IEnumerable<string> validValues = _staticClass
.GetFields(BindingFlags.Static | BindingFlags.Public)
.Select(x => x.GetValue(null).ToString());

if (validValues.Contains(value)) {
return ValidationResult.Success;
}

return new ValidationResult($"The value \"{value}\" is invalid");
}
}
42 changes: 21 additions & 21 deletions src/Mollie.Api/Client/BalanceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,49 @@ namespace Mollie.Api.Client {
public class BalanceClient : BaseMollieClient, IBalanceClient {
public BalanceClient(string apiKey, HttpClient? httpClient = null) : base(apiKey, httpClient) {
}

public async Task<BalanceResponse> GetBalanceAsync(string balanceId) {
this.ValidateRequiredUrlParameter(nameof(balanceId), balanceId);
return await this.GetAsync<BalanceResponse>($"balances/{balanceId}").ConfigureAwait(false);
ValidateRequiredUrlParameter(nameof(balanceId), balanceId);
return await GetAsync<BalanceResponse>($"balances/{balanceId}").ConfigureAwait(false);
}

public async Task<BalanceResponse> GetBalanceAsync(UrlObjectLink<BalanceResponse> url) {
return await this.GetAsync(url).ConfigureAwait(false);
return await GetAsync(url).ConfigureAwait(false);
}

public async Task<BalanceResponse> GetPrimaryBalanceAsync() {
return await this.GetAsync<BalanceResponse>("balances/primary").ConfigureAwait(false);
return await GetAsync<BalanceResponse>("balances/primary").ConfigureAwait(false);
}

public async Task<ListResponse<BalanceResponse>> ListBalancesAsync(string? from = null, int? limit = null, string? currency = null) {
var queryParameters = BuildListBalanceQueryParameters(currency);
return await this.GetListAsync<ListResponse<BalanceResponse>>($"balances", from, limit, queryParameters).ConfigureAwait(false);
return await GetListAsync<ListResponse<BalanceResponse>>($"balances", from, limit, queryParameters).ConfigureAwait(false);
}

public async Task<ListResponse<BalanceResponse>> ListBalancesAsync(UrlObjectLink<ListResponse<BalanceResponse>> url) {
return await this.GetAsync(url).ConfigureAwait(false);
return await GetAsync(url).ConfigureAwait(false);
}

public async Task<BalanceReportResponse> GetBalanceReportAsync(string balanceId, DateTime from, DateTime until, string? grouping = null) {
this.ValidateRequiredUrlParameter(nameof(balanceId), balanceId);
ValidateRequiredUrlParameter(nameof(balanceId), balanceId);
var queryParameters = BuildGetBalanceReportQueryParameters(from, until, grouping);
return await this.GetAsync<BalanceReportResponse>($"balances/{balanceId}/report{queryParameters.ToQueryString()}").ConfigureAwait(false);
return await GetAsync<BalanceReportResponse>($"balances/{balanceId}/report{queryParameters.ToQueryString()}").ConfigureAwait(false);
}

public async Task<BalanceReportResponse> GetPrimaryBalanceReportAsync(DateTime from, DateTime until, string? grouping = null) {
var queryParameters = BuildGetBalanceReportQueryParameters(from, until, grouping);
return await this.GetAsync<BalanceReportResponse>($"balances/primary/report{queryParameters.ToQueryString()}").ConfigureAwait(false);
return await GetAsync<BalanceReportResponse>($"balances/primary/report{queryParameters.ToQueryString()}").ConfigureAwait(false);
}

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

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

private Dictionary<string, string> BuildListBalanceTransactionsQueryParameters(string? from, int? limit) {
Expand All @@ -74,11 +74,11 @@ private Dictionary<string, string> BuildGetBalanceReportQueryParameters(DateTime
result.AddValueIfNotNullOrEmpty("grouping", grouping);
return result;
}

private Dictionary<string, string> BuildListBalanceQueryParameters(string? currency) {
var result = new Dictionary<string, string>();
result.AddValueIfNotNullOrEmpty("currency", currency);
return result;
}
}
}
}
6 changes: 3 additions & 3 deletions src/Mollie.Api/Client/BaseMollieClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IDisposable WithIdempotencyKey(string value) {
}

private async Task<T> SendHttpRequest<T>(HttpMethod httpMethod, string relativeUri, object? data = null) {
HttpRequestMessage httpRequest = this.CreateHttpRequest(httpMethod, relativeUri);
HttpRequestMessage httpRequest = CreateHttpRequest(httpMethod, relativeUri);
if (data != null) {
var jsonData = _jsonConverterService.Serialize(data);
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
Expand All @@ -60,7 +60,7 @@ private async Task<T> SendHttpRequest<T>(HttpMethod httpMethod, string relativeU
}

protected async Task<T> GetListAsync<T>(string relativeUri, string? from, int? limit, IDictionary<string, string>? otherParameters = null) {
string url = relativeUri + this.BuildListQueryString(from, limit, otherParameters);
string url = relativeUri + BuildListQueryString(from, limit, otherParameters);
return await SendHttpRequest<T>(HttpMethod.Get, url).ConfigureAwait(false);
}

Expand Down Expand Up @@ -135,7 +135,7 @@ protected virtual HttpRequestMessage CreateHttpRequest(HttpMethod method, string
HttpRequestMessage httpRequest = new HttpRequestMessage(method, new Uri(new Uri(_apiEndpoint), relativeUri));
httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
httpRequest.Headers.Add("User-Agent", this.GetUserAgent());
httpRequest.Headers.Add("User-Agent", GetUserAgent());
var idemPotencyKey = _idempotencyKey.Value ?? Guid.NewGuid().ToString();
httpRequest.Headers.Add("Idempotency-Key", idemPotencyKey);
httpRequest.Content = content;
Expand Down
26 changes: 13 additions & 13 deletions src/Mollie.Api/Client/CaptureClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@ public CaptureClient(string apiKey, HttpClient? httpClient = null) : base(apiKey
}

public async Task<CaptureResponse> GetCaptureAsync(string paymentId, string captureId, bool testmode = false) {
this.ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
this.ValidateRequiredUrlParameter(nameof(captureId), captureId);
ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
ValidateRequiredUrlParameter(nameof(captureId), captureId);
var queryParameters = BuildQueryParameters(testmode);
return await this.GetAsync<CaptureResponse>($"payments/{paymentId}/captures/{captureId}{queryParameters.ToQueryString()}")
return await GetAsync<CaptureResponse>($"payments/{paymentId}/captures/{captureId}{queryParameters.ToQueryString()}")
.ConfigureAwait(false);
}

public async Task<CaptureResponse> GetCaptureAsync(UrlObjectLink<CaptureResponse> url) {
return await this.GetAsync(url).ConfigureAwait(false);
return await GetAsync(url).ConfigureAwait(false);
}

public async Task<ListResponse<CaptureResponse>> GetCapturesListAsync(string paymentId, bool testmode = false) {
this.ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
var queryParameters = BuildQueryParameters(testmode);
return await this.GetAsync<ListResponse<CaptureResponse>>($"payments/{paymentId}/captures{queryParameters.ToQueryString()}")
return await GetAsync<ListResponse<CaptureResponse>>($"payments/{paymentId}/captures{queryParameters.ToQueryString()}")
.ConfigureAwait(false);
}

public async Task<ListResponse<CaptureResponse>> GetCapturesListAsync(UrlObjectLink<ListResponse<CaptureResponse>> url) {
return await this.GetAsync(url).ConfigureAwait(false);
return await GetAsync(url).ConfigureAwait(false);
}

public async Task<CaptureResponse> CreateCapture(string paymentId, CaptureRequest captureRequest, bool testmode = false) {
this.ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
var queryParameters = BuildQueryParameters(testmode);
return await this.PostAsync<CaptureResponse>($"payments/{paymentId}/captures{queryParameters.ToQueryString()}", captureRequest)
return await PostAsync<CaptureResponse>($"payments/{paymentId}/captures{queryParameters.ToQueryString()}", captureRequest)
.ConfigureAwait(false);
}

private Dictionary<string, string> BuildQueryParameters(bool testmode) {
var result = new Dictionary<string, string>();
result.AddValueIfTrue("testmode", testmode);
return result;
}
}
}
}
26 changes: 13 additions & 13 deletions src/Mollie.Api/Client/ChargebacksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ public ChargebacksClient(string apiKey, HttpClient? httpClient = null) : base(ap
}

public async Task<ChargebackResponse> GetChargebackAsync(string paymentId, string chargebackId, bool testmode = false) {
this.ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
this.ValidateRequiredUrlParameter(nameof(chargebackId), chargebackId);
var queryParameters = this.BuildQueryParameters(testmode);
return await this.GetAsync<ChargebackResponse>($"payments/{paymentId}/chargebacks/{chargebackId}{queryParameters.ToQueryString()}")
ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
ValidateRequiredUrlParameter(nameof(chargebackId), chargebackId);
var queryParameters = BuildQueryParameters(testmode);
return await GetAsync<ChargebackResponse>($"payments/{paymentId}/chargebacks/{chargebackId}{queryParameters.ToQueryString()}")
.ConfigureAwait(false);
}

public async Task<ListResponse<ChargebackResponse>> GetChargebacksListAsync(string paymentId, string? from = null, int? limit = null, bool testmode = false) {
this.ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
var queryParameters = this.BuildQueryParameters(testmode);
ValidateRequiredUrlParameter(nameof(paymentId), paymentId);
var queryParameters = BuildQueryParameters(testmode);
return await this
.GetListAsync<ListResponse<ChargebackResponse>>($"payments/{paymentId}/chargebacks", from, limit, queryParameters)
.ConfigureAwait(false);
}

public async Task<ListResponse<ChargebackResponse>> GetChargebacksListAsync(string? profileId = null, bool testmode = false) {
var queryParameters = this.BuildQueryParameters(profileId, testmode);
return await this.GetListAsync<ListResponse<ChargebackResponse>>($"chargebacks", null, null, queryParameters).ConfigureAwait(false);
var queryParameters = BuildQueryParameters(profileId, testmode);
return await GetListAsync<ListResponse<ChargebackResponse>>($"chargebacks", null, null, queryParameters).ConfigureAwait(false);
}

public async Task<ListResponse<ChargebackResponse>> GetChargebacksListAsync(UrlObjectLink<ListResponse<ChargebackResponse>> url) {
return await this.GetAsync(url).ConfigureAwait(false);
return await GetAsync(url).ConfigureAwait(false);
}

private Dictionary<string, string> BuildQueryParameters(string? profileId, bool testmode) {
var result = new Dictionary<string, string>();
result.AddValueIfNotNullOrEmpty(nameof(profileId), profileId);
result.AddValueIfTrue(nameof(testmode), testmode);
return result;
}

private Dictionary<string, string> BuildQueryParameters(bool testmode) {
var result = new Dictionary<string, string>();
result.AddValueIfTrue(nameof(testmode), testmode);
return result;
}
}
}
}
8 changes: 4 additions & 4 deletions src/Mollie.Api/Client/ClientLinkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ public class ClientLinkClient : OauthBaseMollieClient, IClientLinkClient
public ClientLinkClient(string clientId, string oauthAccessToken, HttpClient? httpClient = null)
: base(oauthAccessToken, httpClient)
{
this._clientId = clientId;
_clientId = clientId;
}

public async Task<ClientLinkResponse> CreateClientLinkAsync(ClientLinkRequest request)
{
return await this.PostAsync<ClientLinkResponse>($"client-links", request)
return await PostAsync<ClientLinkResponse>($"client-links", request)
.ConfigureAwait(false);
}

public string GenerateClientLinkWithParameters(
string clientLinkUrl,
string state,
List<string> scopes,
List<string> scopes,
bool forceApprovalPrompt = false)
{
var parameters = new Dictionary<string, string> {
Expand All @@ -39,4 +39,4 @@ public string GenerateClientLinkWithParameters(
return clientLinkUrl + parameters.ToQueryString();
}
}
}
}
30 changes: 15 additions & 15 deletions src/Mollie.Api/Client/ConnectClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Mollie.Api.Client {
public class ConnectClient : BaseMollieClient, IConnectClient {
private const string AuthorizeEndPoint = "https://www.mollie.com/oauth2/authorize";
private const string TokenEndPoint = "https://api.mollie.nl/oauth2/";

private readonly string _clientId;
private readonly string _clientSecret;

Expand All @@ -24,21 +24,21 @@ public ConnectClient(string clientId, string clientSecret, HttpClient? httpClien
if (string.IsNullOrWhiteSpace(clientSecret)) {
throw new ArgumentNullException(nameof(clientSecret));
}
this._clientSecret = clientSecret;
this._clientId = clientId;

_clientSecret = clientSecret;
_clientId = clientId;
}

public string GetAuthorizationUrl(
string state,
List<string> scopes,
string? redirectUri = null,
bool forceApprovalPrompt = false,
string? locale = null,
string state,
List<string> scopes,
string? redirectUri = null,
bool forceApprovalPrompt = false,
string? locale = null,
string? landingPage = null) {

var parameters = new Dictionary<string, string> {
{"client_id", this._clientId},
{"client_id", _clientId},
{"state", state},
{"scope", string.Join(" ", scopes)},
{"response_type", "code"},
Expand All @@ -52,17 +52,17 @@ public string GetAuthorizationUrl(
}

public async Task<TokenResponse> GetAccessTokenAsync(TokenRequest request) {
return await this.PostAsync<TokenResponse>("tokens", request).ConfigureAwait(false);
return await PostAsync<TokenResponse>("tokens", request).ConfigureAwait(false);
}

public async Task RevokeTokenAsync(RevokeTokenRequest request) {
await this.DeleteAsync("tokens", request).ConfigureAwait(false);
await DeleteAsync("tokens", request).ConfigureAwait(false);
}

protected override HttpRequestMessage CreateHttpRequest(HttpMethod method, string relativeUri, HttpContent? content = null) {
HttpRequestMessage httpRequest = new HttpRequestMessage(method, new Uri(new Uri(ConnectClient.TokenEndPoint), relativeUri));
httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic", this.Base64Encode($"{this._clientId}:{this._clientSecret}"));
httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic", Base64Encode($"{_clientId}:{_clientSecret}"));
httpRequest.Content = content;

return httpRequest;
Expand All @@ -73,4 +73,4 @@ private string Base64Encode(string value) {
return Convert.ToBase64String(bytes);
}
}
}
}
Loading

0 comments on commit ca02113

Please sign in to comment.