Developer notes
Technical reference for developers who customize Xero Accounting Sync.
Add-on identity
Section titled “Add-on identity”| Item | Value |
|---|---|
| Add-on id | kv_xero |
| Function prefix | fn_kv_xero_ |
| Language variables | kv_xero.* |
| CSS scope | .kv-xero |
| PHP namespace | Tygh\Addons\KvXero |
| Preset | accounting (generated by kv new --kind integration) |
Structure
Section titled “Structure”| Class | Role |
|---|---|
Client\BaseClient |
HTTP (cURL, TLS verification, timeouts), JSON, Retry-After and rate limit headers, error mapping, masked logging |
Client\Api |
OAuth 2.0 (authorization code, rotating refresh token under a database lock) and the Accounting API calls |
Client |
Client per company, the connection test |
Sync |
Contact, invoice, payment, credit note, refund and item sync; tax allocation; the map table |
Accounts, Secret |
Credentials (test and live) sealed with AES-256-GCM; one account per store owner or per vendor |
Config, Access |
Settings, owner mode, who may see and manage what |
Queue, Jobs, JobException |
Job queue: back-off 5 min / 15 min / 1 h / 3 h / 12 h, per-job isolation, overlap lock; handlers in Jobs::handle(), recurring work in Jobs::schedule() |
Log |
Event log with masking, filters, CSV, retention |
Database tables
Section titled “Database tables”| Table | Purpose |
|---|---|
?:kv_xero_accounts |
Credentials per company (secrets sealed), last connection check, token cache |
?:kv_xero_log |
Log |
?:kv_xero_jobs |
Queue |
?:kv_xero_map |
What was sent to the accounting system (Xero ids, payload hash) |
Hooks used
Section titled “Hooks used”PHP hook change_order_status_post (queues the invoice, payment and credit note jobs). Template hooks: only the License card in the add-on settings. Nothing is printed on the storefront, so full page cache and Varnish are unaffected.
Test the HTTP layer without Xero
Section titled “Test the HTTP layer without Xero”The base URL can be overridden for tests in config.local.php (development only):
$config['kv_xero_base_url'] = 'http://127.0.0.1:11923';node tests/mock-server/server.js 11923 starts a local stand-in of the Xero identity service and Accounting API; node tests/e2e/e2e.mjs runs the end-to-end test (real orders, OAuth flow, refunds) against it; php tests/unit.php runs the unit tests.
Template overrides
Section titled “Template overrides”Admin templates live in design/backend/templates/addons/kv_xero/. Do not edit them in a store; they are replaced on update.
API conformance (official Xero documentation)
Section titled “API conformance (official Xero documentation)”Checked on 2026-11-06 in a real browser against developer.xero.com. The mock server (tests/mock-server/server.js) carries the official scope list
and the resource-to-scope table copied from the Scopes page; it refuses the deprecated broad scopes with invalid_scope and answers 403 when a
token lacks the scope that covers a resource, so it no longer follows our own code.
| Purpose | What the add-on does | Official page | Verified |
|---|---|---|---|
| Scopes | offline_access accounting.invoices accounting.payments accounting.contacts + accounting.settings.read (accounting.settings when Xero items are created). Invoices, CreditNotes and Allocations fall under accounting.invoices; Payments under accounting.payments; Contacts under accounting.contacts; Organisation, Accounts, TaxRates and Items under accounting.settings. The broad accounting.transactions is deprecated: Web and PKCE apps have granular scopes since March 2026, broad scopes remain only for existing apps until September 2027. |
https://developer.xero.com/documentation/guides/oauth2/scopes/ | yes |
| Authorization code flow | GET https://login.xero.com/identity/connect/authorize (response_type=code, client_id, redirect_uri, scope, state); code valid 5 minutes |
https://developer.xero.com/documentation/guides/oauth2/auth-flow/ | yes |
| Tokens | POST https://identity.xero.com/connect/token with Basic client id and secret; access token 30 minutes; refresh token single use, 60 days; offline_access needed for a refresh token |
https://developer.xero.com/documentation/guides/oauth2/auth-flow/ | yes |
| Tenants | GET https://api.xero.com/connections, header xero-tenant-id on every Accounting call |
https://developer.xero.com/documentation/guides/oauth2/tenants/ | yes |
| Limits | 5 concurrent calls, 60 per minute, 5,000 per day per organisation (1,000 on the starter tier); Retry-After on 429 |
https://developer.xero.com/documentation/guides/oauth2/limits/ | yes |
| Accounting resources | /api.xro/2.0/Invoices, /Payments, /CreditNotes, /CreditNotes/{id}/Allocations, /Contacts, /Items, /Accounts, /TaxRates, /Organisation |
https://github.com/XeroAPI/Xero-OpenAPI (xero_accounting.yaml) |
yes |
- API sources: Xero’s published OpenAPI descriptions (github.com/XeroAPI/Xero-OpenAPI:
xero_accounting.yaml,xero-identity.yaml) and the developer.xero.com pages listed in the conformance table below. - Refresh tokens are single use.
Accounts::locked()serialises the refresh withGET_LOCK, and a second process re-reads the account after the lock, so cron and an admin click never burn the same token. - Idempotency keys:
kv-inv-<order>-<hash>,kv-pay-<order>,kv-cn-<order>,kv-rf-<order>,kv-al-<order>. - Map table entities: customer, invoice, payment, credit, refund (payment or allocation), item.
- CS-Cart stores taxes either per line (
appliesP_) or per order (subtotal calculation); Sync::allocate()handles both.