Skip to content
Merged
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
68 changes: 68 additions & 0 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: .NET CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
name: Build and test
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'

- name: Restore dependencies
run: dotnet restore MAES.Fiskal.Tests/MAES.Fiskal.Tests.csproj

- name: Run tests
run: dotnet test MAES.Fiskal.Tests/MAES.Fiskal.Tests.csproj --configuration Release --no-restore

pack-and-publish:
name: Pack and publish package
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'

- name: Restore dependencies
run: dotnet restore MAES.Fiskal/MAES.Fiskal.csproj

- name: Determine package version
id: version
run: |
VERSION_PREFIX=$(grep -oPm1 "(?<=<Version>)[^<]+" MAES.Fiskal/MAES.Fiskal.csproj)
PACKAGE_VERSION="${VERSION_PREFIX%.*}.${GITHUB_RUN_NUMBER}"
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo "Pack version: $PACKAGE_VERSION"

- name: Pack library
run: dotnet pack MAES.Fiskal/MAES.Fiskal.csproj --configuration Release --output ./artifacts --no-restore /p:PackageVersion=${{ env.PACKAGE_VERSION }}

- name: Publish package to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
run: |
dotnet nuget push "./artifacts/*.nupkg" \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,5 @@ $RECYCLE.BIN/

# Vim temporary swap files
*.swp

