summaryrefslogtreecommitdiff
path: root/internal/billing/ledger.go
diff options
context:
space:
mode:
authorChia <Chia@93.nz>2026-08-05 14:48:00 +1200
committerChia <Chia@93.nz>2026-08-05 14:48:00 +1200
commitcd0dd91ab93653631904f2ea0e574ccde6d60339 (patch)
treec65417b880a3f4a35c504c44edae821bc2122f70 /internal/billing/ledger.go
parent86b1f42e3c5601ff10621a9779cf0076590797a1 (diff)
add passkey, totp.
Diffstat (limited to '')
-rw-r--r--internal/billing/ledger.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/billing/ledger.go b/internal/billing/ledger.go
index 28cbe4c..c408cfe 100644
--- a/internal/billing/ledger.go
+++ b/internal/billing/ledger.go
@@ -73,6 +73,44 @@ func (s *Service) ListLedger(ctx context.Context, tenantID string, limit int) ([
return result, rows.Err()
}
+func (s *Service) ListTopUpOrders(ctx context.Context, tenantID string, limit int) ([]TopUpOrder, error) {
+ if limit < 1 || limit > 200 {
+ limit = 50
+ }
+ rows, err := s.db.Query(ctx, `SELECT id::text,tenant_id::text,amount_minor,amount_micros,currency,status,
+ COALESCE(stripe_session_id,''),COALESCE(checkout_url,''),created_at,paid_at FROM topup_orders
+ WHERE tenant_id=$1 ORDER BY created_at DESC LIMIT $2`, tenantID, limit)
+ if err != nil {
+ return nil, fmt.Errorf("query top-up orders: %w", err)
+ }
+ defer rows.Close()
+ result := make([]TopUpOrder, 0)
+ for rows.Next() {
+ var item TopUpOrder
+ if err := rows.Scan(&item.ID, &item.TenantID, &item.AmountMinor, &item.AmountMicros, &item.Currency, &item.Status,
+ &item.StripeSessionID, &item.CheckoutURL, &item.CreatedAt, &item.PaidAt); err != nil {
+ return nil, err
+ }
+ result = append(result, item)
+ }
+ return result, rows.Err()
+}
+
+func (s *Service) GetTopUpOrder(ctx context.Context, tenantID, orderID string) (TopUpOrder, error) {
+ var result TopUpOrder
+ err := s.db.QueryRow(ctx, `SELECT id::text,tenant_id::text,amount_minor,amount_micros,currency,status,
+ COALESCE(stripe_session_id,''),COALESCE(checkout_url,''),created_at,paid_at FROM topup_orders
+ WHERE id=$1 AND tenant_id=$2`, orderID, tenantID).Scan(&result.ID, &result.TenantID, &result.AmountMinor, &result.AmountMicros,
+ &result.Currency, &result.Status, &result.StripeSessionID, &result.CheckoutURL, &result.CreatedAt, &result.PaidAt)
+ if errors.Is(err, pgx.ErrNoRows) {
+ return TopUpOrder{}, ErrTopUpOrderNotFound
+ }
+ if err != nil {
+ return TopUpOrder{}, fmt.Errorf("get top-up order: %w", err)
+ }
+ return result, nil
+}
+
func (s *Service) AdjustBalance(ctx context.Context, input AdjustmentInput) (LedgerEntry, error) {
input.TenantID = strings.TrimSpace(input.TenantID)
input.Description = normalizeDescription(input.Description)