Xero Payments SQL Template

SQL table creation template for syncing Xero payment data to your PostgreSQL database.

Updated: 9 Feb 2026

Xero Payments SQL Template

Create a database table to store Xero payment data including amounts, payment types, linked invoices, and currency details.

What Data is Synced?

The Xero Payments sync captures essential payment information from your Xero account:

  • Payment ID: Unique Xero payment identifier
  • Tenant ID: Xero organization ID for multi-org support
  • Payment Date: Date the payment was made
  • Amount: Payment amount
  • Status: AUTHORISED or DELETED
  • Payment Type: ACCRECPAYMENT, ACCPAYPAYMENT, etc.
  • Invoice ID: Linked invoice identifier
  • Currency: Three-letter currency code
  • Complete Data: Full Xero payment object stored as JSONB
  • Sync Tracking: Timestamp of when CLS last synced this record

SQL Table Template

Table Schema Explanation

Here's what each column in the table represents:

ColumnTypeDescription
idTEXTXero payment ID. Part of composite primary key.
tenant_idTEXTXero organization ID. Part of composite primary key.
payment_dateDATEDate the payment was made.
amountNUMERIC(15,2)Payment amount.
statusTEXTPayment status: AUTHORISED or DELETED.
payment_typeTEXTType: ACCRECPAYMENT (receivable), ACCPAYPAYMENT (payable), etc.
invoice_idTEXTXero invoice ID this payment is applied to.
currency_codeTEXTThree-letter ISO currency code (e.g., GBP, USD).
dataJSONBComplete Xero payment object stored as JSON.
livemodeBOOLEANWhether this is production data.
updated_date_utcTIMESTAMPTZTimestamp when payment was last modified in Xero.
synced_atTIMESTAMPTZTimestamp when CLS last synced this payment record. Auto-updated.

The table uses a composite primary key (id, tenant_id) to support syncing payments from multiple Xero organizations to the same table.

Usage Examples

After syncing, you can query your payment data using standard SQL:

-- Get all payments ordered by date
SELECT id, payment_date, amount, payment_type, status
FROM xero_payments
WHERE status = 'AUTHORISED'
ORDER BY payment_date DESC;

-- Calculate total payments received by month
SELECT
  DATE_TRUNC('month', payment_date) AS month,
  SUM(amount) AS total_received
FROM xero_payments
WHERE payment_type = 'ACCRECPAYMENT' AND status = 'AUTHORISED'
GROUP BY DATE_TRUNC('month', payment_date)
ORDER BY month DESC;

-- Get payments for a specific invoice
SELECT * FROM xero_payments
WHERE invoice_id = 'invoice_id'
ORDER BY payment_date DESC;

-- Breakdown by payment type
SELECT payment_type, COUNT(*) as count, SUM(amount) as total
FROM xero_payments
WHERE status = 'AUTHORISED'
GROUP BY payment_type;

-- Get payments by currency
SELECT currency_code, COUNT(*) as count, SUM(amount) as total
FROM xero_payments
WHERE status = 'AUTHORISED'
GROUP BY currency_code
ORDER BY total DESC;

-- Find recent payments
SELECT id, payment_date, amount, payment_type
FROM xero_payments
WHERE payment_date > CURRENT_DATE - INTERVAL '30 days'
  AND status = 'AUTHORISED'
ORDER BY payment_date DESC;

-- Get payments for a specific organization
SELECT * FROM xero_payments
WHERE tenant_id = 'your_tenant_id'
  AND status = 'AUTHORISED'
ORDER BY payment_date DESC;

-- Calculate receivable vs payable totals
SELECT
  payment_type,
  COUNT(*) AS payment_count,
  SUM(amount) AS total_amount
FROM xero_payments
WHERE status = 'AUTHORISED'
GROUP BY payment_type;

Common Customizations

The template includes performance indexes for tenant_id, payment_date, invoice_id, status, payment_type, currency_code, livemode, and updated_date_utc columns. You can add additional table-specific customizations:

Add Index for Amount-Based Queries

CREATE INDEX idx_xero_payments_amount
ON xero_payments(amount)
WHERE status = 'AUTHORISED';

Add Compound Index for Date Range Queries by Type

CREATE INDEX idx_xero_payments_type_date
ON xero_payments(payment_type, payment_date)
WHERE status = 'AUTHORISED';