From c02d834fe0b652ef7864ee420dbb20ddb3280b13 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Thu, 21 May 2026 14:29:38 -0700 Subject: [PATCH] Remove some stripe proxy methods --- backend/src/api.rs | 8 ++++++++ backend/src/billing.rs | 26 -------------------------- backend/src/main.rs | 4 +++- backend/src/routes/invoices.rs | 4 ++-- backend/src/routes/stripe.rs | 4 ++-- backend/src/routes/tenants.rs | 10 ++++++++-- 6 files changed, 23 insertions(+), 33 deletions(-) diff --git a/backend/src/api.rs b/backend/src/api.rs index 5c62304..7a0844f 100644 --- a/backend/src/api.rs +++ b/backend/src/api.rs @@ -33,6 +33,8 @@ use crate::env::Env; use crate::infra::Infra; use crate::models::{Relay, Tenant}; use crate::query::Query; +use crate::robot::Robot; +use crate::stripe::Stripe; use crate::routes::identity::get_identity; use crate::routes::invoices::{get_invoice, get_invoice_bolt11, list_tenant_invoices}; use crate::routes::plans::{get_plan, list_plans}; @@ -52,6 +54,8 @@ pub struct Api { pub query: Query, pub command: Command, pub billing: Billing, + pub stripe: Stripe, + pub robot: Robot, pub infra: Infra, } @@ -60,6 +64,8 @@ impl Api { query: Query, command: Command, billing: Billing, + stripe: Stripe, + robot: Robot, infra: Infra, env: &Env, ) -> Self { @@ -68,6 +74,8 @@ impl Api { query, command, billing, + stripe, + robot, infra, } } diff --git a/backend/src/billing.rs b/backend/src/billing.rs index f4be823..c19cf51 100644 --- a/backend/src/billing.rs +++ b/backend/src/billing.rs @@ -567,32 +567,6 @@ impl Billing { }) } - pub async fn stripe_create_customer(&self, tenant_pubkey: &str) -> Result { - let short_pubkey: String = tenant_pubkey.chars().take(8).collect(); - let display_name = self - .robot - .fetch_nostr_name(tenant_pubkey) - .await - .unwrap_or(short_pubkey); - self.stripe - .create_customer(tenant_pubkey, &display_name) - .await - } - - pub async fn stripe_list_invoices(&self, customer_id: &str) -> Result> { - self.stripe.list_invoices(customer_id).await - } - - pub async fn stripe_create_portal_session( - &self, - customer_id: &str, - return_url: Option<&str>, - ) -> Result { - self.stripe - .create_portal_session(customer_id, return_url) - .await - } - pub async fn create_bolt11(&self, amount_due_minor: i64, currency: &str) -> Result { let amount_msats = bitcoin::fiat_to_msats(amount_due_minor, currency).await?; self.wallet diff --git a/backend/src/main.rs b/backend/src/main.rs index 56a62d1..45ab223 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -25,6 +25,7 @@ use crate::env::Env; use crate::infra::Infra; use crate::query::Query; use crate::robot::Robot; +use crate::stripe::Stripe; #[tokio::main] async fn main() -> Result<()> { @@ -39,11 +40,12 @@ async fn main() -> Result<()> { let pool = pool::create_pool(&env.database_url).await?; let robot = Robot::new(&env).await?; + let stripe = Stripe::new(&env); let query = Query::new(pool.clone(), &env); let command = Command::new(pool); let billing = Billing::new(query.clone(), command.clone(), robot.clone(), &env); let infra = Infra::new(query.clone(), command.clone(), &env); - let api = Api::new(query, command, billing.clone(), infra.clone(), &env); + let api = Api::new(query, command, billing.clone(), stripe, robot, infra.clone(), &env); let cors = if env.server_allow_origins.is_empty() { CorsLayer::permissive() diff --git a/backend/src/routes/invoices.rs b/backend/src/routes/invoices.rs index a6d6366..dccebf4 100644 --- a/backend/src/routes/invoices.rs +++ b/backend/src/routes/invoices.rs @@ -14,8 +14,8 @@ pub async fn list_tenant_invoices( let tenant = api.get_tenant_or_404(&pubkey).await?; let invoices = api - .billing - .stripe_list_invoices(&tenant.stripe_customer_id) + .stripe + .list_invoices(&tenant.stripe_customer_id) .await .map_err(internal)?; ok(invoices) diff --git a/backend/src/routes/stripe.rs b/backend/src/routes/stripe.rs index cc886ef..86c3581 100644 --- a/backend/src/routes/stripe.rs +++ b/backend/src/routes/stripe.rs @@ -25,8 +25,8 @@ pub async fn create_stripe_session( let tenant = api.get_tenant_or_404(&pubkey).await?; let url = api - .billing - .stripe_create_portal_session(&tenant.stripe_customer_id, params.return_url.as_deref()) + .stripe + .create_portal_session(&tenant.stripe_customer_id, params.return_url.as_deref()) .await .map_err(internal)?; ok(serde_json::json!({ "url": url })) diff --git a/backend/src/routes/tenants.rs b/backend/src/routes/tenants.rs index c0a6591..778f5e1 100644 --- a/backend/src/routes/tenants.rs +++ b/backend/src/routes/tenants.rs @@ -65,9 +65,15 @@ pub async fn create_tenant( return ok(TenantResponse::from(t)); } + let display_name = api + .robot + .fetch_nostr_name(&pubkey) + .await + .unwrap_or(pubkey.chars().take(8).collect()); + let stripe_customer_id = api - .billing - .stripe_create_customer(&pubkey) + .stripe + .create_customer(&pubkey, &display_name) .await .map_err(internal)?;