Skip to content

Commit

Permalink
Upgrade to CIS WSDL 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrospic committed Jul 26, 2017
1 parent faf08bc commit 341b234
Show file tree
Hide file tree
Showing 20 changed files with 351 additions and 763 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ nuget.exe
docs/*.html
README.html
/*.cmd
/*.ps1
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
_**Napomena**: Zbog promjene u minimalnoj verziji TLS enkripcije od `CIS v1.3` ova komponenta zahtjeva **.NET 4.5** za komunikaciju sa serverom ([detaljnije](#cis-v13---tls-v11--tls-v12)).
Zbog ove promjene izdan je novi release COM komponente `v1.2.1-com`._

.NET (C#) wrapper oko generiranog SOAP klijenta za pozivanje fiskalizacijskog servisa porezne uprave `CIS v1.3`.
.NET (C#) wrapper oko generiranog SOAP klijenta za pozivanje fiskalizacijskog servisa porezne uprave `CIS WSDL v1.4`.

Sa Microsoft [Wsdl.exe][wsdl.exe] tool-om su generirane proxy klase sa strukturom po WSDL shemi koja je objavljena na stranicama porezne uprave [Tehničke specifikacije][porezna-spec] i koja je uključena u source kôd projekta.
Preko generiranog SOAP klijenta [FiskalizacijaService][fiscalization-service.cs] se rade svi SOAP pozivi prema __CIS__ servisu. Kompletna implementacija je u [Fiscalization][fiscalization.cs] klasi sa dodatkom async metoda u [Fiscalization.Async.cs][fiscalization-async.cs] file-u. :smile:
Expand Down Expand Up @@ -55,18 +55,18 @@ public static class Fiscalization
{
// Async .NET 4.5 :: Fiscalization.Async.cs
Task<RacunOdgovor> SendInvoiceAsync(RacunType invoice, X509Certificate2 cert);
Task<PoslovniProstorOdgovor> SendLocationAsync(PoslovniProstorType location, X509Certificate2 cert);
Task<ProvjeraOdgovor> CheckInvoiceAsync(RacunType invoice, X509Certificate2 cert)

// Sync :: Fiscalization.cs
RacunOdgovor SendInvoice(RacunType invoice, X509Certificate2 cert);
PoslovniProstorOdgovor SendLocation(PoslovniProstorType location, X509Certificate2 cert);
ProvjeraOdgovor CheckInvoice(RacunType invoice, X509Certificate2 cert);
}
```

Svaka metoda još opcionalno prima funkciju `Action<FiskalizacijaService>` za postavljanje
parametara generiranoj proxy klasi __FiskalizacijaService__ (npr. url, timeout...).

Za _RacunType, RacunOdgovor, PoslovniProstorType, PoslovniProstorOdgovor_ i ostale generirane proxy klase vidi source [FiskalizacijaService.cs][fiscalization-service.cs].
Za _RacunType, RacunOdgovor, ProvjeraOdgovor_ i ostale generirane proxy klase vidi source [FiskalizacijaService.cs][fiscalization-service.cs].

Primjer poziva servisa za slanje računa
```cs
Expand All @@ -92,7 +92,7 @@ var invoice = new RacunType()
{
Stopa = 25.ToString("N2", CultureInfo.InvariantCulture),
Osnovica = 2.34.ToString("N2", CultureInfo.InvariantCulture),
Iznos = 0.59.ToString("N2", CultureInfo.InvariantCulture),
Iznos = .56.ToString("N2", CultureInfo.InvariantCulture)
}
},
USustPdv = true
Expand Down Expand Up @@ -131,7 +131,8 @@ RacunOdgovor response = await Fiscalization.SendInvoiceAsync(invoice, certificat

Od `CIS v1.3` verzija protokola za enkripciju preko HTTPS-a je `TLS v1.1` ili `TLS v1.2`.

Ova komponenta koristi `System.Net` za komunikaciju u kojoj su ti protokoli podržani od **.NET 4.5** verzije. .NET 4.6 ima default postavljenu verziju TLS 1.2 dok .NET 4.5 nema pa se to može napraviti na sljedeći način:
Ova komponenta koristi `System.Net` za komunikaciju u kojoj su ti protokoli podržani od **.NET 4.5** verzije.
.NET 4.6 ima default postavljenu verziju TLS 1.2 dok .NET 4.5 nema pa se to može napraviti na sljedeći način:

```cs
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
Expand Down Expand Up @@ -184,7 +185,7 @@ start Fiscalization.sln

[docs-com]: ./docs/fiscalization-com.md
[docs-com-api]: ./docs/fiscalization-com-api.md
[cis-version-image]: https://cdn.rawgit.com/tgrospic/Cis.Fiscalization/master/docs/cis-service-version.svg?v1.3
[cis-version-image]: https://cdn.rawgit.com/tgrospic/Cis.Fiscalization/master/docs/cis-service-version-1.4.svg
[fiscalization.cs]: ./src/Fiscalization/Cis/Fiscalization.cs
[fiscalization-async.cs]: ./src/Fiscalization/Cis/Fiscalization.Async.cs
[fiscalization-service.cs]: ./src/Fiscalization/Cis/FiskalizacijaService.cs
Expand Down
20 changes: 20 additions & 0 deletions docs/cis-service-version-1.4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 0 additions & 20 deletions docs/cis-service-version.svg

This file was deleted.

15 changes: 6 additions & 9 deletions docs/fiscalization-com-api.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# COM API specifikacija

Ovdje je cijeli COM API zajedno sa helper metodama i field-ovima. Za strukturu generiranih proxy objekata (_RacunType, RacunZahtjev, RacunOdgovor, PoslovniProstorType_, ...) vidi source [FiskalizacijaService.cs][fiscalization-service.cs] ili WSDL shemu.
Ovdje je cijeli COM API zajedno sa helper metodama i field-ovima. Za strukturu generiranih proxy objekata (_RacunType, RacunZahtjev, RacunOdgovor, ProvjeraOdgovor, ...) vidi source [FiskalizacijaService.cs][fiscalization-service.cs] ili WSDL shemu.

## FiscalizationComInterop
```vb
' Slanje računa
RacunOdgovor SendInvoice(RacunType, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)
RacunOdgovor SendInvoiceRequest(RacunZahtjev, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)

' Slanje poslovnog prostora
PoslovniProstorOdgovor SendLocation(PoslovniProstorType, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)
PoslovniProstorOdgovor SendLocationRequest(PoslovniProstorZahtjev, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)
' Provjera računa
ProvjeraOdgovor CheckInvoice(RacunType, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)
ProvjeraOdgovor CheckInvoiceRequest(RacunZahtjev, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)

' Echo
String SendEcho(String, timeout/ms: Int, isDemo: Bool)
Expand All @@ -24,8 +24,8 @@ GenerateZki(RacunType, (X509Certificate2))
' Kreiranje zahtjeva za račun (ako se koristi SendInvoiceRequest)
RacunZahtjev CreateInvoiceRequest(RacunType)

' Kreiranje zahtjeva za popslovni prostor (ako se koristi SendLocationRequest)
PoslovniProstorZahtjev CreateLocationRequest(PoslovniProstorType)
' Kreiranje zahtjeva za provjeru račun (ako se koristi CheckInvoiceRequest)
ProvjeraZahtjev CreateCheckRequest(RacunType)

' Potpisivanje zatjeva (RacunZahtjev ili PoslovniProstorZahtjev)
Sign(zahtjev: ICisRequest, (X509Certificate2))
Expand Down Expand Up @@ -55,9 +55,6 @@ NacinPlacanjaType_G
NacinPlacanjaType_K
NacinPlacanjaType_O
NacinPlacanjaType_T

' Oznaka zatvaranja
OznakaZatvaranjaType_Z
```

#### VBScript - pomoćne metode za konverziju Variant() array-a
Expand Down
18 changes: 8 additions & 10 deletions docs/fiscalization-com.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ REM x64

## API

**Napomena**: od verzije `v1.2.0` postoje dvije nove metode za jednostavnije slanje koje automatski kreiraju zahtjev. Sve ostalo je isto kao i kod verzije `v1.1.0`.

Ovdje je kompletan [COM API][com-api].
Metode za poziv servisa i pomoćne metode su prilagođene za pozive preko COM-a sa __FiscalizationComInterop__ klasom.
Svejedno je jel se koristi uvijek ista instanca ili se za svaki poziv kreira nova.
Expand All @@ -41,17 +39,17 @@ Svejedno je jel se koristi uvijek ista instanca ili se za svaki poziv kreira nov
' .NET COM Interop
Dim cisInterop As New FiscalizationComInterop

' Slanje računa (od v1.2.0)
' Slanje računa
Set result = cisInterop.SendInvoice(RacunType, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)

' Slanje poslovnog prostora (od v1.2.0)
Set result = cisInterop.SendLocation(PoslovniProstorType, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)

' Slanje računa (zahtjev)
Set result = cisInterop.SendInvoiceRequest(RacunZahtjev, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)

' Slanje poslovnog prostora (zahtjev)
Set result = cisInterop.SendLocationRequest(PoslovniProstorZahtjev, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)
' Provjera računa
Set result = cisInterop.CheckInvoice(RacunType, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)

' Provjera računa (zahtjev)
Set result = cisInterop.CheckInvoiceRequest(RacunZahtjev, (X509Certificate2), timeout/ms: Int, isDemo: Bool, check_response_signature: Bool)

' Echo
Set result = cisInterop.SendEcho(String, timeout/ms: Int, isDemo: Bool)
Expand Down Expand Up @@ -164,6 +162,6 @@ Call cisInterop.GenerateZki((invoice), (cert))
Call cisInterop.Sign((request), (cert))
```

[release-latest]: https://github.com/tgrospic/Cis.Fiscalization/releases/tag/v1.2.1-com
[download-com]: https://github.com/tgrospic/Cis.Fiscalization/releases/download/v1.2.1-com/FiscalizationCom-v1.2.1-com.zip
[release-latest]: https://github.com/tgrospic/Cis.Fiscalization/releases/latest
[download-com]: https://github.com/tgrospic/Cis.Fiscalization/releases/download/v1.3.0/FiscalizationCom-v1.3.0.zip
[com-api]: ./fiscalization-com-api.md
36 changes: 15 additions & 21 deletions src/Fiscalization/Cis/Fiscalization.Async.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Cis.Fiscalization v1.2.0 :: CIS v1.2 (2012-2015)
// Cis.Fiscalization v1.3.0 :: CIS WSDL v1.4 (2012-2017)
// https://github.com/tgrospic/Cis.Fiscalization
// Copyright (c) 2013, 2015 Tomislav Grospic
// Copyright (c) 2013-present Tomislav Grospic
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Expand All @@ -21,7 +21,6 @@ public static partial class Fiscalization
/// <param name="request">Request to send</param>
/// <param name="certificate">Signing certificate, optional if request is already signed</param>
/// <param name="setupService">Function to set service settings</param>
/// <returns></returns>
public static Task<RacunOdgovor> SendInvoiceRequestAsync(RacunZahtjev request, X509Certificate2 certificate = null,
Action<FiskalizacijaService> setupService = null)
{
Expand All @@ -37,7 +36,6 @@ public static Task<RacunOdgovor> SendInvoiceRequestAsync(RacunZahtjev request, X
/// <param name="invoice">Invoice to send</param>
/// <param name="certificate">Signing certificate</param>
/// <param name="setupService">Function to set service settings</param>
/// <returns></returns>
public static Task<RacunOdgovor> SendInvoiceAsync(RacunType invoice, X509Certificate2 certificate,
Action<FiskalizacijaService> setupService = null)
{
Expand All @@ -54,50 +52,46 @@ public static Task<RacunOdgovor> SendInvoiceAsync(RacunType invoice, X509Certifi
}

/// <summary>
/// Send location request async
/// Check invoice request async
/// </summary>
/// <param name="request">Request to send</param>
/// <param name="certificate">Signing certificate, optional if request is already signed</param>
/// <param name="setupService">Function to set service settings</param>
/// <returns></returns>
public static Task<PoslovniProstorOdgovor> SendLocationRequestAsync(PoslovniProstorZahtjev request, X509Certificate2 certificate = null,
public static Task<ProvjeraOdgovor> CheckInvoiceRequestAsync(ProvjeraZahtjev request, X509Certificate2 certificate = null,
Action<FiskalizacijaService> setupService = null)
{
if (request == null) throw new ArgumentNullException("request");
if (request.PoslovniProstor == null) throw new ArgumentNullException("request.PoslovniProstor");
if (request.Racun == null) throw new ArgumentNullException("request.Racun");

return SignAndSendRequestAsync<PoslovniProstorZahtjev, PoslovniProstorOdgovor>(
request, x => x.PoslovniProstorAsync, certificate, setupService);
return SignAndSendRequestAsync<ProvjeraZahtjev, ProvjeraOdgovor>(request, x => x.ProvjeraAsync, certificate, setupService);
}

/// <summary>
/// Send location async
/// Send invoice async
/// </summary>
/// <param name="location">Location to send</param>
/// <param name="invoice">Invoice to check</param>
/// <param name="certificate">Signing certificate</param>
/// <param name="setupService">Function to set service settings</param>
/// <returns></returns>
public static Task<PoslovniProstorOdgovor> SendLocationAsync(PoslovniProstorType location, X509Certificate2 certificate,
public static Task<ProvjeraOdgovor> CheckInvoiceAsync(RacunType invoice, X509Certificate2 certificate,
Action<FiskalizacijaService> setupService = null)
{
if (location == null) throw new ArgumentNullException("location");
if (invoice == null) throw new ArgumentNullException("invoice");
if (certificate == null) throw new ArgumentNullException("certificate");

var request = new PoslovniProstorZahtjev
var request = new ProvjeraZahtjev
{
PoslovniProstor = location,
Racun = invoice,
Zaglavlje = Cis.Fiscalization.GetRequestHeader()
};

return SendLocationRequestAsync(request, certificate, setupService);
return CheckInvoiceRequestAsync(request, certificate, setupService);
}

/// <summary>
/// Send echo request async
/// </summary>
/// <param name="echo">String to send</param>
/// <param name="setupService">Function to set service settings</param>
/// <returns></returns>
public static Task<string> SendEchoAsync(string echo, Action<FiskalizacijaService> setupService = null)
{
if (echo == null) throw new ArgumentNullException("echo");
Expand Down Expand Up @@ -206,9 +200,9 @@ public Task<RacunOdgovor> RacuniAsync(RacunZahtjev request)
return Task.Factory.FromAsync(Beginracuni, Endracuni, request, null);
}

public Task<PoslovniProstorOdgovor> PoslovniProstorAsync(PoslovniProstorZahtjev request)
public Task<ProvjeraOdgovor> ProvjeraAsync(ProvjeraZahtjev request)
{
return Task.Factory.FromAsync(BeginposlovniProstor, EndposlovniProstor, request, null);
return Task.Factory.FromAsync(Beginprovjera, Endprovjera, request, null);
}

public Task<string> EchoAsync(string request)
Expand Down
Loading

0 comments on commit 341b234

Please sign in to comment.