A paid checkout queues an invoice row with every invoice detail (buyer, tax type and number, item, net, VAT, gross). The worker's new 'invoices' task creates the Billingo partner and the paid card invoice and e-mails it (API v3), saving each step so a retry never issues a second invoice, and keeps Billingo's whole answer; the PDF is fetched from Billingo when the user downloads it from the new Számláim page (in the menu once there is an invoice). Payments and invoices outlive a deleted account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
87 lines
2.6 KiB
Rust
87 lines
2.6 KiB
Rust
//! Sorsfonalak backend: users, login, charts, synastries, analyses, credits
|
|
//! and public sharing. Charts are calculated by the horoscope-api service.
|
|
//!
|
|
//! Configuration: see [`config::Config`]; plus `BIND_ADDR` (default
|
|
//! `0.0.0.0:8081`), `LOG_FORMAT` and `RUST_LOG`.
|
|
//! Database migrations run at startup.
|
|
//!
|
|
//! `backend healthcheck` performs a local health check (for Docker).
|
|
|
|
mod auth;
|
|
mod birth_changes;
|
|
mod config;
|
|
mod credits;
|
|
mod error;
|
|
mod google;
|
|
mod invoices;
|
|
mod models;
|
|
mod packages;
|
|
mod persons;
|
|
mod routes;
|
|
mod stripe;
|
|
#[cfg(test)]
|
|
mod tests;
|
|
mod views;
|
|
|
|
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
|
|
use anyhow::Context;
|
|
use horoscope_client::HoroscopeClient;
|
|
use sqlx::PgPool;
|
|
|
|
use crate::auth::LoginLimiter;
|
|
use crate::config::Config;
|
|
use crate::google::GoogleVerifier;
|
|
|
|
const DEFAULT_BIND_ADDR: &str = "0.0.0.0:8081";
|
|
|
|
pub struct AppState {
|
|
pub db: PgPool,
|
|
pub config: Config,
|
|
pub horoscope: HoroscopeClient,
|
|
pub google: GoogleVerifier,
|
|
pub login_limiter: LoginLimiter,
|
|
pub models: models::Catalog,
|
|
pub stripe: stripe::Client,
|
|
}
|
|
|
|
impl AppState {
|
|
pub fn new(db: PgPool, config: Config) -> Self {
|
|
Self {
|
|
horoscope: HoroscopeClient::new(&config.horoscope_api_url),
|
|
google: GoogleVerifier::new(config.google_client_ids.clone(), config.google_jwks_url.clone()),
|
|
login_limiter: LoginLimiter::new(10, Duration::from_secs(15 * 60)),
|
|
models: models::Catalog::new(&config.openrouter_models_url),
|
|
stripe: stripe::Client::default(),
|
|
db,
|
|
config,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let addr = service_kit::bind_addr(DEFAULT_BIND_ADDR)?;
|
|
if std::env::args().nth(1).as_deref() == Some("healthcheck") {
|
|
return service_kit::healthcheck(addr);
|
|
}
|
|
service_kit::init_logging();
|
|
let config = Config::from_env()?;
|
|
let pool = db::connect(&config.database_url).await.context("connecting to the database")?;
|
|
db::migrate(&pool).await.context("running database migrations")?;
|
|
tracing::info!(
|
|
google_login = !config.google_client_ids.is_empty(),
|
|
horoscope_api = %config.horoscope_api_url,
|
|
"database ready"
|
|
);
|
|
if std::env::args().nth(1).as_deref() == Some("recalculate") {
|
|
return routes::recalculate(&AppState::new(pool, config)).await;
|
|
}
|
|
let app = routes::router(Arc::new(AppState::new(pool, config)));
|
|
let listener = tokio::net::TcpListener::bind(addr).await.with_context(|| format!("binding {addr}"))?;
|
|
tracing::info!(%addr, "listening");
|
|
axum::serve(listener, app).with_graceful_shutdown(service_kit::shutdown_signal()).await?;
|
|
Ok(())
|
|
}
|