Skip to main content

order_payout

Firestore trigger — fires on every new document created in the orders_payout collection.
Trigger: onDocumentCreated("orders_payout/{id}")
This function is not called directly by clients. It is triggered automatically when order_process writes a new orders_payout document.

What it does

If the newly created payout document has payout_type set to any value other than "Manual", the function immediately writes a payment_reference object back to the same document:
FieldValue
payment_reference.amountThe payout amount from the document
payment_reference.dateFirestore Timestamp.now()
payment_reference.document"" (empty, to be filled later)
payment_reference.reference"ref ref ref" (placeholder)
date.updatedFirestore Timestamp.now()
Payouts created with payout_type = "Manual" (the default for non-TMT-POS orders) are left for manual reconciliation and are not updated by this trigger.

Payout document shape

The orders_payout collection stores documents with the following fields:
FieldTypeDescription
amountnumberPayout amount in base currency
amount_currencystring"USD" or "VEF"
amount_exchangenumberAmount in local currency equivalent
amount_exchange_ratenumberExchange rate applied
client_idstringClient account ID
client_namestringClient display name
custody_account.idstringCustody account ID
custody_account.namestringCustody account name
custody_account.account_numberstringBank account number
date.createdTimestampCreation time
date.payoutstringPayout execution time (filled on settlement)
descriptionstring"Pago Costo Fijo" or "Pago Costo Variable"
entitystring"TMT" or "Cliente"
event_idstringAssociated event ID
event_namestringAssociated event name
order_idstringParent order document ID
payment_dataobjectRaw payment gateway data
payment_idstringPayment method identifier
payment_namestringPayment method name
payout_statusbooleanfalse = pending, true = paid
payout_typestring"Manual" or "Automatic"

split_payout

POST https://{region}-{project}.cloudfunctions.net/split_payout
Returns a comprehensive payout summary for an event, broken down by cost type, currency (USD and VEF), and payment status (paid vs. pending). Also returns the per-cost-item allocation based on the event’s financial setup.

Request body

data.event_id
string
required
Event document ID. Used both to filter orders_payout rows and to load the event’s setup/financial document.
data.from
string
Start datetime filter applied to date_created in PostgreSQL.
data.to
string
End datetime filter applied to date_created in PostgreSQL.

Response

USD totals

data.total_cost_fijo
number
Total fixed cost (TMT) in USD across all statuses.
data.total_cost_variable_tmt
number
Total variable cost (TMT) in USD across all statuses.
data.total_cost_variable_cliente
number
Total variable cost (Client) in USD across all statuses.
data.total_cost_fijo_pagado
number
Fixed cost (TMT) USD — paid only.
data.total_cost_variable_tmt_pagado
number
Variable cost (TMT) USD — paid only.
data.total_cost_variable_cliente_pagado
number
Variable cost (Client) USD — paid only.
data.total_cost_fijo_nopagado
number
Fixed cost (TMT) USD — pending only.
data.total_cost_variable_tmt_nopagado
number
Variable cost (TMT) USD — pending only.
data.total_cost_variable_cliente_nopagado
number
Variable cost (Client) USD — pending only.

VEF totals

data.total_cost_fijo_VEF
number
Total fixed cost (TMT) in VEF across all statuses.
data.total_cost_variable_tmt_VEF
number
Total variable cost (TMT) in VEF across all statuses.
data.total_cost_variable_cliente_VEF
number
Total variable cost (Client) in VEF across all statuses.
data.total_cost_fijo_pagado_VEF
number
Fixed cost (TMT) VEF — paid only.
data.total_cost_variable_tmt_pagado_VEF
number
Variable cost (TMT) VEF — paid only.
data.total_cost_variable_cliente_pagado_VEF
number
Variable cost (Client) VEF — paid only.
data.total_cost_fijo_nopagado_VEF
number
Fixed cost (TMT) VEF — pending only.
data.total_cost_variable_tmt_nopagado_VEF
number
Variable cost (TMT) VEF — pending only.
data.total_cost_variable_cliente_nopagado_VEF
number
Variable cost (Client) VEF — pending only.

Cost line items

data.costs_fixed
array
Per-cost-item fixed cost allocations. Each item contains: name, entity ("TMT"), percentage, amaount, amaount_pagado, amaount_nopagado, amaount_VEF, amaount_pagado_VEF, amaount_nopagado_VEF.
data.costs_variables
array
Per-cost-item variable cost allocations. Each item contains: name, entity ("TMT" or "Cliente"), percentage, amaount, amaount_pagado, amaount_nopagado, amaount_VEF, amaount_pagado_VEF, amaount_nopagado_VEF.

Example

curl -X POST \
  https://{region}-{project}.cloudfunctions.net/split_payout \
  -H 'Content-Type: application/json' \
  -d '{
    "data": {
      "event_id": "evt_abc123",
      "from": "2026-01-01",
      "to": "2026-01-31"
    }
  }'

Build docs developers (and LLMs) love