Detailed analysis button, loading wheel, birth data change limits
Backend: - own birth data: three corrections within an hour of the first save, then one change per 24 hours (birth_data_changes); 429 birth_data_change_limit with the user-facing message; /v1/me birth_change shows the notice; admins are not limited - admins get detailed analyses free (no unit spent) - POST /v1/payments/mock (MOCK_PAYMENTS): stand-in payment that adds a unit, until Stripe is connected; on in the compose files for now Frontend: - detailed analysis offer: admin starts it free, users with units confirm, others go through the (stand-in) payment step - turning wheel with elapsed time while the summary or the analysis is being written - no "adatok javítása" on the chart page (only in the profile), limit notice there; wheel hover highlighting removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
//! Payments. Until Stripe is connected, `MOCK_PAYMENTS=true` turns on a
|
||||
//! stand-in: "paying" adds one analysis unit right away, so the paid flow can
|
||||
//! be used end to end.
|
||||
|
||||
use axum::Json;
|
||||
use axum::extract::State;
|
||||
use axum_extra::extract::WithRejection;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{Body, St};
|
||||
use crate::auth::AuthUser;
|
||||
use crate::credits::{self, Unit};
|
||||
use crate::error::{ApiError, ApiResult};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct MockPayment {
|
||||
unit: Unit,
|
||||
}
|
||||
|
||||
/// Adds one unit of the given kind as a (pretend) purchase.
|
||||
pub async fn mock(
|
||||
State(state): St,
|
||||
auth: AuthUser,
|
||||
WithRejection(Json(req), _): Body<MockPayment>,
|
||||
) -> ApiResult<Json<Value>> {
|
||||
if !state.config.mock_payments {
|
||||
return Err(ApiError::NotFound("payment method"));
|
||||
}
|
||||
let mut tx = state.db.begin().await?;
|
||||
sqlx::query(
|
||||
"INSERT INTO credit_ledger (id, user_id, unit, delta, reason, note) VALUES ($1, $2, $3, 1, 'purchase', 'mock payment')",
|
||||
)
|
||||
.bind(Uuid::now_v7())
|
||||
.bind(auth.id())
|
||||
.bind(req.unit.as_str())
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
let balance = credits::balance(&mut tx, auth.id()).await?;
|
||||
tx.commit().await?;
|
||||
Ok(Json(json!({ "analyses_left": balance.view() })))
|
||||
}
|
||||
Reference in New Issue
Block a user