Remove some stripe proxy methods

This commit is contained in:
Jon Staab
2026-05-21 14:29:38 -07:00
parent e6cbfb361e
commit c02d834fe0
6 changed files with 23 additions and 33 deletions
+8
View File
@@ -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,
}
}
-26
View File
@@ -567,32 +567,6 @@ impl Billing {
})
}
pub async fn stripe_create_customer(&self, tenant_pubkey: &str) -> Result<String> {
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<Vec<StripeInvoice>> {
self.stripe.list_invoices(customer_id).await
}
pub async fn stripe_create_portal_session(
&self,
customer_id: &str,
return_url: Option<&str>,
) -> Result<String> {
self.stripe
.create_portal_session(customer_id, return_url)
.await
}
pub async fn create_bolt11(&self, amount_due_minor: i64, currency: &str) -> Result<String> {
let amount_msats = bitcoin::fiat_to_msats(amount_due_minor, currency).await?;
self.wallet
+3 -1
View File
@@ -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()
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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 }))
+8 -2
View File
@@ -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)?;