Overview
DALP posts an organisation's final money events to its Xero ledger. A background job turns each mapped event (such as a trade settlement, fee, bank rail credit or cash-out, paid dividend, or reversal) into a balanced Xero manual journal. It posts each journal once and keeps a posting record for every event.
The same events reach every registered webhook endpoint. Organisations keeping books in another ledger, or running custom posting logic, can subscribe to the signed webhook feed using the rules below. See Receive DALP webhooks for endpoint registration and signature verification.
How DALP posts to Xero
A background job runs once a minute across the deployment to read committed organisation events. Each committed event is written in the same database transaction as the change it describes, independent of webhooks, so a disabled or failing webhook endpoint never blocks posting.
For each event, the job performs four steps:
- Copies the event into a posting record, starting from the creation of the organisation's first stored configuration version. Earlier events are never posted.
- Evaluates the event against the newest configuration version's rule table, as From event to journal describes.
- Maps account keys to Xero account codes, checks the journal currency against the Xero organisation's base currency, and posts one manual journal with status
POSTEDand no tax. - Stores the Xero journal id and Xero tenant id on the posting record.
Each journal reaches Xero at most once per record across retries, crashes, and configuration updates. DALP embeds a narration marker built from the organisation and source_id, and sends an idempotency key built the same way. Before retrying, DALP searches Xero for that marker and records any existing journal rather than posting a duplicate.
Once a request may have reached Xero, later attempts resend that exact request to the same Xero organisation, even after a configuration change. Never edit or delete a DALP journal's narration in Xero. Post a new journal for any correction. The job processes one organisation at a time, one record at a time.
Connect Xero
Each organisation connects its own Xero app so the deployment holds no shared credentials. An administrator with webhook:manage connects Xero from a signed-in Console session. API keys cannot connect, read, or disconnect Xero.
- Create a web app in the Xero developer portal and note its client id and client secret.
- From a signed-in Console session, send them to
POST /api/.v2/ accounting/ xero/ connection - Add the returned
redirectUri(<console-) verbatim to the Xero app's redirect URIs.url>/ api/ v2/ accounting/ xero/ callback - Within ten minutes, open
authorizeUrlin the same browser and consent at Xero for the target Xero organisation. - Xero redirects back to DALP, which completes the connection and redirects to
/.org- settings/ accounting?xero=<outcome> - Call
GET /api/, then store a posting configuration withv2/ accounting/ xero/ connection mapping.xeroTenantIdset to one of itstenantIds.
curl -sS -X POST "$DALP_API_URL/api/v2/accounting/xero/connection" \
-H "Cookie: $DALP_SESSION_COOKIE" \
-H "Content-Type: application/json" \
-d '{
"clientId": "6F1C9A2B4D7E40A8B3C5D9E1F2A4B6C8",
"clientSecret": "xero-app-client-secret"
}'DALP returns the consent URL (requesting all four scopes) and the redirect URI, and never returns the client secret:
{
"authorizeUrl": "<Xero consent URL carrying the client id, the redirect URI, the four scopes and a single-use state>",
"redirectUri": "https://console.example.com/api/v2/accounting/xero/callback"
}DALP requests four Xero scopes:
offline_access: keeps the OAuth connection active via refresh tokens.accounting.: posts and searches manual journals.manualjournals accounting.settings.read: reads the Xero organisation's base currency and chart of accounts.accounting.: reads the client-money balance for bank rail daily reconciliation.reports. balancesheet. read
Connections created before DALP requested accounting. continue posting. Reconnect Xero to add that scope.
A new connect replaces any connect waiting for consent. The callback completes only for the signed-in user who started it while they still hold webhook:manage, and each consent URL works once. Without a Console session, the callback returns 401 and leaves the consent URL valid until expiry.
On every outcome except connected, DALP discards the stored client secret and revokes any issued token without exposing Xero's raw error text. Reconnecting with the same Xero user and app replaces the stored token. Using a different user or app also revokes the earlier grant at Xero.
Connection status and disconnect
GET /api/ reads the stored connection without calling Xero:
{
"state": "connected",
"tenantIds": ["8a3f2c71-5d4e-4b9a-a1c6-2e7f9b0d3c58"],
"lastRefreshedAt": "2026-11-10T09:15:00.000Z"
}state is connected, needs-reconnect, or disconnected. needs-reconnect means Xero rejected the stored grant, which pauses posting and raises a Xero connection needs attention case. Reconnect to resume.
DALP refreshes the access token roughly every 30 minutes while posting, and refreshes idle connections before Xero's 60-day refresh-token expiry. Each refresh rotates the refresh token safely across crashes.
DELETE /api/ stops posting immediately, revokes the grant at Xero (retrying every minute until confirmed), and deletes the stored token and client secret afterwards. Five unconfirmed attempts raise a Xero connection needs attention case. Disconnecting with no active connection returns 404 (DALP-20544).
Who can call what
See Approvals for protecting Custody administration changes.
Where the credentials live
Refresh tokens and client secrets never enter accounting tables, logs, audit records, or API responses. DALP stores them in the secret manager selected by secretManager.provider (Secrets and key handling):
- With
local, DALP encrypts each secret under the deployment master password in the platform database. - With
aws,gcp,azure, orvault, secrets live in AWS Secrets Manager, Google Secret Manager, Azure Key Vault, or HashiCorp Vault under that store's controls.
Every platform service with secret-manager access can read these secrets, and the organisation in a secret's name is a label rather than an access control. On deletion, Azure Key Vault retains soft-deleted secrets for its retention window, and HashiCorp Vault KV v2 deletes only the latest version. Audit records redact the callback's state and code.
Posting records
DALP stores one posting record for every committed event of a configured organisation, even for unmapped event types, so rules added later can process earlier events. Each record carries its status, reason, deciding configuration version, built journal, and Xero identifiers.
Key lifecycle rules:
- A new configuration version re-evaluates every
unmappedrecord on the next pass. - Replaying a
failed,unmapped, orignoredrecord moves it back topending.postedrecords are never replayed. - Payloads stay until 30 days after a record reaches
postedorignored, while the decided journal stays permanently. Replaying anignoredrecord after payload pruning is refused. - An event whose payload was pruned before DALP copied it enters
failedwith reasonpayload-pruned.
Read and retry posting records
GET /api/ lists posting records newest first using page[limit] (default 50) and page[offset], returning meta.total and meta.facets.status across all statuses. Filter with filter[status]=failed or predicates such as filter[status][in. Any sort other than -createdAt returns 400 DALP-.
Each record includes status, reason, detail, journal (narration, debit total, and lines), xeroJournalId or dailyJournal, attempts, replayCount, and replayable. The Console's Accounting page (Accounting) displays these records and the Xero connection state.
POST /api/ (the route behind Retry posting) returns an eligible failed, unmapped, or ignored record to pending and clears its reason, failure detail, and daily journal link. On the next pass, unmapped and ignored records re-evaluate under the newest configuration.
For a failed record already sent to Xero less than six minutes ago, DALP resends the exact built journal. Otherwise DALP checks Xero by narration marker first, marks it posted if present, or rebuilds it under the newest configuration if absent. The replay request takes no body and returns 200:
curl -sS -X POST "$DALP_API_URL/api/v2/accounting/postings/4f6b2c1e-8a3d-4e7f-9b25-0c6d1a8e3f72/replays" \
-H "Cookie: $DALP_SESSION_COOKIE"{
"data": {
"id": "4f6b2c1e-8a3d-4e7f-9b25-0c6d1a8e3f72",
"sourceId": "chain:537001:0x3f9c2a7e5b1d84c06e2a9f4b7d3c1e8a5f6b2d9c0e7a4f1b3c5d8e2a6f9b0c4d:3:0:primary-market.subscription.final@1",
"eventType": "primary-market.subscription.final",
"eventVersion": 1,
"lifecycleState": "final",
"status": "pending",
"reason": null,
"detail": null,
"configurationVersion": 3,
"postingPolicy": "per-trade",
"journal": {
"narration": "primary-market.subscription.final chain:537001:0x3f9c2a7e5b1d84c06e2a9f4b7d3c1e8a5f6b2d9c0e7a4f1b3c5d8e2a6f9b0c4d:3:0:primary-market.subscription.final@1",
"occurredAt": "2026-10-12T09:15:00.000Z",
"amount": "24.99",
"currency": "USD",
"lines": [
{
"side": "debit",
"amount": "24.99",
"currency": "USD",
"accountKey": "investor-cash",
"classification": "trades",
"description": "Subscription"
},
{
"side": "credit",
"amount": "24.99",
"currency": "USD",
"accountKey": "subscription-liability",
"classification": "trades",
"description": "Subscription"
}
]
},
"xeroJournalId": null,
"xeroTenantId": null,
"dailyJournal": null,
"reversedBy": null,
"attempts": 2,
"replayCount": 1,
"replayable": false,
"createdAt": "2026-10-12T09:16:04.000Z",
"updatedAt": "2026-11-10T14:02:31.000Z"
},
"links": { "self": "/api/v2/accounting/postings" }
}Each replay writes an audit record. Refused replays are not retryable and leave the record unchanged:
Posting policies
postingPolicy is per-trade (the default) or daily-aggregate. Each record keeps the policy stamped when decided, so changes apply only to newly decided records.
Under per-trade, each record posts its own journal dated on the UTC day of the event's timestamp.
Under daily-aggregate, decided records wait as sealed until 02:00 UTC the next day, when DALP builds and posts one balanced journal for that UTC day:
- Lines are summed per account, side, tax type, and tracking category, netting debits against credits on the same account.
- A day netting to zero marks records
postedwithout calling Xero. - Days reaching ten billion in ledger currency split into multiple journals.
- Late records go into a supplementary journal for that day (failing with a case if Xero's period is locked).
- Unmapped records do not block the rest of the day. If Xero refuses a daily journal, its records become
failed, and replayed records join the next journal for that day.
Reversals
A retraction (such as a trade bust) posts as a reversal mirroring the original journal's lines on the same Xero account codes, even if account mappings changed later:
- Under
per-trade, a reversal waits silently until its original posts. - Under
daily-aggregate, a same-day reversal nets inside that day's open journal, and a later reversal waits for the original's daily journal to post. - DALP reverses an original at most once.
- A reversal waiting more than one connected day raises an Accounting event blocked case and retries hourly until the original posts.
Operations cases
DALP opens an operations case whenever an event cannot post. See Work an operations case.
Xero limits
Xero's Starter tier allows 1,000 API calls per day and 5 connected organisations, suitable for trials but not production books. Each post uses about two calls once tokens and tenants are cached, so production organisations should use a higher Xero tier or daily-aggregate. On HTTP 429, DALP pauses only that organisation until Xero's retry window (default 60 seconds).
A Xero Demo Company resets every 28 days with a new tenant id, raising a Xero connection needs attention case until you reconnect and save a new configuration version.
What DALP does not post
- Mirror-token issuance and burn (delivered to webhook endpoints only, not committed accounting intake).
- Completed partial redemptions and buybacks (no cash-movement event exists, so they end
unmappedwith a case). - Events before the organisation's first configuration version, or events whose payload was pruned before copy.
- Tax-bearing journal lines (end
unmapped).
Book these manually or through a custom subscriber.
Run your own subscriber
A custom subscriber handles ledgers other than Xero, webhook-only events from What DALP does not post, and scheduled reconciliation against DALP read APIs. If both DALP and a custom subscriber post to Xero, keep their rule tables disjoint so movements are never double-posted.
The remaining sections specify the subscriber contract. DALP's built-in posting job follows the same rule table.
A signed delivery is verified, branched on lifecycle_state and posted once per source_id, so a replay builds the same entry.
See Accounting feed events for the delivery envelope fields and the bank rail, fee, and bond payout events.
Verify and accept a delivery
Verify every delivery signature before parsing JSON or running posting logic, using verifyWebhook or a Standard Webhooks library (Verify the signature). During secret rotation, webhook-signature can carry two signatures and either is valid.
Respond with 2xx as soon as the event is stored durably, then post asynchronously. Responses slower than 20 seconds count as failures and trigger retries. See retries, counter-signed receipts, and secret rotation.
A valid signature proves origin and integrity, not finality. Inspect lifecycle_state next.
From event to journal
A rule table maps events to journals using two rule kinds:
- Posting rule: Names
type,version, an optional payload match condition, a classification (trades,fees,servicing, orcorrections), debit and credit account keys, plus the payload fields for amount, asset, timestamp, optional domain key, and description references. - Reversal rule: Names the event type it reverses and the payload field that matches the original's domain key.
An account key is an organisation-chosen logical name such as investor-cash. The account mapping resolves each key per classification to a real ledger account code, keeping rules decoupled from chart-of-accounts changes.
Reject the entire rule table if any invariant fails:
- Every account key resolves in the mapping for its classification.
- No two rules match the same event, and no event type has both posting and reversal rules.
- Every reversal rule targets a type with a posting rule keyed on the same payload field.
- Every asset's currency matches the ledger currency.
- No posting rule targets a
pendingorprovisionalevent.
Which events post
Refuse a final event with no matching rule, or a retracted event reversing a posted entry with no rule, using a named error so you extend the rule table. Acknowledge test, recalled, pending, and provisional events (and their retractions) as no-ops so they never cause retry loops.
The journal shape
Each posting produces one balanced two-line entry:
Each line carries the classification, ledger currency, and a description combining the rule text with field=value reference pairs.
Amounts
Token and asset event amounts are integer strings in base units. Use the organisation's asset table (currency and decimals) to convert into exact integer cents with no rounding.
Refuse any amount that is zero, not a whole number of cents, or ten billion or more in the ledger currency. A sub-cent amount indicates a rule or asset-table mismatch that requires human review rather than rounding.
Worked example: one subscription
When an investor subscribes to a token sale and its block reaches finality, DALP delivers:
{
"evt_id": "evt_7c12e838e3f9a8bafcaa292f86ed41e7",
"source_id": "chain:537001:0x3f9c2a7e5b1d84c06e2a9f4b7d3c1e8a5f6b2d9c0e7a4f1b3c5d8e2a6f9b0c4d:3:0:primary-market.subscription.final@1",
"type": "primary-market.subscription.final",
"version": 1,
"lifecycle_state": "final",
"payload": {
"saleAddress": "0x7777777777777777777777777777777777777777",
"paymentCurrencyAddress": "0x8888888888888888888888888888888888888888",
"paymentAmount": "1000000000",
"occurredAt": "2026-10-12T09:15:00.000Z"
}
}With a posting rule mapping paymentCurrencyAddress 0x8888...8888 to USD (6 decimals), 1000000000 base units converts to 1000. (100,000 cents). Using <source_id> for the envelope's source_id, the subscriber builds:
The connector resolves investor-cash and subscription-liability under the trades mapping and posts one balanced manual journal.
Store a posting configuration
Store your rule table, account mapping, and posting policy with PUT /api/, and read the latest version with GET /api/:
postingPolicy:per-trade(default) ordaily-aggregate.mapping:xeroTenantId,defaultCurrency, per-classificationaccounts, and optionaltaxTypesandtrackingCategories.rules: either an explicit rule table or preset parameters.
Each write creates an immutable version. Send the last version as expectedVersion (or null for the first). A stale version returns 409, identical content returns the existing version, and an invalid rule table returns 422 with data.issues.
Preset parameters name quote assets, mirror assets, other assets, and bank rail currencies with account suffixes (such as client-). DALP expands and freezes the resulting rule table inside that version, so preset updates reach an organisation only when you save a new version. Versions saved before bond payout rules existed need a re-save with servicing. mapped for every ledger-currency quote asset.
The first stored version starts posting-record intake from that timestamp forward. Any record that may already have reached Xero retains the configuration version that decided it.
Reversals and idempotency
Two keys keep the ledger accurate:
webhook-iddeduplicates deliveries. It carries the envelope'sevt_id. Store handled ids and respond2xxon retries.source_idmakes postings idempotent. Replays assign a newevt_idbut keepsource_id, so keying entries on(organisation, sourceprevents duplicates.Entry Id)
Treat posted entries as immutable. Post a new entry with a new source id for every correction.
The reversal key
Every posted entry stores a reversal key: <type>#<domainKeyValue>, or <type>#source:<source_ when the posting rule defines no domain key.
When a reversal event carries a matching domain key, a reversal rule resolves it directly. When a retraction carries only supersedes (the original's evt_id), look up the original in your stored deliveries to obtain its reversal key, then:
- Build
<reversedType>#<value>or take the stored reversal key fromsupersedes. - Find every entry posted under that key for this organisation.
- Post one new mirroring entry (swapping debit and credit, preserving account keys and amounts, using
<originaland descriptions starting with “Reversal of”).Line Id>:reversal - Set
sourceEntryIdto the retraction'ssource_idand narration to<type> reverses <reversal.Key>
If the lookup finds no posted entry, check whether the original is still in flight or unposted in your delivery store. If so, acknowledge the webhook and retry the reversal internally once the original lands. If the original was pending or provisional, or never existed for this endpoint, log it, acknowledge with 2xx, and post nothing. Never reverse another organisation's entry.
Delivery, retries, ordering and replay
DALP delivers at least once. See retries for backoff and the three-day retry window.
- Ordering is per endpoint. Later events wait while an earlier event retries, and linked corrections wait on their cause. Finality waits do not block later events, and replays can send older events after newer ones (ordering).
- Gaps are possible. While an endpoint is disabled (manually or after 30 consecutive failures open its circuit breaker), DALP records no events for it. Reconcile ledger totals against DALP read APIs on a schedule.
- Replay recovers recorded events. Use Resend and replay by block range or
evtIdwithin the 30-day retention window. Replayed envelopes keep the originalsource_id. For outages exceeding 30 days or disabled windows, rebuild missing entries from DALP read APIs.
Frequently asked questions
Why not post provisional events and correct them later?
A provisional event can be retracted by a chain reorganisation, creating noisy reversal entries. Final chain events wait for finality depth. trading- and trading- are the exception: DALP sends them when settlement confirms before finality depth, so reconcile trades against chain state before closing a period.
What if your rules need a field the thin payload removes?
The default thin payload strips personal data while keeping amounts and timestamps. Check the machine-readable event definitions for stripped fields, then follow the payload shape contract to switch to full or choose another field.
Next steps
- Receive DALP webhooks covers endpoint registration, signatures, and secret rotation.
- Webhook Delivery explains retries, circuit breakers, and delivery evidence.
- Platform Event explains lifecycle states and event identifiers.
- Work an operations case covers acknowledging and resolving accounting cases.
- Secrets and key handling covers the secret manager holding Xero credentials.