Developer notes
Technical reference for developers who customize Turkey e-Fatura and e-Arsiv.
Add-on identity
Section titled “Add-on identity”| Item | Value |
|---|---|
| Add-on id | kv_efatura_tr |
| Function prefix | fn_kv_efatura_tr_ |
| Language variables | kv_efatura_tr.* |
| CSS scope | .kv-efatura-tr |
| PHP namespace | Tygh\Addons\KvEfaturaTr |
Structure
Section titled “Structure”| Class | Role |
|---|---|
TransportInterface |
The driver of a GIB special integrator: seller, taxpayer, send, status, pdf, cancel. Documents::transport() returns the driver; 1.0 ships Transport\Nilvera only. |
Transport\Nilvera |
Nilvera driver: taxpayer pick, status mapping (mapStatus), send, PDF, cancel |
Client\Api |
The Nilvera REST calls (the only provider specific HTTP code) on top of Client\BaseClient (cURL with TLS verification, JSON, error mapping, masked logging) |
Generators\Nilvera |
Builds the Nilvera Send/Model JSON of an order: lines, VAT, discounts, shipping and fees, buyer, e-Arsiv internet-sale block (carrier VKN per shipping method, payment intermediary) |
Documents |
Invoices: creation, buyer identity, reverse by status, resend, reissue, cancel request, recording of returns / cancellations (recordWithdrawal, guidance), listing, PDF token |
Jobs, Queue, JobException |
Jobs send_document, poll_status, cancel_document; back-off 5 min / 15 min / 1 h / 3 h / 12 h, per-job isolation, overlap lock |
TaxId |
VKN and TCKN check-digit validation |
OrderTax |
Order taxes in both CS-Cart tax calculation methods |
Idempotency |
Per-document locks and atomic state claims |
Accounts, Secret, Config, Access |
Credentials (AES-256-GCM), series and seller block per account, settings, owner mode, who may see and change what |
Log, Retention, Upgrade\Synchronizer, License\Client |
Event log, keep-data on uninstall, self-healing upgrades, licence client |
Nilvera endpoints used
Section titled “Nilvera endpoints used”All paths come from the public Nilvera documentation (developer.nilvera.com); the OpenAPI documents they were copied from are in tests/fixtures/, each with its source page.
| Purpose | Call |
|---|---|
| Connection test and seller | GET /general/Company |
| e-Fatura taxpayer | GET /general/GlobalCompany/Check/TaxNumber/{vkn}?globalUserType=Invoice (the post box alias is the Name field of the PK entry) |
| Send e-Fatura / e-Arsiv | POST /einvoice/Send/Model, POST /earchive/Send/Model (answer UUID, InvoiceNumber) |
| Status | GET /einvoice/Sale/{uuid}/Status, GET /earchive/Invoices/{uuid}/Status |
| Number after a lost answer | GET /einvoice/Sale/{uuid}/Details, GET /earchive/Invoices/{uuid}/Details |
GET /einvoice/Sale/{uuid}/pdf, GET /earchive/Invoices/{uuid}/pdf |
|
| Cancel e-Arsiv | PUT /earchive/Invoices/{uuid}/Cancel |
Authentication is Authorization: Bearer <API key>; the hosts are https://api.nilvera.com and https://apitest.nilvera.com. Nilvera has no webhooks, so the status is polled.
Adding another integrator
Section titled “Adding another integrator”Implement TransportInterface, return it from Documents::transport() (choose by an account field) and, if its invoice format is not the Nilvera model, return another GeneratorInterface from Documents::generator(). The queue, numbering state, buyer logic, PDF page and UI do not change. Integrators that only publish SOAP services need a SOAP client class next to Client\Api.
Returns
Section titled “Returns”No IADE document is built: an iade invoice is issued by the party that returns the goods. Documents::reverseOrder() (order status hook) drops a never-sent invoice, queues the Nilvera cancellation of an accepted e-Arsiv invoice and, for an e-Fatura, only writes the guidance text and a log warning. Jobs::adopt() records a TICARIFATURA rejection by the buyer (withdrawal = buyer_rejected). Everything else is Documents::recordWithdrawal(): no API call.
Idempotency
Section titled “Idempotency”- Every invoice gets its UUID (ETTN) when the row is created; the UUID is sent with the model.
- The generated model is stored before the POST. A retry first asks Nilvera for the UUID: if it exists the invoice is adopted (number from Details), if not it is sent.
- A 409 answer is resolved the same way; it is only adopted when the UUID is known at Nilvera.
- Documents have unique source keys (
order:<id>:invoice) and every job takes a database lock per document.
Database tables
Section titled “Database tables”| Table | Purpose |
|---|---|
?:kv_efatura_tr_accounts |
API key (sealed) and tax number per company, series and seller block, last connection check |
?:kv_efatura_tr_documents |
Invoices: UUID, number, scenario, profile, buyer, amounts, state, stored model, recorded return / cancellation (type, reference, date) |
?:kv_efatura_tr_jobs, ?:kv_efatura_tr_log |
Queue and log |
These tables are kept on uninstall unless “Permanently delete all invoice data on uninstall” is on (retention.json).
Hooks used
Section titled “Hooks used”| Hook | Use |
|---|---|
change_order_status_post |
Issue and reverse invoices at the configured statuses |
delete_order |
Writes a log entry; invoices of a deleted order are kept |
init_templater_post |
Upgrade synchronizer (only while an upgrade is pending) |
orders:tabs_extra, orders:manage_header, orders:manage_data (admin) |
Order tab and list column |
orders:info (storefront) |
PDF link on the customer’s order page |
Test without Nilvera
Section titled “Test without Nilvera”The base URL can be overridden for tests in config.local.php (development only):
$config['kv_efatura_tr_base_url'] = 'http://127.0.0.1:11830';node tests/mock-server/server.js 11830 starts a local stand-in built from the documentation: it validates every sent model against the OpenAPI schemas, uses the documented paths and error bodies and can simulate a lost answer, a closed cancellation window, an unknown series and a network rejection. node tests/e2e/e2e.mjs --store cs417 runs the end-to-end test (it refuses to run when the store does not point at the mock); php tests/unit.php runs the unit tests. The mock proves the add-on against the documentation, not against the live service.
Template overrides
Section titled “Template overrides”Admin templates live in design/backend/templates/addons/kv_efatura_tr/. Do not edit them in a store; they are replaced on update.