Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.3 version update #2

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,7 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Exclude unit test Runsettings
*.runsettings
.vscode/*
87 changes: 60 additions & 27 deletions Privatbank.Business.Tests/PrivatBankAutoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,107 @@ public class Tests
public void SetUp()
{
_client = new PrivatbankAutoClient(
Environment.GetEnvironmentVariable("CLIENT_ID"),
Environment.GetEnvironmentVariable("CLIENT_TOKEN"));
}

[Test]
public async Task TestStatementsSettings()
{
var result = await _client.GetStatementsSettingsAsync();

Assert.IsNotEmpty(result.Phase);
Assert.IsNotEmpty(result.NonOperationalDays);
Assert.AreNotEqual(result.PreviousOperationalDay, DateTime.MinValue);
Assert.AreNotEqual(result.CurrentOperationalDay, DateTime.MinValue);
Assert.AreNotEqual(result.ServerDateTime, DateTime.MinValue);
Assert.AreNotEqual(result.DateTimeOfFinalStatement, DateTime.MinValue);
}
#region Balance

[Test]
public async Task TestGetBalance()
{
public async Task TestGetBalance() {
var result = await _client.GetBalanceAsync(DateTime.Now);

Assert.IsNotEmpty(result);
}

[Test]
public async Task TestGetBalanceInterim()
{
public async Task TestGetBalanceInterim() {
var result = await _client.GetBalanceInterimAsync();

Assert.IsNotEmpty(result);
}


[Test]
public async Task TestGetBalanceFinal()
{
public async Task TestGetBalanceFinal() {
var result = await _client.GetBalanceFinalAsync();

Assert.IsNotEmpty(result);
}
#endregion

[Test]
public async Task TestStatementsSettings()
{
var result = await _client.GetStatementsSettingsAsync();

Assert.IsNotEmpty(result.Phase);
Assert.IsNotEmpty(result.NonOperationalDays);
Assert.AreNotEqual(result.PreviousOperationalDay, DateTime.MinValue);
Assert.AreNotEqual(result.CurrentOperationalDay, DateTime.MinValue);
Assert.AreNotEqual(result.ServerDateTime, DateTime.MinValue);
Assert.AreNotEqual(result.DateTimeOfFinalStatement, DateTime.MinValue);
}

#region Transactions
[Test]
public async Task TestGetTransactions()
{
public async Task TestGetTransactions() {
var result = await _client.GetTransactionsAsync(
DateTime.Now - TimeSpan.FromDays(30));

Assert.IsNotEmpty(result);
}

[Test]
public async Task TestGetTransactionsInterim()
{
public async Task TestGetTransactionsInterim() {
var result = await _client.GetTransactionsInterimAsync();

Assert.IsNotEmpty(result);
}

[Test]
public async Task TestGetTransactionsFinal()
{
public async Task TestGetTransactionsFinal() {
var result = await _client.GetTransactionsFinalAsync();

Assert.NotNull(result);
}
#endregion
[Test]
public async Task TestGetRecipientsAsync() {
var recipeints = await _client.GetRecipientsAsync(Data.Enums.SalaryProjects.GroupType.SALARY);
Assert.NotNull(recipeints);
}

[Test]
public async Task TestGetGroups() {
var result = await _client.GetGroupsAsync();
if (result.Count != 0) {
Assert.IsTrue(result[0].comission_rate >= 0);
Assert.IsTrue(result[0].comission_rate < 1);
}
Assert.NotNull(result);
}

[Test]
public async Task TestGetPackets() {
var result = await _client.GetPacketsAsync(new DateTime(2022, 1, 1), new DateTime(2023, 1, 1));
if (result.Count != 0) {
Assert.IsTrue(result[0].amount >= 0);
}
Assert.NotNull(result);
}
[Test]
public async Task TestGetPacketElements() {
var packets = await _client.GetPacketsAsync(new DateTime(2022, 1, 1), new DateTime(2023, 1, 1));
if (packets.Count == 0) {
return;
}
var elements = await _client.GetPacketEntriesAsync(packets[0]);
if (elements.Count > 0) {
Assert.IsTrue(elements[0].amount > 0);
}
Assert.NotNull(elements);
}

/*[Test]
public async Task TestCreatePayment()
{
var result = await _client.CreatePaymentAsync(new Payment
Expand All @@ -97,7 +130,7 @@ public async Task TestCreatePayment()

Assert.NotNull(result.Reference);
Assert.NotNull(result.PackedReference);
}
}*/

[TearDown]
public void TearDown()
Expand Down
2 changes: 1 addition & 1 deletion Privatbank.Business.Tests/Privatbank.Business.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
8 changes: 8 additions & 0 deletions Privatbank.Business.Tests/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Privatbank.Business.Tests": {
"commandName": "Project",
"nativeDebugging": true
}
}
}
10 changes: 10 additions & 0 deletions Privatbank.Business.Tests/example env var.runsettings.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- configuration elements -->
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<!-- List of environment variables we want to set-->
<CLIENT_TOKEN>your_client_token</CLIENT_TOKEN>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
20 changes: 20 additions & 0 deletions Privatbank.Business/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Privat.Buisness changelog
## plan for 1.0.3
add another enum in older models like
- `Transaction.Type`
- `Transaction.DocumentType`
- `Transaction.Status`
- `Transaction.Real`

## 1.0.2 - salary groups, api 3-0-0
added support for client with token only

