OrderData structure
The following fields are written to theorders collection by order_created and mirrored to the orders PostgreSQL table.
| Field | Type | Description |
|---|---|---|
amount | number | Total order value in base currency |
date.created | Timestamp | Server timestamp set at creation |
date.updated | Timestamp | Updated each time the order is modified |
event_id | string | Firestore ID of the parent event |
event_name | string | Display name of the event |
office_id | string | ID of the box office that processed the sale |
office_name | string | Display name of the box office |
client_id | string | ID of the event organizer (client) |
client_name | string | Display name of the event organizer |
box_office_id | string | ID of the physical point of sale |
box_office_name | string | Display name of the physical point of sale |
status | string | Order status string passed by the caller |
status_type.id | string | Always "completed" on creation |
status_type.name | string | Always "Completada" on creation |
exchange_rate | number | Exchange rate applied to foreign-currency payments |
tickets | array | List of ticket objects included in the order |
transactions | array | List of transaction objects (one per payment method) |
purchaser_info | object|null | Purchaser details if provided |
recipient_info | object|null | Recipient details if provided |
is_courtesy | boolean | true if this is a complimentary order |
is_corporate | boolean | true for corporate purchases |
is_gift | boolean | true if tickets are being gifted |
distribution | array | Payout distribution records (written by order_process) |
billing_info | object | Billing result added by process_order_billing |
Ticket item structure
Each entry in thetickets array represents one seat in the order:
ticket_id is a composite key in the format {event_id}-{firestore_doc_id}. order_process splits this value on the - character to locate the ticket document at events/{event_id}/tickets/{ticket_doc_id}.Lifecycle flow
order_created — write the order
An HTTP POST from the point-of-sale client submits the full order payload. The function:
- Builds the
OrderDataobject with server-side timestamps. - Writes it to the
ordersFirestore collection. - Inserts a matching row into the
ordersPostgreSQL table. - Returns the new Firestore document ID.
order_process via the onDocumentCreated Firestore trigger.order_process — process tickets, payouts, and transactions
Fired automatically when a new document appears in the
orders collection. The function:- Iterates the
ticketsarray and updates customer metadata on eachevents/{id}/tickets/{id}document via a batched Firestore write, and updates theticketsPostgreSQL table. - Calls
order_userto register the order under the buyer’s user profile (creating au_usersaccount if none exists). - Reads the event’s
setup/financialdocument to calculate the fixed-cost and variable-cost split. - Writes
orders_payoutrecords to Firestore and PostgreSQL for both TMT (platform) and Client (organizer) shares. - Updates the order document with the
distributionarray. - Calls
transactions_generateto createorders_transactionsrecords and mark tickets as sold.
order_user — register the order on the buyer's profile
Called internally by
order_process. Looks up the buyer by customer_email in u_users.- If a user record exists, the order is written to
u_users/{uid}/orders/{order_id}. - If no user record exists, a Firebase Auth account and
u_usersdocument are created automatically using the buyer’s details fromticket.metadata. A random temporary password is stored inu_users/{uid}/security.
order_payout — handle non-manual payout references
A Firestore trigger on
orders_payout/{id}. When a new payout record has payout_type != "Manual", the function writes a payment_reference object back to the payout document containing the amount, timestamp, and a placeholder reference string.Manual payouts (the default) are not touched by this trigger — they are settled through invoice_payout_status.invoice_payout_status — mark payouts as settled
An HTTP function used by finance staff to confirm that a batch of payout obligations has been paid. Filters
orders_payout records by event_id, date range, and currency (vef / usd flags), then sets payout_status = true and records a reference_number on all matching rows in PostgreSQL.process_order_billing — generate the invoice
An independent HTTP function called after order creation to trigger invoice generation without blocking the main order flow. It:
- Enriches
purchaser_infofrom theu_userscollection. - Fetches client (tercero) data from
u_clients. - Calls
getNextInvoiceNumber()for a sequential invoice number. - Builds billing data via
generateBillingDataFromOrder()and emits the invoice viaemitirFacturaCore(). - On success, writes a
billing_infoobject back to the order document.
Function reference
order_created
Creates a new order in Firestore and PostgreSQL. Trigger:POST /order_created
Request
Response
true when the order was created successfully.The Firestore document ID of the newly created order.
split_queries
Returns a summary of payout distribution for an event across a date range. Queries theorders_payout PostgreSQL table grouped by entity and description.
Trigger: POST /split_queries
Request
The event to query.
Start of the date range (ISO 8601). Filters on
date_created >= from.End of the date range (ISO 8601). Filters on
date_created <= to.Response
split_payout
Returns a detailed payout breakdown for an event, split by currency (USD/VEF) and payment status (payout_status = true/false). Used by finance to reconcile what has been paid versus what is outstanding.
Trigger: POST /split_payout
Request
The event to query.
Start of the date range (ISO 8601).
End of the date range (ISO 8601).
total_cost_fijo, total_cost_variable_tmt, and total_cost_variable_cliente, each with _pagado (paid), _nopagado (unpaid), and _VEF (bolivar-denominated) variants.
invoice_payout_status
Marks a batch oforders_payout records as settled in PostgreSQL.
Trigger: POST /invoice_payout_status
Request
The event whose payouts are being settled.
Start date filter (ISO 8601).
End date filter (ISO 8601).
If
true, marks VEF-denominated payout records as paid.If
true, marks USD-denominated payout records as paid.The payment reference to record on settled rows.
process_order_billing
Triggers invoice generation for a completed order. Run separately fromorder_process to avoid Cloud Function timeouts.
Trigger: POST /process_order_billing
Request
The Firestore document ID of the order to invoice.
The full order data object (same shape as the
orders document).The event ID.
The event display name.
The office ID.
The office display name.
The exchange rate used for currency conversion on the invoice.