More billing work

This commit is contained in:
Jon Staab
2026-03-23 17:44:03 -07:00
parent 1ea087643b
commit 9491d608ae
11 changed files with 1253 additions and 637 deletions
+45 -28
View File
@@ -14,14 +14,11 @@ pub struct RelayConfig {
pub struct Tenant {
pub pubkey: String,
pub status: String,
pub tenant_nwc_url: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewTenant {
pub pubkey: String,
pub status: String,
pub tenant_nwc_url: String,
pub nwc_url: String,
pub created_at: i64,
pub billing_anchor_at: i64,
pub stripe_customer_id: String,
pub stripe_subscription_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -37,24 +34,38 @@ pub struct Relay {
pub config: Option<RelayConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Plan {
pub id: String,
pub sats_per_month: i64,
}
/// Append-only record of relay lifecycle transitions (provisioned, suspended,
/// unsuspended, deactivated). Used as the source of truth for usage metering.
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct RelayLifecycleEvent {
pub id: String,
pub relay: String,
pub tenant: String,
/// One of: "provisioned", "suspended", "unsuspended", "deactivated"
pub event_type: String,
/// Plan active on the relay at the time of the event
pub plan: String,
pub created_at: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Invoice {
pub id: String,
pub tenant: String,
pub amount: i64,
/// One of: "pending", "past_due", "paid", "void"
pub status: String,
pub created_at: String,
pub invoice: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewInvoice {
pub id: String,
pub tenant: String,
pub amount: i64,
pub status: String,
pub created_at: String,
pub invoice: String,
pub created_at: i64,
/// bolt11 invoice string (may be refreshed in-app when expired)
pub bolt11: String,
pub period_start: i64,
pub period_end: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
@@ -63,16 +74,22 @@ pub struct InvoiceItem {
pub invoice: String,
pub relay: String,
pub amount: i64,
pub period_start: String,
pub period_end: String,
pub period_start: i64,
pub period_end: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewInvoiceItem {
/// Canonical history of payment attempts. `invoices.status` is a synchronous
/// projection updated in the same transaction as each new attempt row.
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct InvoiceAttempt {
pub id: String,
pub invoice: String,
pub relay: String,
pub amount: i64,
pub period_start: String,
pub period_end: String,
/// Groups all method attempts within a single collection run
pub run_id: String,
/// One of: "nwc", "stripe", "lightning", "nip17_dm"
pub method: String,
/// One of: "success", "failed", "sent" (for DM)
pub outcome: String,
pub error: String,
pub created_at: i64,
}