Skip to workflow content
Vora
← Workflow library

Finance Operations

Reconcile identity-linked payment reversals

Conserve positive integer minor-unit principal using exact payment references, posted-state rules and explicit currency identity. Supplied facts only; returns a review packet with no external effects.

Experimental native example · local preview · revision 1

WORKFLOW PREVIEW

See how it works

2 nodes · 1 connections

Use + and − to zoom, F to fit. Press Enter on a node to inspect it.

Private preview. These tested drafts are available for inspection. Adding them to a Vora workspace is still being tested.

What you need

  • Authorized supplied facts matching the closed contract.
  • Explicit scope, version, authority and completeness facts reviewed by an operator.
Follow the workflow step by step
  1. Supplied agency data

    Receive the explicitly supplied manual input packet.

  2. Reconcile identity-linked payment reversals

    Conserve positive integer minor-unit principal using exact payment references, posted-state rules and explicit currency identity. Supplied facts only; returns a review packet with no external effects.

Setup and review

  • Review the contract and evidence bounds.
  • Run a synthetic supplied-data case.
  • Inspect every conflict, omission and unknown before proposing downstream action.

Inspect every node

Expand a node to inspect its complete settings. Review the runtime and adoption evidence before installing it.

Supplied agency data · wfManualTrigger
{
  "label": "Supplied agency data"
}
Reconcile identity-linked payment reversals · code
{
  "code": "\nfunction fail(reason){throw new Error('input: '+reason);}\nfunction check(schema,value,where){\n if(value===null){if(schema.type==='null'||Array.isArray(schema.type)&&schema.type.includes('null'))return;fail(where+' wrong_type');}\n const type=Array.isArray(schema.type)?schema.type[0]:schema.type;\n if(type==='object'){\n  if(!value||typeof value!=='object'||Array.isArray(value))fail(where+' wrong_type');\n  for(const name of Object.keys(value))if(!Object.hasOwn(schema.properties,name))fail(where+' unknown_field');\n  for(const name of schema.required)if(!Object.hasOwn(value,name))fail(where+' missing_field');\n  for(const [name,shape]of Object.entries(schema.properties))check(shape,value[name],where+'.'+name);\n }else if(type==='array'){\n  if(!Array.isArray(value)||value.length>schema.maxItems)fail(where+' array_bound');\n  for(const item of value)check(schema.items,item,where+'[]');\n }else if(type==='string'){if(typeof value!=='string'||value.length>schema.maxLength)fail(where+' string_bound');}\n else if(type==='integer'){if(!Number.isSafeInteger(value)||value<schema.minimum||value>schema.maximum)fail(where+' integer_bound');}\n else if(type==='boolean'){if(typeof value!=='boolean')fail(where+' wrong_type');}\n else fail(where+' unsupported_type');\n}\nfunction id(value){if(typeof value!=='string'||!value||value.trim()!==value)fail('noncanonical_identity');return value;}\nfunction unique(values,reason){if(new Set(values).size!==values.length)fail(reason);}\nfunction safeAdd(a,b){if(a>Number.MAX_SAFE_INTEGER-b)fail('unsafe_sum');return a+b;}\nfunction day(value){if(!/^\\d{4}-\\d{2}-\\d{2}$/.test(value))fail('invalid_calendar_day');const ms=Date.parse(value+'T00:00:00Z');if(!Number.isFinite(ms)||new Date(ms).toISOString().slice(0,10)!==value)fail('invalid_calendar_day');return ms;}\nfunction refKey(ref){id(ref.assetId);if(ref.version<1)fail('positive_version_required');return JSON.stringify([ref.assetId,ref.version]);}\nfunction refValue(key){const pair=JSON.parse(key);return {assetId:pair[0],version:pair[1]};}\nfunction sortedRefs(keys){return [...keys].sort().map(refValue);}\n\ncheck({\"type\":\"object\",\"properties\":{\"scopeId\":{\"type\":\"string\",\"maxLength\":128},\"currency\":{\"type\":\"string\",\"maxLength\":128},\"inputComplete\":{\"type\":[\"boolean\",\"null\"]},\"events\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"eventId\":{\"type\":\"string\",\"maxLength\":128},\"revision\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":9007199254740991},\"kind\":{\"type\":\"string\",\"maxLength\":128},\"state\":{\"type\":\"string\",\"maxLength\":128},\"amountMinor\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":9007199254740991},\"currency\":{\"type\":\"string\",\"maxLength\":128},\"originalPaymentId\":{\"type\":[\"string\",\"null\"],\"maxLength\":128}},\"required\":[\"eventId\",\"revision\",\"kind\",\"state\",\"amountMinor\",\"currency\",\"originalPaymentId\"],\"additionalProperties\":false},\"maxItems\":100}},\"required\":[\"scopeId\",\"currency\",\"inputComplete\",\"events\"],\"additionalProperties\":false},context.input,\"input\");\nconst result=(function paymentReversalConservation(x){\n id(x.scopeId);id(x.currency);\n const groups=new Map();\n for(const row of x.events){\n  id(row.eventId);id(row.currency);\n  if(row.revision<1)fail('positive_revision_required');\n  if(!['payment','reversal'].includes(row.kind))fail('invalid_event_kind');\n  if(!['posted','pending'].includes(row.state))fail('invalid_event_state');\n  if(row.amountMinor<=0)fail('positive_amount_required');\n  if(row.kind==='payment'&&row.originalPaymentId!==null)fail('invalid_payment_reference');\n  if(row.kind==='reversal'){if(row.originalPaymentId===null)fail('reversal_reference_required');id(row.originalPaymentId);}\n  if(!groups.has(row.eventId))groups.set(row.eventId,[]);groups.get(row.eventId).push(row);\n }\n const resolved=[],identical=[],conflicting=[];\n for(const [eventId,rows]of groups){\n  const signatures=new Set(rows.map(r=>JSON.stringify([r.revision,r.kind,r.state,r.amountMinor,r.currency,r.originalPaymentId])));\n  if(signatures.size>1){conflicting.push(eventId);continue;}\n  if(rows.length>1)identical.push(eventId);resolved.push(rows[0]);\n }\n const paymentsById=new Map(resolved.filter(r=>r.kind==='payment').map(r=>[r.eventId,r]));\n const posted=resolved.filter(r=>r.kind==='payment'&&r.state==='posted'&&r.currency===x.currency);\n const reversals=resolved.filter(r=>r.kind==='reversal'),currencyConflicts=new Set(resolved.filter(r=>r.currency!==x.currency).map(r=>r.eventId)),orphans=[],unposted=[],sums=new Map();\n for(const row of reversals){\n  const original=paymentsById.get(row.originalPaymentId);\n  if(!original){orphans.push(row.eventId);continue;}\n  if(row.currency!==original.currency||row.currency!==x.currency){currencyConflicts.add(row.eventId);continue;}\n  if(row.state==='posted'&&original.state!=='posted'){unposted.push(row.eventId);continue;}\n  if(row.state==='posted'&&original.state==='posted')sums.set(original.eventId,safeAdd(sums.get(original.eventId)||0,row.amountMinor));\n }\n const over=[],paymentResults=[];let principal=0,totalReversed=0;\n for(const original of posted){\n  principal=safeAdd(principal,original.amountMinor);\n  const reversed=sums.get(original.eventId)||0;totalReversed=safeAdd(totalReversed,reversed);\n  const excess=reversed>original.amountMinor;\n  if(excess)over.push(original.eventId);\n  const invalidLinkedCurrency=reversals.some(r=>r.originalPaymentId===original.eventId&&currencyConflicts.has(r.eventId));\n  paymentResults.push({paymentId:original.eventId,postedPrincipalMinor:original.amountMinor,linkedPostedReversalMinor:reversed,knownNetMinor:excess||invalidLinkedCurrency?null:original.amountMinor-reversed});\n }\n paymentResults.sort((a,b)=>a.paymentId<b.paymentId?-1:a.paymentId>b.paymentId?1:0);\n const conflict=conflicting.length>0||currencyConflicts.size>0||unposted.length>0||over.length>0;\n const status=conflict?'conflict':x.inputComplete!==true||orphans.length?'unknown':'conserved';\n return {status,currency:x.currency,inputComplete:x.inputComplete,postedPrincipalMinor:principal,conservedNetMinor:status==='conserved'?principal-totalReversed:null,payments:paymentResults,pendingEventIds:resolved.filter(r=>r.state==='pending').map(r=>r.eventId).sort(),identicalDuplicateEventIds:identical.sort(),conflictingEventIds:conflicting.sort(),currencyConflictIds:[...currencyConflicts].sort(),orphanReversalIds:orphans.sort(),unpostedReferenceReversalIds:unposted.sort(),overReversedPaymentIds:over.sort()};\n})(context.input);\ncheck({\"type\":\"object\",\"properties\":{\"status\":{\"type\":\"string\",\"maxLength\":128},\"currency\":{\"type\":\"string\",\"maxLength\":128},\"inputComplete\":{\"type\":[\"boolean\",\"null\"]},\"postedPrincipalMinor\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":9007199254740991},\"conservedNetMinor\":{\"type\":[\"integer\",\"null\"],\"minimum\":0,\"maximum\":9007199254740991},\"payments\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"paymentId\":{\"type\":\"string\",\"maxLength\":128},\"postedPrincipalMinor\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":9007199254740991},\"linkedPostedReversalMinor\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":9007199254740991},\"knownNetMinor\":{\"type\":[\"integer\",\"null\"],\"minimum\":0,\"maximum\":9007199254740991}},\"required\":[\"paymentId\",\"postedPrincipalMinor\",\"linkedPostedReversalMinor\",\"knownNetMinor\"],\"additionalProperties\":false},\"maxItems\":100},\"pendingEventIds\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"maxLength\":128},\"maxItems\":100},\"identicalDuplicateEventIds\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"maxLength\":128},\"maxItems\":100},\"conflictingEventIds\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"maxLength\":128},\"maxItems\":100},\"currencyConflictIds\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"maxLength\":128},\"maxItems\":100},\"orphanReversalIds\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"maxLength\":128},\"maxItems\":100},\"unpostedReferenceReversalIds\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"maxLength\":128},\"maxItems\":100},\"overReversedPaymentIds\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"maxLength\":128},\"maxItems\":100}},\"required\":[\"status\",\"currency\",\"inputComplete\",\"postedPrincipalMinor\",\"conservedNetMinor\",\"payments\",\"pendingEventIds\",\"identicalDuplicateEventIds\",\"conflictingEventIds\",\"currencyConflictIds\",\"orphanReversalIds\",\"unpostedReferenceReversalIds\",\"overReversedPaymentIds\"],\"additionalProperties\":false},result,\"output\");\nreturn result;",
  "label": "Reconcile identity-linked payment reversals",
  "memoryLimit": 16,
  "outputVar": "result",
  "timeout": 1000
}
Input and output contracts

