Skip to main content
This page documents the functions that run as part of the order fulfillment pipeline after an order is created.

order_process

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

What it does

  1. Reads the new order document from the orders/{id} path.
  2. If data.status is true, iterates each transaction and builds a TransactionData object.
  3. For each ticket where status is false, updates the corresponding ticket document inside events/{event_id}/tickets/{ticket_id} with attendee fields: customer_email, customer_id, customer_name, customer_phone, customer_address, customer_country, and date.updated.
  4. Batch-updates those same fields in the PostgreSQL tickets table.
  5. Calls the order_user callable function to create or link the end-user account.
  6. Reads events/{event_id}/setup/financial to determine fixed and variable cost splits, then writes one or more orders_payout documents per transaction.
  7. Calls transactions_generate to finalize the transaction records.
  8. If point_sale_tmt is true on a transaction, routes to for_conciliation instead of creating payout records directly.

Payout split logic

ConditionPayout created
Fixed cost balance not fully collectedPago Costo Fijo entry for TMT
Variable cost percentage > 0Pago Costo Variable entry for TMT
Variable cost percentage > 0Pago Costo Variable entry for Cliente

order_update

This function is an internal alias used within the order pipeline. It does not expose an independent HTTP endpoint.

order_user

POST https://{region}-{project}.cloudfunctions.net/order_user
Creates a new Firebase Auth user and u_users Firestore document for the ticket purchaser if one does not already exist, then attaches the order to the user’s orders subcollection.

Request body

data.customer_email
string
required
Attendee email. Used to look up existing user accounts.
data.customer_name
string
required
Attendee full name.
data.customer_id
string
required
Attendee national ID (cédula).
data.customer_phone
string
required
Attendee phone number.
data.customer_address
string
Attendee address. Defaults to "".
data.customer_country
object
Country object { code, name, key }. Defaults to { code: "ve", name: "Venezuela", key: 0 }.
data.customer_id_type
string
ID document type prefix. Defaults to "V".
data.idorder_id
string
required
The Firestore order document ID to attach to the user.
data.OrderuserData
object
required
The full order data object written to the user’s orders subcollection.

What it does

  • Queries u_users where email == customer_email.
  • New user: creates a Firebase Auth account with a random password, writes a u_users/{uid} document, attaches the order to u_users/{uid}/orders/{order_id}, and stores the generated password in u_users/{uid}/security.
  • Existing user: attaches the order to the existing user’s orders subcollection.

Response

message
string
"procesado "
status
number
200 on success, 400 if user creation fails.
data.valido
boolean
true when the operation succeeded.

Example

curl -X POST \
  https://{region}-{project}.cloudfunctions.net/order_user \
  -H 'Content-Type: application/json' \
  -d '{
    "data": {
      "customer_email": "[email protected]",
      "customer_name": "Juan Pérez",
      "customer_id": "12345678",
      "customer_phone": "04141234567",
      "customer_id_type": "V",
      "idorder_id": "Kx9mP2qRtLwNvY4jBc",
      "OrderuserData": {}
    }
  }'

invoice_payout_status

POST https://{region}-{project}.cloudfunctions.net/invoice_payout_status
Marks payout records in PostgreSQL as paid (payout_status = true) for a given event and date range, by currency.

Request body

data.event_id
string
required
Filter payouts by event.
data.from
string
Start date filter (date_created >= from). ISO 8601 date string.
data.to
string
End date filter (date_created <= to). ISO 8601 date string.
data.vef
boolean
If true, marks all VEF-currency payout records as paid.
data.usd
boolean
If true, marks all USD-currency payout records as paid.
data.reference_number
string
required
The bank transfer or payment reference number to record against each updated row.

Example

curl -X POST \
  https://{region}-{project}.cloudfunctions.net/invoice_payout_status \
  -H 'Content-Type: application/json' \
  -d '{
    "data": {
      "event_id": "evt_abc123",
      "from": "2026-01-01",
      "to": "2026-01-31",
      "vef": true,
      "usd": false,
      "reference_number": "REF-20260131-001"
    }
  }'

process_order_billing

POST https://{region}-{project}.cloudfunctions.net/process_order_billing
Emits an invoice for a completed order. This function runs independently to avoid timeout issues in order_process. It resolves the purchaser’s full profile from u_users, fetches client data from u_clients, generates a sequential invoice number, and calls the billing core.

Request body

data.order_id
string
required
Firestore order document ID.
data.order_data
object
required
Full order data object (same shape as the orders Firestore document).
data.event_id
string
required
Event document ID.
data.event_name
string
required
Event display name.
data.office_id
string
required
Box office document ID.
data.office_name
string
required
Box office display name.
data.exchange_rate
number
required
VEF/USD exchange rate to use for invoice line items.

What it does

  1. Resolves the purchaser’s full profile by looking up order_data.purchaser_info.email in u_users.
  2. Fetches client (tercero) details from u_clients/{client_id}.
  3. Calls getNextInvoiceNumber() for a sequential, unique invoice number.
  4. Calls generateBillingDataFromOrder() and then emitirFacturaCore().
  5. On success, updates the orders/{order_id} document with billing_info: { billed: true, billing_date, billing_result }.

Response

message
string
"Facturación completada exitosamente" on success, "Error en facturación" on billing failure.
status
number
200 on success, 400 on billing error, 500 on critical error.
data.success
boolean
true when billing succeeded.
data.order_id
string
The order ID that was billed.
data.billing_result
object
The raw billing result object returned by the billing core.

Example

curl -X POST \
  https://{region}-{project}.cloudfunctions.net/process_order_billing \
  -H 'Content-Type: application/json' \
  -d '{
    "data": {
      "order_id": "Kx9mP2qRtLwNvY4jBc",
      "order_data": { "purchaser_info": { "email": "[email protected]" }, "client_id": "client_001" },
      "event_id": "evt_abc123",
      "event_name": "Gran Concierto 2026",
      "office_id": "off_xyz",
      "office_name": "Taquilla Central",
      "exchange_rate": 36.50
    }
  }'

split_queries

POST https://{region}-{project}.cloudfunctions.net/split_queries
Returns a breakdown of payout amounts by cost category (fixed TMT, variable TMT, variable Client) for a given event and date range, with each line item split by the cost definitions in the event’s financial setup.

Request body

data.event_id
string
required
Event document ID. Used to filter payouts and to load the event’s financial setup.
data.from
string
Start datetime filter (date_created >= from).
data.to
string
End datetime filter (date_created <= to).

Response

data.total_cost_fijo
number
Total fixed cost collected by TMT (USD).
data.total_cost_variable_tmt
number
Total variable cost collected by TMT (USD).
data.total_cost_variable_cliente
number
Total variable cost allocated to the Client (USD).
data.costs_fixed
array
Array of fixed cost line items from the event’s financial setup, each with: name, amaount, entity, percentage.
data.costs_variables
array
Array of variable cost line items, each with: name, amaount, entity, percentage.

Example

curl -X POST \
  https://{region}-{project}.cloudfunctions.net/split_queries \
  -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