Transaction codes
Posting templates. Define the entries once, then create transactions by code and parameters.
Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /trancodes | List transaction code templates |
| POST | /trancodes | Create a transaction code template |
| GET | /trancodes/{id} | Get a specific transaction code template |
| PUT | /trancodes/{id} | Update a transaction code template (increments version) |
| POST | /trancodes/{id}/deprecate | Mark a transaction code as deprecated (one-way state transition) |
| POST | /trancodes/{id}/validate-params | Validate a parameter payload against a transaction code's params_schema |
Define a template
entries_template needs at least two entries. account and amount take a literal, a {params.NAME} reference, or an expression in braces ({params.amount * 1.05}, {round(params.amount * 0.025)}). params_schema is a JSON-Schema fragment the server validates params against.
curl -X POST https://ledga.io/api/v1/trancodes \
-H "Authorization: Bearer sk_xxxxxxxx_your_secret" \
-H "Content-Type: application/json" \
-d '{
"code": "BOOK_TRANSFER",
"name": "Book transfer",
"params_schema": {
"type": "object",
"required": ["amount", "from_account", "to_account"],
"properties": {
"amount": { "type": "string" },
"from_account": { "type": "string" },
"to_account": { "type": "string" }
}
},
"entries_template": {
"entries": [
{ "account": "{params.from_account}", "type": "credit", "amount": "{params.amount}" },
{ "account": "{params.to_account}", "type": "debit", "amount": "{params.amount}" }
]
}
}'$code = $ledga->transactionCodes->create([
'code' => 'BOOK_TRANSFER',
'name' => 'Book transfer',
'params_schema' => [
'type' => 'object',
'required' => ['amount', 'from_account', 'to_account'],
'properties' => [
'amount' => ['type' => 'string'],
'from_account' => ['type' => 'string'],
'to_account' => ['type' => 'string'],
],
],
'entries_template' => ['entries' => [
['account' => '{params.from_account}', 'type' => 'credit', 'amount' => '{params.amount}'],
['account' => '{params.to_account}', 'type' => 'debit', 'amount' => '{params.amount}'],
]],
]);Invoke it with POST /transactions — see Transactions.
Rules
codeis immutable: uppercase letters, digits,-,_.PUT /trancodes/{id}incrementsversion;codeandstatuscannot change.POST /trancodes/{id}/deprecateis one-way. Deprecated codes cannot be invoked.POST /trancodes/{id}/validate-paramschecks a payload without posting.attributes_templatestamps attributes onto every generated transaction.