| 1 |
|
| 2 |
|
| 3 |
use axum::{ |
| 4 |
extract::State, |
| 5 |
response::{Html, IntoResponse, Response}, |
| 6 |
Form, |
| 7 |
}; |
| 8 |
use serde::Deserialize; |
| 9 |
|
| 10 |
use crate::{ |
| 11 |
auth::AuthUser, |
| 12 |
db, |
| 13 |
error::Result, |
| 14 |
templates::SaveStatusTemplate, |
| 15 |
AppState, |
| 16 |
}; |
| 17 |
|
| 18 |
#[derive(Debug, Deserialize)] |
| 19 |
pub struct StripeTaxForm { |
| 20 |
pub stripe_tax_enabled: Option<String>, |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
#[tracing::instrument(skip_all, name = "users::toggle_stripe_tax")] |
| 25 |
pub(in crate::routes::api) async fn toggle_stripe_tax( |
| 26 |
State(state): State<AppState>, |
| 27 |
AuthUser(user): AuthUser, |
| 28 |
Form(form): Form<StripeTaxForm>, |
| 29 |
) -> Result<Response> { |
| 30 |
let enabled = form.stripe_tax_enabled.as_deref() == Some("on"); |
| 31 |
|
| 32 |
db::users::update_stripe_tax_enabled(&state.db, user.id, enabled).await?; |
| 33 |
|
| 34 |
Ok(Html(SaveStatusTemplate { |
| 35 |
success: true, |
| 36 |
message: "Tax setting saved".to_string(), |
| 37 |
}.render_string()).into_response()) |
| 38 |
} |
| 39 |
|