Skip to content

Commit

Permalink
added 'madeInUkraine' account type
Browse files Browse the repository at this point in the history
  • Loading branch information
maisak committed Jan 5, 2025
1 parent 011fb92 commit 358b24e
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/Monobank.Core/Models/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Monobank.Core.Models
public class Account
{
[JsonPropertyName("id")]
public string Id { get; set; }
public string Id { get; set; } = string.Empty;

[JsonPropertyName("balance")]
public long Balance { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion src/Monobank.Core/Models/Consts/AccountTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public enum AccountTypes
Yellow = 6,

[EnumMember(Value = "eAid")]
EAid = 7
EAid = 7,

[EnumMember(Value = "madeInUkraine")]
MadeInUkraine = 8
}
}
4 changes: 2 additions & 2 deletions src/Monobank.Core/Models/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Monobank.Core.Models
{
public class Error
{
[JsonPropertyName("errorDescription")]
public string Description { get; set; }
[JsonPropertyName("errorDescription")]
public string Description { get; set; } = string.Empty;
}
}
12 changes: 6 additions & 6 deletions src/Monobank.Core/Models/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace Monobank.Core.Models
public class Statement
{
[JsonPropertyName("id")]
public string Id { get; set; }
public string Id { get; set; } = string.Empty;

[JsonPropertyName("time")]
public long TimeInSeconds { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }
public string Description { get; set; } = string.Empty;

[JsonPropertyName("mcc")]
public int MerchantCategoryCode { get; set; }
Expand All @@ -41,16 +41,16 @@ public class Statement
public long Balance { get; set; }

[JsonPropertyName("comment")]
public string Comment { get; set; }
public string Comment { get; set; } = string.Empty;

[JsonPropertyName("receiptId")]
public string ReceiptId { get; set; }
public string ReceiptId { get; set; } = string.Empty;

[JsonPropertyName("counterEdrpou")]
public string CounterEdrpou { get; set; }
public string CounterEdrpou { get; set; } = string.Empty;

[JsonPropertyName("counterIban")]
public string CounterIban { get; set; }
public string CounterIban { get; set; } = string.Empty;

#region Custom properties

Expand Down
18 changes: 9 additions & 9 deletions src/Monobank.Core/Models/UserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace Monobank.Core.Models
{
public class UserInfo
{
[JsonPropertyName("clientId")]
public string Id { get; set; }
[JsonPropertyName("clientId")]
public string Id { get; set; } = string.Empty;

[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;

[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("webHookUrl")]
public string? WebHookUrl { get; set; }

[JsonPropertyName("webHookUrl")]
public string WebHookUrl { get; set; }

[JsonPropertyName("accounts")]
public ICollection<Account> Accounts { get; set; }
[JsonPropertyName("accounts")]
public ICollection<Account> Accounts { get; set; } = [];
}
}
12 changes: 7 additions & 5 deletions src/Monobank.Core/Models/WebHookModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ namespace Monobank.Core.Models
public class WebHookModel
{
[JsonPropertyName("type")]
public string Type { get; set; }
[JsonPropertyName("data")]
public WebHookData Data { get; set; }
public string Type { get; set; } = string.Empty;

[JsonPropertyName("data")]
public WebHookData Data { get; set; } = null!;
}

public class WebHookData
{
[JsonPropertyName("account")]
public string Account { get; set; }
public string Account { get; set; } = string.Empty;

[JsonPropertyName("statementItem")]
public Statement StatementItem { get; set; }
public Statement StatementItem { get; set; } = null!;
}
}
9 changes: 6 additions & 3 deletions src/Monobank.Core/Monobank.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<PackageId>Monobank.API.Core</PackageId>
<PackageTags>API monobank net-standard-2</PackageTags>
<Authors>Anthony Maisak</Authors>
<Company>Anthony Maisak</Company>
<Description>Monobank.ua API wrapper</Description>
<Copyright>Copyright 2024</Copyright>
<Copyright>Copyright 2025</Copyright>
<PackageProjectUrl>https://github.com/maisak/monobank-api</PackageProjectUrl>
<RepositoryUrl>https://github.com/maisak/monobank-api</RepositoryUrl>
<PackageIcon>logo.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryType>Git</RepositoryType>
<PackageReleaseNotes>Updated code to reflect API changes.</PackageReleaseNotes>
<PackageVersion>1.2</PackageVersion>
<PackageVersion>1.3</PackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ISO.4217.CurrencyCodes" Version="1.0.10" />
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 6 additions & 5 deletions src/Monobank.Core/Services/ClientService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ public ClientService(HttpClient client, string token)
_httpClient.DefaultRequestHeaders.Add(TokenHeader, token);
}

public async Task<UserInfo> GetClientInfoAsync()
public async Task<UserInfo?> GetClientInfoAsync()
{
var uri = new Uri(ClientInfoEndpoint, UriKind.Relative);
var response = await _httpClient.GetAsync(uri);
var responseString = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
var error = JsonSerializer.Deserialize<Error>(responseString);
throw new Exception(error.Description);
throw new Exception(error!.Description);
}

return JsonSerializer.Deserialize<UserInfo>(responseString);
}

Expand All @@ -56,16 +57,16 @@ public async Task<ICollection<Statement>> GetStatementsAsync(DateTime from, Date
if (!response.IsSuccessStatusCode)
{
var error = JsonSerializer.Deserialize<Error>(responseString);
throw new Exception(error.Description);
throw new Exception(error!.Description);
}
_previousRequestTimestamp = DateTime.UtcNow;
return JsonSerializer.Deserialize<ICollection<Statement>>(responseString);
return JsonSerializer.Deserialize<ICollection<Statement>>(responseString) ?? [];
}

public async Task<bool> SetWebhookAsync(string url)
{
// create body containing webhook url
var body = JsonSerializer.Serialize(new {webHookUrl = url});
var body = JsonSerializer.Serialize(new { webHookUrl = url });
// uri to call
var uri = new Uri(WebhookEndpoint, UriKind.Relative);
// set webhook
Expand Down
14 changes: 4 additions & 10 deletions src/Monobank.Core/Services/CurrencyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@

namespace Monobank.Core.Services
{
public class CurrencyService
public class CurrencyService(HttpClient client)
{
private const string CurrencyEndpoint = "bank/currency";
private readonly HttpClient _httpClient;

public CurrencyService(HttpClient client)
{
_httpClient = client;
}

public async Task<ICollection<CurrencyInfo>> GetCurrencies()
{
var uri = new Uri($"{CurrencyEndpoint}", UriKind.Relative);
var response = await _httpClient.GetAsync(uri);
var response = await client.GetAsync(uri);
var responseString = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
var error = JsonSerializer.Deserialize<Error>(responseString);
throw new Exception(error.Description);
throw new Exception(error!.Description);
}

return JsonSerializer.Deserialize<ICollection<CurrencyInfo>>(responseString);
return JsonSerializer.Deserialize<ICollection<CurrencyInfo>>(responseString) ?? [];
}
}
}
12 changes: 6 additions & 6 deletions src/Monobank.Tests/Monobank.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="nunit" Version="4.2.2" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="nunit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/MonobankClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monobank.Core", "Monobank.C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Monobank.Tests", "Monobank.Tests\Monobank.Tests.csproj", "{163928F8-82AB-47C1-B794-99FD516704AE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution items", "Solution items", "{C382ABF6-3EFD-4C3A-84D4-A2A9DABD6E3E}"
ProjectSection(SolutionItems) = preProject
..\.gitignore = ..\.gitignore
..\README.md = ..\README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down

0 comments on commit 358b24e

Please sign in to comment.