Files
member-console/internal/billing/queries/payments.sql
2026-04-06 03:15:20 -05:00

38 lines
949 B
SQL

-- name: CreatePayment :one
INSERT INTO billing.payments (
invoice_id, billing_account_id, payment_method_id,
amount, currency, status, failed_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING *;
-- name: GetPaymentByID :one
SELECT * FROM billing.payments
WHERE payment_id = $1;
-- name: GetPaymentsByInvoiceID :many
SELECT * FROM billing.payments
WHERE invoice_id = $1
ORDER BY created_at DESC;
-- name: ListPayments :many
SELECT
p.payment_id,
p.invoice_id,
p.billing_account_id,
p.payment_method_id,
p.amount,
p.currency,
p.status,
p.failed_at,
p.created_at,
p.updated_at,
ba.name as billing_account_name,
pm.pm_type as payment_method_type,
pm.card_brand,
pm.card_last4
FROM billing.payments p
JOIN billing.accounts ba ON p.billing_account_id = ba.billing_account_id
LEFT JOIN billing.payment_methods pm ON p.payment_method_id = pm.payment_method_id
ORDER BY p.created_at DESC;