Input

{
  "type": "object",
  "properties": {
    "scopeId": {
      "type": "string",
      "maxLength": 128
    },
    "currency": {
      "type": "string",
      "maxLength": 128
    },
    "inputComplete": {
      "type": [
        "boolean",
        "null"
      ]
    },
    "events": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "eventId": {
            "type": "string",
            "maxLength": 128
          },
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "kind": {
            "type": "string",
            "maxLength": 128
          },
          "state": {
            "type": "string",
            "maxLength": 128
          },
          "amountMinor": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "currency": {
            "type": "string",
            "maxLength": 128
          },
          "originalPaymentId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 128
          }
        },
        "required": [
          "eventId",
          "revision",
          "kind",
          "state",
          "amountMinor",
          "currency",
          "originalPaymentId"
        ],
        "additionalProperties": false
      },
      "maxItems": 100
    }
  },
  "required": [
    "scopeId",
    "currency",
    "inputComplete",
    "events"
  ],
  "additionalProperties": false
}

Output

{
  "type": "object",
  "properties": {
    "status": {
      "type": "string",
      "maxLength": 128
    },
    "currency": {
      "type": "string",
      "maxLength": 128
    },
    "inputComplete": {
      "type": [
        "boolean",
        "null"
      ]
    },
    "postedPrincipalMinor": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "conservedNetMinor": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "payments": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "paymentId": {
            "type": "string",
            "maxLength": 128
          },
          "postedPrincipalMinor": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "linkedPostedReversalMinor": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "knownNetMinor": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "paymentId",
          "postedPrincipalMinor",
          "linkedPostedReversalMinor",
          "knownNetMinor"
        ],
        "additionalProperties": false
      },
      "maxItems": 100
    },
    "pendingEventIds": {
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 128
      },
      "maxItems": 100
    },
    "identicalDuplicateEventIds": {
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 128
      },
      "maxItems": 100
    },
    "conflictingEventIds": {
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 128
      },
      "maxItems": 100
    },
    "currencyConflictIds": {
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 128
      },
      "maxItems": 100
    },
    "orphanReversalIds": {
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 128
      },
      "maxItems": 100
    },
    "unpostedReferenceReversalIds": {
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 128
      },
      "maxItems": 100
    },
    "overReversedPaymentIds": {
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 128
      },
      "maxItems": 100
    }
  },
  "required": [
    "status",
    "currency",
    "inputComplete",
    "postedPrincipalMinor",
    "conservedNetMinor",
    "payments",
    "pendingEventIds",
    "identicalDuplicateEventIds",
    "conflictingEventIds",
    "currencyConflictIds",
    "orphanReversalIds",
    "unpostedReferenceReversalIds",
    "overReversedPaymentIds"
  ],
  "additionalProperties": false
}

