Remove some stripe proxy methods
This commit is contained in:
@@ -33,6 +33,8 @@ use crate::env::Env;
|
|||||||
use crate::infra::Infra;
|
use crate::infra::Infra;
|
||||||
use crate::models::{Relay, Tenant};
|
use crate::models::{Relay, Tenant};
|
||||||
use crate::query::Query;
|
use crate::query::Query;
|
||||||
|
use crate::robot::Robot;
|
||||||
|
use crate::stripe::Stripe;
|
||||||
use crate::routes::identity::get_identity;
|
use crate::routes::identity::get_identity;
|
||||||
use crate::routes::invoices::{get_invoice, get_invoice_bolt11, list_tenant_invoices};
|
use crate::routes::invoices::{get_invoice, get_invoice_bolt11, list_tenant_invoices};
|
||||||
use crate::routes::plans::{get_plan, list_plans};
|
use crate::routes::plans::{get_plan, list_plans};
|
||||||
@@ -52,6 +54,8 @@ pub struct Api {
|
|||||||
pub query: Query,
|
pub query: Query,
|
||||||
pub command: Command,
|
pub command: Command,
|
||||||
pub billing: Billing,
|
pub billing: Billing,
|
||||||
|
pub stripe: Stripe,
|
||||||
|
pub robot: Robot,
|
||||||
pub infra: Infra,
|
pub infra: Infra,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +64,8 @@ impl Api {
|
|||||||
query: Query,
|
query: Query,
|
||||||
command: Command,
|
command: Command,
|
||||||
billing: Billing,
|
billing: Billing,
|
||||||
|
stripe: Stripe,
|
||||||
|
robot: Robot,
|
||||||
infra: Infra,
|
infra: Infra,
|
||||||
env: &Env,
|
env: &Env,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -68,6 +74,8 @@ impl Api {
|
|||||||
query,
|
query,
|
||||||
command,
|
command,
|
||||||
billing,
|
billing,
|
||||||
|
stripe,
|
||||||
|
robot,
|
||||||
infra,
|
infra,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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> {
|
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?;
|
let amount_msats = bitcoin::fiat_to_msats(amount_due_minor, currency).await?;
|
||||||
self.wallet
|
self.wallet
|
||||||
|
|||||||
+3
-1
@@ -25,6 +25,7 @@ use crate::env::Env;
|
|||||||
use crate::infra::Infra;
|
use crate::infra::Infra;
|
||||||
use crate::query::Query;
|
use crate::query::Query;
|
||||||
use crate::robot::Robot;
|
use crate::robot::Robot;
|
||||||
|
use crate::stripe::Stripe;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@@ -39,11 +40,12 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
let pool = pool::create_pool(&env.database_url).await?;
|
let pool = pool::create_pool(&env.database_url).await?;
|
||||||
let robot = Robot::new(&env).await?;
|
let robot = Robot::new(&env).await?;
|
||||||
|
let stripe = Stripe::new(&env);
|
||||||
let query = Query::new(pool.clone(), &env);
|
let query = Query::new(pool.clone(), &env);
|
||||||
let command = Command::new(pool);
|
let command = Command::new(pool);
|
||||||
let billing = Billing::new(query.clone(), command.clone(), robot.clone(), &env);
|
let billing = Billing::new(query.clone(), command.clone(), robot.clone(), &env);
|
||||||
let infra = Infra::new(query.clone(), command.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() {
|
let cors = if env.server_allow_origins.is_empty() {
|
||||||
CorsLayer::permissive()
|
CorsLayer::permissive()
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ pub async fn list_tenant_invoices(
|
|||||||
let tenant = api.get_tenant_or_404(&pubkey).await?;
|
let tenant = api.get_tenant_or_404(&pubkey).await?;
|
||||||
|
|
||||||
let invoices = api
|
let invoices = api
|
||||||
.billing
|
.stripe
|
||||||
.stripe_list_invoices(&tenant.stripe_customer_id)
|
.list_invoices(&tenant.stripe_customer_id)
|
||||||
.await
|
.await
|
||||||
.map_err(internal)?;
|
.map_err(internal)?;
|
||||||
ok(invoices)
|
ok(invoices)
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ pub async fn create_stripe_session(
|
|||||||
let tenant = api.get_tenant_or_404(&pubkey).await?;
|
let tenant = api.get_tenant_or_404(&pubkey).await?;
|
||||||
|
|
||||||
let url = api
|
let url = api
|
||||||
.billing
|
.stripe
|
||||||
.stripe_create_portal_session(&tenant.stripe_customer_id, params.return_url.as_deref())
|
.create_portal_session(&tenant.stripe_customer_id, params.return_url.as_deref())
|
||||||
.await
|
.await
|
||||||
.map_err(internal)?;
|
.map_err(internal)?;
|
||||||
ok(serde_json::json!({ "url": url }))
|
ok(serde_json::json!({ "url": url }))
|
||||||
|
|||||||
@@ -65,9 +65,15 @@ pub async fn create_tenant(
|
|||||||
return ok(TenantResponse::from(t));
|
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
|
let stripe_customer_id = api
|
||||||
.billing
|
.stripe
|
||||||
.stripe_create_customer(&pubkey)
|
.create_customer(&pubkey, &display_name)
|
||||||
.await
|
.await
|
||||||
.map_err(internal)?;
|
.map_err(internal)?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user