To correct mistakes, you can reverse a Ledger Entry that you've posted to FRAGMENT. Reversing a Ledger Entry posts a new Ledger Entry that offsets the original Ledger Entry.
Call the reverseLedgerEntry mutation to reverse a posted Ledger Entry:
mutation ReverseLedgerEntry(
$id: ID!
) {
reverseLedgerEntry(
id: $id
) {
__typename
... on ReverseLedgerEntryResult {
reversingLedgerEntry {
ik
id
type
posted
created
reverses {
id
created
}
reversalPosition
}
reversedLedgerEntry {
ik
id
type
posted
created
reversedBy {
id
created
}
reversalPosition
reversedAt
}
isIkReplay
}
... on Error {
code
message
}
}
}{
"id": "<ID of the entry to reverse>"
}You cannot reverse a Ledger Entry using ik because the reversing, reversed, and any subsequent reposting of the Ledger Entry will all share the same ik. This ensures all versions of a Ledger Entry are idempotent. Attempting to reverse a reversing Ledger Entry will return isIkReplay: true.
The new, reversing, Ledger Entry will have:
amount values in the same currency as the original Ledger Entry.posted timestamp as the original Ledger Entry. This ensures that the net balance change at the posted timestamp is 0.created timestamp, set to the time of posting.reverses field that points to the original Ledger Entry.reversalPosition value of one greater than the original Ledger Entry. This position value is 1 indexed.The reversed Ledger Entry will be updated to include:
reversedBy field that points to the reversing Ledger Entry.reversedAt timestamp that is the created timestamp of the reversing Ledger Entry.After calling reverseLedgerEntry, both the reversing and reversed Ledger Entries are immutable and can no longer be updated using updateLedgerEntry.
Once a Ledger Entry has been reversed, it can be reposted by using the same ik value. Any Entry Type can be used for the reposted Ledger Entry. To do so, simply use the addLedgerEntry or reconcileTx mutation.
mutation AddLedgerEntry(
$ik: SafeString!
$entry: LedgerEntryInput!
) {
addLedgerEntry(
ik: $ik,
entry: $entry
) {
__typename
... on AddLedgerEntryResult {
entry {
type
created
posted
reversalPosition
}
lines {
amount
key
description
account {
path
}
}
}
... on Error {
code
message
}
}
}{
"ik": "add-ledger-entry",
"entry": {
"ledger": {
"ik": "quickstart-ledger"
},
"type": "user_funds_account",
"posted": "1234-01-01T01:01:01",
"parameters": {
"user_id": "testing-user",
"funding_amount": "400"
}
}
}mutation ReconcileTx(
$entry: LedgerEntryInput!
) {
reconcileTx(
entry: $entry
) {
... on ReconcileTxResult {
entry {
type
created
posted
reversalPosition
}
lines {
amount
key
description
account {
path
}
}
}
... on Error {
code
message
}
}
}{
"entry": {
"type": "user_funding",
"ledger": {
"ik": "quickstart-ledger"
},
"parameters": {
"txId": "tx_12345",
"customerId": "customer-1"
}
}
}The newly posted Ledger Entry will have a reversalPosition value of one greater than the previous reversal Ledger Entry.
Use the ledgerEntryHistory query to get the full history of a Ledger Entry with reversals. Lookups by IK for a reversing or reversed Ledger Entry will return a ledger_entry_not_found BadRequestError.
Additionally, Ledger Entries have a reversalHistory field that returns a list of all Ledger Entries and their reversals that share an ik.