Choose an output for this job

This business workflow also has 15 delivery formats. Compare their inputs, output examples and limits.

Compare implementations for this job

Example input and result

These examples use synthetic data.

Input

{
  "scopeId": "client-A",
  "currency": "USD",
  "inputComplete": true,
  "events": [
    {
      "eventId": "pay-A",
      "revision": 1,
      "kind": "payment",
      "state": "posted",
      "amountMinor": 1000,
      "currency": "USD",
      "originalPaymentId": null
    },
    {
      "eventId": "rev-A",
      "revision": 1,
      "kind": "reversal",
      "state": "posted",
      "amountMinor": 300,
      "currency": "USD",
      "originalPaymentId": "pay-A"
    }
  ]
}

Expected result

{
  "status": "conserved",
  "currency": "USD",
  "inputComplete": true,
  "postedPrincipalMinor": 1000,
  "conservedNetMinor": 700,
  "payments": [
    {
      "paymentId": "pay-A",
      "postedPrincipalMinor": 1000,
      "linkedPostedReversalMinor": 300,
      "knownNetMinor": 700
    }
  ],
  "pendingEventIds": [],
  "identicalDuplicateEventIds": [],
  "conflictingEventIds": [],
  "currencyConflictIds": [],
  "orphanReversalIds": [],
  "unpostedReferenceReversalIds": [],
  "overReversedPaymentIds": []
}