added salary groups:
- get salary groups `GetGroupsAsync()`
- get salary groups recipients `GetRecipientsAsync(GroupType type)`
- get packets `GetPacketsAsync(DateTime from, DateTime to)`
- get packet elements `GetPacketEntriesAsync(Packet packet)`

salary groups use enums
## 1.0.2 - transactions
functionality for transactions statements and balances
12 changes: 4 additions & 8 deletions Privatbank.Business/Converters/StringDateTimeArrayConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Privatbank.Business.Converters
{
internal class StringDateTimeArrayConverter : JsonConverter<DateTime[]>
{
public override DateTime[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
namespace Privatbank.Business.Converters {
internal class StringDateTimeArrayConverter : JsonConverter<DateTime[]> {
public override DateTime[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
var resultList = new List<DateTime>();

if (reader.TokenType == JsonTokenType.StartArray)
Expand All @@ -25,8 +22,7 @@ public override DateTime[] Read(ref Utf8JsonReader reader, Type typeToConvert, J
return resultList.ToArray();
}

public override void Write(Utf8JsonWriter writer, DateTime[] value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, DateTime[] value, JsonSerializerOptions options) {
throw new NotImplementedException();
}
}
Expand Down
14 changes: 5 additions & 9 deletions Privatbank.Business/Converters/StringDateTimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Privatbank.Business.Converters
{
internal class StringDateTimeConverter : JsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
namespace Privatbank.Business.Converters {
internal class StringDateTimeConverter : JsonConverter<DateTime> {
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
string[] formats =
{
"yyyy-MM-dd'T'HH:mm:ss.fffzzz",
"dd.MM.yyyy HH:mm:ss",
"dd-MM-yyyy HH:mm:ss",
"dd-MM-yyyy",
"dd.MM.yyyy",
"HH:mm"
};

return DateTime.TryParseExact(
reader.GetString(),
formats,
Expand All @@ -27,8 +24,7 @@ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
: DateTime.MinValue;
}

public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) {
writer.WriteStringValue(
value.ToString("dd.MM.yyyy"));
}
Expand Down
15 changes: 6 additions & 9 deletions Privatbank.Business/Converters/StringDecimalConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Privatbank.Business.Converters
{
internal class StringDecimalConverter : JsonConverter<decimal>
{
public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return decimal.Parse(reader.GetString());
namespace Privatbank.Business.Converters {
internal class StringDecimalConverter : JsonConverter<decimal> {
static private NumberFormatInfo formatInfo = new NumberFormatInfo() { NumberDecimalSeparator = "." };
public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
return decimal.Parse(reader.GetString(), formatInfo);
}

public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options) {
writer.WriteStringValue(
value.ToString(CultureInfo.InvariantCulture));
}
Expand Down
12 changes: 4 additions & 8 deletions Privatbank.Business/Converters/StringYesNoConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Privatbank.Business.Converters
{
internal class StringYesNoConverter : JsonConverter<bool>
{
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
namespace Privatbank.Business.Converters {
internal class StringYesNoConverter : JsonConverter<bool> {
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
var result = reader.GetString();

return result.Equals("yes", StringComparison.InvariantCultureIgnoreCase) ||
result.Equals("y", StringComparison.InvariantCultureIgnoreCase);
}

public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) {
throw new NotImplementedException();
}
}
Expand Down
30 changes: 30 additions & 0 deletions Privatbank.Business/Data/Enums/SalaryProjects/GroupType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Text.Json.Serialization;

namespace Privatbank.Business.Data.Enums.SalaryProjects {
/// <summary>
/// group salary type
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverterWithAttributeSupport))]
public enum GroupType {
/// <summary>
/// project type
/// </summary>
MASSPAYMENTS,
/// <summary>
/// other salary projects
/// </summary>
SALARY,
/// <summary>
/// project type
/// </summary>
STUDENT,
/// <summary>
/// project type
/// </summary>
HESED,
/// <summary>
/// use this ALL for request about salary group members
/// </summary>
ALL,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Privatbank.Business.Data.Models.SalaryProjects;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace Privatbank.Business.Data.Enums.SalaryProjects {
/// <summary>
/// salary packet element status <see cref="PacketEntrie"/>
/// N Запис ще не перевірявся
/// N$ У записі є помилка, яку можна виправити у веб інтерфейсі Приват24 для бізнесу(наприклад 0 сума)
/// R Успішно перевірена
/// M Успішно сплачено
/// E Забракована
/// * Все останнє можна вважати помилками, на які не можливо повпливати
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverterWithAttributeSupport))]
public enum Packet_Element_Status {
/// <summary>
/// N Запис ще не перевірявся
/// </summary>
[EnumMember(Value = "N")]
Not_reviewed,
/// <summary>
/// can be fixed in interface
/// </summary>
[EnumMember(Value = "N$")]
Can_be_fixed,
/// <summary>
/// successfully reviewed and accepted, awaits payment
/// </summary>
[EnumMember(Value = "R")]
Reviewed,
/// <summary>
/// paid
/// </summary>
[EnumMember(Value = "M")]
Successfully_paid,
/// <summary>
/// rejectd
/// </summary>
[EnumMember(Value = "E")]
Rejected,
/// <summary>
/// all after unfixable
/// </summary>
[EnumMember(Value = "*")]
All_bad,
}
}
Loading