General Description of the Software Solution

General description of the software solution, its functionalities, the method of integration with the ATK fiscalization system, and the technologies used.

This page mirrors SOFTWARE-DESCRIPTION.md in the repository and fulfils the requirement for a general description of the software solution, its functionalities, the integration method (connection of SEF with the ATK system), and the technologies used (free format).

1. General Description

This software solution (referred to below as SEF — the fiscalization software integrated into a business' POS/ERP system) is a PHP-based client library and companion test console that implements the integration between a business' point of sale / ERP system and the ATK (Tatimore e Kosovës) central Fiscalization System.

Its purpose is to allow any POS/ERP vendor to:

Deployment model. Rather than distributing this library separately to every client, it will be operated as a single centralized fiscalization service, hosted at https://fiscalization.starsoft.app. Multiple client ERP/POS applications (from different vendors/technologies) will integrate with this one central service over its HTTP API, submitting their sale data in the API/JSON format described below (see section 3.3). The centralized service takes care of building, signing, and submitting the coupons to ATK on behalf of each onboarded business, and returns the resulting QR code data back to the calling ERP.

The repository is organized into the following main parts:

Folder / file Purpose
models.proto, Atk/, GPBMetadata/ Protocol Buffers schema and the generated PHP model classes for PosCoupon, CitizenCoupon, CouponItem, Payment, TaxGroup, QrCoupon, and related enums (CouponType, PaymentType).
fiskalizimi/ModelBuilder.php Example/reference builder that constructs sample CitizenCoupon and PosCoupon objects.
fiskalizimi/CouponFactory.php Converts plain associative-array/JSON data (e.g. from an ERP) into validated protobuf coupon objects.
fiskalizimi/Signer.php Wraps OpenSSL ECDSA (SHA-256) digital signing of serialized coupon data.
fiskalizimi/FiscalizationService.php Orchestrates build → serialize → sign → (optionally) submit to ATK's /citizen/coupon and /pos/coupon endpoints over HTTPS.
fiskalizimi/Program.php Reference/example entry point demonstrating the end-to-end flow.
public/ A local, browser-based Test Console used by developers integrating with this library: a raw JSON coupon builder, a guided POS Manual Sale cash-register simulator, and a bilingual (English/Albanian) User Manual.
onboarder-*.zip Cross-platform (Windows/macOS/Linux) companion utility used once per POS/till to generate its PKI key pair, request a signed certificate from the ATK Certificate Authority, and export the private key/certificate used by the Signer.
2. Functionalities
  1. Coupon construction — building PosCoupon and CitizenCoupon protobuf messages from structured sale data: business/POS/branch identifiers, operator, line items (CouponItem: name, unit, price, quantity, tax rate, total), payments (Payment: cash, credit card, voucher, cheque, cryptocurrency, other), and tax groups (TaxGroup: rate code, taxable base, tax amount).
  2. VAT/tax-rate handling — support for the four ATK tax rate codes: A (0%, exempt), C (0%, zero-rated), D (8%, reduced), E (18%, standard), with automatic aggregation into TaxGroup totals that must reconcile between the POS Coupon and the Citizen Coupon.
  3. Digital signing (PKI/ECDSA) — serializing a coupon to Protobuf binary, Base64-encoding it, hashing it with SHA-256, and signing the hash with the business/POS' ECDSA private key via PHP's OpenSSL extension.
  4. QR code generation — combining the Base64-encoded Citizen Coupon and its Base64-encoded signature (<data>|<signature>) into the string that is encoded as the QR code printed on the physical fiscal receipt.
  5. Submission to the ATK Fiscalization Service — sending the signed POS Coupon to ATK's /pos/coupon endpoint at the time of sale, and (for testing) sending the signed Citizen Coupon to /citizen/coupon, mimicking what the Citizen Mobile App does when a customer scans the receipt's QR code.
  6. Local Test Console (public/index.html) — paste or edit raw Citizen/POS coupon JSON, then Build & Sign (locally only) or Build, Sign & Send (a real call to ATK), and inspect the resulting Base64 payload, signature, QR string and HTTP response.
  7. POS Manual Sale simulator (public/pos-sale.html) — a guided cash-register-style form: add items with a per-line tax rate, take one or more split payments, and automatically compute subtotals, tax groups and totals; then build/sign (and optionally send) both the POS Coupon and its matching Citizen Coupon in one action, rendering a scannable QR code image.
  8. User documentation (public/manual.html) — bilingual (English/Albanian) step-by-step instructions and troubleshooting guidance for using the tools above.
  9. PKI onboarding tool (onboarder) — a separate cross-platform executable that generates the POS' unique ECDSA key pair, produces a Certificate Signing Request (CSR), submits it to the ATK Certificate Authority, and retrieves/exports the signed certificate and private key (PEM format) used by this software's Signer class.
3. Method of Integration — Connection Between SEF and the ATK System

Integration between the business' software (SEF) and the ATK central Fiscalization System happens in two phases: a one-time onboarding phase and the recurring, per-sale fiscalization phase.

3.1 Onboarding (one time, per POS/till)

  1. The business runs the onboarder utility on the specific POS machine, using -env=TEST or -env=PROD, providing the business NUI, Fiscalization Number (obtained from EDI) and a unique POS ID / Branch ID.
  2. The utility generates an ECDSA key pair locally and sends a Certificate Signing Request (CSR) to the ATK Certificate Authority.
  3. ATK validates and digitally signs the certificate; the utility retrieves it and lets the operator export private-key.pem and signed-certificate.pem.
  4. The private key never leaves the POS machine and is configured for this software via the PRIVATE_KEY environment variable (or a local dummy-private-key.pem for local testing only).

3.2 Fiscalization flow (every sale)

sequenceDiagram
    participant POS as SEF (POS/ERP system)
    participant Lib as This software (fiskalizimi/*)
    participant ATK as ATK Fiscalization Service
    participant App as ATK Citizen Mobile App

    POS->>Lib: Sale data (items, payments, tax groups, totals)
    Lib->>Lib: Build PosCoupon + CitizenCoupon (Protobuf)
    Lib->>Lib: Serialize -> Base64 -> SHA-256 hash -> ECDSA sign (private key)
    Lib->>ATK: POST /pos/coupon (Base64 details + signature)
    ATK-->>Lib: HTTP 200 / acknowledgement
    Lib-->>POS: QR string = Base64(CitizenCoupon) + "|" + Base64(signature)
    POS->>POS: Print receipt with embedded QR code
    App->>App: Customer scans printed QR code
    App->>ATK: POST /citizen/coupon (same QR payload)
    ATK->>ATK: Verify signature & reconcile totals against stored POS Coupon
    ATK-->>App: Verified / Failed verification
        

Key points of the integration:

3.3 Centralized Multi-Tenant Deployment (fiscalization.starsoft.app)

In production, this software will not be installed and operated separately by each client. Instead, a single instance will be deployed and centrally operated at https://fiscalization.starsoft.app, exposed as an API that all client ERP/POS applications can call, regardless of the ERP vendor or technology stack:

flowchart LR
    ERP1[Client ERP / App 1] -->|API data - JSON| Central
    ERP2[Client ERP / App 2] -->|API data - JSON| Central
    ERP3[Client ERP / App N] -->|API data - JSON| Central
    Central[["Centralized fiskalizimi service<br/>fiscalization.starsoft.app"]] -->|Signed POS Coupon| ATK[ATK Fiscalization Service]
    Central -->|QR code string + result| ERP1
    Central -->|QR code string + result| ERP2
    Central -->|QR code string + result| ERP3
        

How responsibilities are split:

This model lets any number of ERP/POS applications integrate with ATK's fiscalization system through one simple, uniform API, without each of them having to separately implement or maintain the Protobuf/PKI/signing logic described above.

4. Technologies Used