//! 计费模块 — 计划管理、订阅、用量配额、支付 pub mod types; pub mod service; pub mod handlers; pub mod payment; pub mod invoice_pdf; use axum::routing::{get, post, put}; /// 全部计费路由(用于 main.rs 一次性挂载) pub fn routes() -> axum::Router { axum::Router::new() .route("/api/v1/billing/plans", get(handlers::list_plans)) .route("/api/v1/billing/plans/:id", get(handlers::get_plan)) .route("/api/v1/billing/subscription", get(handlers::get_subscription)) .route("/api/v1/billing/usage", get(handlers::get_usage)) .route("/api/v1/billing/usage/increment", post(handlers::increment_usage_dimension)) .route("/api/v1/billing/payments", post(handlers::create_payment)) .route("/api/v1/billing/payments/:id", get(handlers::get_payment_status)) .route("/api/v1/billing/invoices/:id/pdf", get(handlers::get_invoice_pdf)) } /// 计划查询路由(无需 AuthContext,可挂载到公开区域) pub fn plan_routes() -> axum::Router { axum::Router::new() .route("/api/v1/billing/plans", get(handlers::list_plans)) .route("/api/v1/billing/plans/:id", get(handlers::get_plan)) } /// 需要认证的计费路由(订阅、用量、支付、发票) pub fn protected_routes() -> axum::Router { axum::Router::new() .route("/api/v1/billing/subscription", get(handlers::get_subscription)) .route("/api/v1/billing/usage", get(handlers::get_usage)) .route("/api/v1/billing/usage/increment", post(handlers::increment_usage_dimension)) .route("/api/v1/billing/payments", post(handlers::create_payment)) .route("/api/v1/billing/payments/:id", get(handlers::get_payment_status)) .route("/api/v1/billing/invoices/:id/pdf", get(handlers::get_invoice_pdf)) } /// 支付回调路由(无需 auth — 支付宝/微信服务器回调) pub fn callback_routes() -> axum::Router { axum::Router::new() .route("/api/v1/billing/callback/:method", post(handlers::payment_callback)) } /// mock 支付页面路由(开发模式) pub fn mock_routes() -> axum::Router { axum::Router::new() .route("/api/v1/billing/mock-pay", get(handlers::mock_pay_page)) .route("/api/v1/billing/mock-pay/confirm", post(handlers::mock_pay_confirm)) } /// 管理员计费路由(需 super_admin 权限) pub fn admin_routes() -> axum::Router { axum::Router::new() .route("/api/v1/admin/accounts/:id/subscription", put(handlers::admin_switch_subscription)) }