*.p12
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Tests",
"type": "coreclr",
"program": "${workspaceFolder}/MAES.Fiskal.Tests/bin/Debug/net10.0/MAES.Fiskal.Tests.dll",
"request": "launch",
"preLaunchTask": "Test",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Example",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build Example",
"program": "${workspaceFolder}/MAES.Fiskal.Example/bin/Debug/net10.0/MAES.Fiskal.Example.exe",
"cwd": "${workspaceFolder}/MAES.Fiskal.Example",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
40 changes: 40 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,46 @@
],
"dependsOn": "Pack",
"problemMatcher": []
},
{
"label": "Test",
"type": "shell",
"command": "dotnet",
"args": [
"test",
"${workspaceFolder}/MAES.Fiskal.Tests",
"--verbosity",
"normal"
],
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": "$msCompile"
},
{
"label": "Build Example",
"type": "shell",
"command": "dotnet",
"args": [
"build",
"${workspaceFolder}/MAES.Fiskal.Example",
"--configuration",
"Debug"
],
"problemMatcher": "$msCompile"
},
{
"label": "Run Example",
"type": "shell",
"command": "dotnet",
"args": [
"run",
"--project",
"${workspaceFolder}/MAES.Fiskal.Example"
],
"dependsOn": "Build Example",
"problemMatcher": []
}
],
"inputs": [
Expand Down
14 changes: 14 additions & 0 deletions MAES.Fiskal.Example/MAES.Fiskal.Example.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\MAES.Fiskal\MAES.Fiskal.csproj" />
</ItemGroup>

</Project>
46 changes: 46 additions & 0 deletions MAES.Fiskal.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel.Security;
using MAES.Fiskal;

var invoice = new RacunType
{
BrRac = new BrojRacunaType
{
BrOznRac = "1", // Invoice number (incremental for each receipt)
OznPosPr = "POSL1", // Workspace code
OznNapUr = "1" // Cash reegister number
},
DatVrijeme = DateTime.Now.ToString("dd.MM.yyyyTHH:mm:ss"), // DateTime of invoice
IznosUkupno = "12.50", // Total amount (must be format 0.00)
NakDost = false,
Oib = "18945722090", // Identification number of company
OibOper = "18945722090", // Odentitfication numer of person operating POS
OznSlijed = OznakaSlijednostiType.N,
Pdv = [ // Taxes list
new ()
{
Stopa = "25.00", // Tax percentage (must be format 0.00)
Osnovica = "10.00", // Tax base (must be format 0.00)
Iznos = "2.50" // Tax amount (must be format 0.00)
}
],
USustPdv = true, // Does company falls under tax obligation laws
NacinPlac = NacinPlacanjaType.G // Type of payment (G - Cash, K - Cards, etc...)
};

// !! Disable certificate validation (for testing purposes only, do not use in production) !!
ReferenceTypeExtensions.SslCertificateAuthentification = new()
{
CertificateValidationMode = X509CertificateValidationMode.None,
RevocationMode = X509RevocationMode.NoCheck
};

// Load certificate from file (ensure you have a valid .p12 in execution directory)
X509Certificate2 certificate = X509CertificateLoader.LoadPkcs12FromFile("cert.p12", "");

// Send invoice to fiskalization api (ensure you have access to test api and correct url)
var res = await invoice.SendAsync(certificate, "https://cistest.apis-it.hr:8449/FiskalizacijaServiceTest");

// Check for errors and print JIR
if(res.Greske != null && res.Greske.Length != 0) Console.WriteLine(string.Join(", ", res.Greske.Select(g => g.PorukaGreske)));
else Console.WriteLine($"JIR: {res.Jir}");
77 changes: 77 additions & 0 deletions MAES.Fiskal.Tests/FiskalTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace MAES.Fiskal.Tests;

using System.Security.Cryptography.X509Certificates;
using System.ServiceModel.Security;

public class FiskalTests
{
X509Certificate2 certificate => X509CertificateLoader.LoadPkcs12FromFile("cert.p12", "");

string testUrl => "https://cistest.apis-it.hr:8449/FiskalizacijaServiceTest";

RacunType invoice = new ()
{
BrRac = new BrojRacunaType
{
BrOznRac = "1",
OznPosPr = "POSL1",
OznNapUr = "1"
},
DatVrijeme = DateTime.Now.ToString("dd.MM.yyyyTHH:mm:ss"),
IznosUkupno = "100.00",
Oib = "18945722090",
OibOper = "18945722090",
OznSlijed = OznakaSlijednostiType.N,
Pdv = [ new() { Stopa = "25.00", Osnovica = "80.00", Iznos = "20.00" } ],
USustPdv = true,
NacinPlac = NacinPlacanjaType.G
};

[Fact]
public void GenerateZKI()
{
var zki = invoice.ZKI(certificate);

Assert.NotNull(zki);
Assert.NotEmpty(zki);
Assert.True(zki.Length > 20);
}

[Fact]
public async Task SendInvoice()
{
ReferenceTypeExtensions.SslCertificateAuthentification = new()
{
CertificateValidationMode = X509CertificateValidationMode.None,
RevocationMode = X509RevocationMode.NoCheck
};

var response = await invoice.SendAsync(certificate, testUrl);

Assert.NotNull(response);
Assert.NotEmpty(response.Jir);
}

// This test cannot succeed because test api doesnt have invoices
// [Fact]
// public async Task FiscalizeInvoiceTip_WithCertificate_ShouldReturnJir()
// {
// ReferenceTypeExtensions.SslCertificateAuthentification = new()
// {
// CertificateValidationMode = X509CertificateValidationMode.None,
// RevocationMode = X509RevocationMode.NoCheck
// };

// var napojnicaData = new NapojnicaType
// {
// iznosNapojnice = "10.00",
// nacinPlacanjaNapojnice = NacinPlacanjaType.G
// };

// var response = await invoice.ToRacunNapojnicaType(napojnicaData).SendAsync(certificate, testUrl);

// Assert.NotNull(response);

// if(response.NapojnicaOdgovor.Greske != null && response.NapojnicaOdgovor.Greske.Length > 0) throw new Exception($"{string.Join(", ", response.NapojnicaOdgovor.Greske.Select(g => g.PorukaGreske))}");
// }
}
25 changes: 25 additions & 0 deletions MAES.Fiskal.Tests/MAES.Fiskal.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MAES.Fiskal\MAES.Fiskal.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions MAES.Fiskal.csproj → MAES.Fiskal/MAES.Fiskal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<PackageReference Include="System.ServiceModel.Duplex" Version="6.0.0" />
<PackageReference Include="System.ServiceModel.Http" Version="6.0.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="6.0.0" />
<None Include="README.md" Pack="true" PackagePath="\"/>
<None Include="LICENSE.md" Pack="true" PackagePath="" />
<None Include="../README.md" Pack="true" PackagePath="\"/>
<None Include="../LICENSE.md" Pack="true" PackagePath="" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Reference.cs → MAES.Fiskal/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace MAES.Fiskal
{

#pragma warning disable 1591

[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "8.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.apis-it.hr/fin/2012/services/FiskalizacijaService", ConfigurationName="MAES.Fiskal.FiskalizacijaPortType")]
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ using MAES.Fiskal;
BrRac = new BrojRacunaType
{
BrOznRac = "1", // Invoice number (incremental for each receipt)
OznPosPr = "POSL_1", // Workspace code
OznPosPr = "POSL1", // Workspace code
OznNapUr = "1" // Cash reegister number
},
DatVrijeme = DateTime.Now.ToString("dd.MM.yyyyTHH:mm:ss"), // DateTime of invoice
Expand All @@ -87,9 +87,9 @@ using MAES.Fiskal;
Iznos = "2.50" // Tax amount (must be format 0.00)
}
],
Pnp = [], // Fill tax on spending if nececary :S
Pnp = [], // Fill tax on spending if nececary :S (if empty it this must not be present or fucking xml will start retardmaxxing)
USustPdv = true, // Does company falls under tax obligation laws
NacPlac = NacinPlacanjaType.G // Type of payment (G - Cash, K - Cards, etc...)
NacinPlac = NacinPlacanjaType.G // Type of payment (G - Cash, K - Cards, etc...)
};
```
2. Send invoice
Expand Down
Loading