Success means: Conserve positive integer minor-unit principal using exact payment references, posted-state rules and explicit currency identity. Supplied facts only; returns a review packet with no external effects.

When something goes wrong

  • Correct the rejected shape, identity, scope or numeric bound and repeat with supplied facts. Preserve unknown and conflicting facts rather than invent a resolution.

Limits and costs

  • Amounts are positive safe integers in supplied minor units. Kind is payment or reversal; state is posted or pending. Payment originalPaymentId is null; reversal references an exact payment event ID. Identical duplicate event+revision facts collapse; differing facts or revisions for one event ID conflict without choosing latest. Posted payments supply principal; posted linked same-currency reversals reduce it; pending events do not. Orphans/incomplete input keep total unknown; currency/version/over-reversal/unposted-reference conflicts block a conserved total. No FX, clamping, unrelated subtraction or refund. Unsafe sums fail. Per-payment known subtotals describe supplied facts only. Pure supplied-data processing; no independent provider, legal, authentication or customer-acceptance verification.
  • No paid model calls or metered third-party operations are declared in this pure graph. Vora plan availability, compute and quotas still apply; pricing has not been verified by this batch.

USE IN VORA

Reconcile identity-linked payment reversals

Review this workflow’s steps and required inputs. Get access to Vora before setting it up in your workspace.

Workspace installation is being connected. This page lets you inspect the workflow; it does not create or run one.

Required input fields
{
  "type": "object",
  "properties": {
    "scopeId": {
      "type": "string",
      "maxLength": 128
    },
    "currency": {
      "type": "string",
      "maxLength": 128
    },
    "inputComplete": {
      "type": [
        "boolean",
        "null"
      ]
    },
    "events": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "eventId": {
            "type": "string",
            "maxLength": 128
          },
          "revision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "kind": {
            "type": "string",
            "maxLength": 128
          },
          "state": {
            "type": "string",
            "maxLength": 128
          },
          "amountMinor": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "currency": {
            "type": "string",
            "maxLength": 128
          },
          "originalPaymentId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 128
          }
        },
        "required": [
          "eventId",
          "revision",
          "kind",
          "state",
          "amountMinor",
          "currency",
          "originalPaymentId"
        ],
        "additionalProperties": false
      },
      "maxItems": 100
    }
  },
  "required": [
    "scopeId",
    "currency",
    "inputComplete",
    "events"
  ],
  "additionalProperties": false
}