ÁSZF: terms page, consent on every purchase, confirmation e-mail
CI / test (push) Successful in 1m28s
CI / build (push) Successful in 5m29s
CI / deploy (push) Skipped

The new /aszf page holds the terms (a draft for legal review; the
company data come from lib/legal.ts). Stripe's payment page asks every
buyer to accept them and to ask for immediate delivery, giving up the
14-day withdrawal right; the time and the terms version are stored, and
a purchase_confirmation e-mail confirms it. Login, the landing footer,
the package cards and the sitemap link the terms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-20 12:06:10 +00:00
co-authored by Claude Opus 5.5
parent ac5e7fa4fd
commit e326095f3f
14 changed files with 409 additions and 12 deletions
+77 -1
View File
@@ -84,6 +84,9 @@ pub fn method(config: &crate::config::Config) -> Option<&'static str> {
}
}
/// The terms (ÁSZF) version a purchase accepts; the frontend's `TERMS_UPDATED`.
pub const TERMS_VERSION: &str = "2026-11-20";
/// Only admins can buy through Stripe: until purchases open, and always with a
/// test key (nobody gets packages with Stripe's test cards, nobody types a
/// real card into a test page).
@@ -149,6 +152,18 @@ pub async fn checkout(
field("metadata[user_id]", &auth.id().to_string()),
field("payment_intent_data[description]", &format!("Sorsfonalak – {}", package.name)),
field("payment_intent_data[metadata][package]", package.id),
// Every purchase accepts the terms and asks for immediate delivery,
// giving up the 14-day withdrawal right (45/2014. Korm. rendelet 29. §).
// Stripe needs the terms URL in its dashboard (Public details) for this.
field("consent_collection[terms_of_service]", "required"),
field(
"custom_text[terms_of_service_acceptance][message]",
&format!(
"Elfogadom az [ÁSZF-et]({}/aszf), kérem a szolgáltatás azonnali megkezdését, és tudomásul veszem, \
hogy ezzel elveszítem a 14 napos elállási jogomat.",
state.config.public_base_url
),
),
field("success_url", &format!("{back}?fizetes={{CHECKOUT_SESSION_ID}}")),
field("cancel_url", &format!("{back}?fizetes=megszakitva")),
];
@@ -195,17 +210,24 @@ async fn complete(state: &AppState, session: &stripe::Session) -> Result<bool, A
}
None => None,
};
if !session.terms_accepted() {
tracing::warn!(session = %session.id, "paid without the terms consent");
}
sqlx::query(
"UPDATE stripe_checkouts SET completed_at = now(), order_id = $2, payment_intent = $3, amount_huf = $4, \
customer = $5 WHERE id = $1",
customer = $5, terms_accepted_at = CASE WHEN $6 THEN now() END, terms_version = CASE WHEN $6 THEN $7 END \
WHERE id = $1",
)
.bind(&session.id)
.bind(order)
.bind(&session.payment_intent)
.bind(amount_huf.map(|a| a as i32))
.bind(&session.customer_details)
.bind(session.terms_accepted())
.bind(TERMS_VERSION)
.execute(&mut *tx)
.await?;
confirm_by_email(&mut tx, state, session, user_id, package, amount_huf.unwrap_or(i64::from(price_huf))).await?;
let buyer = invoices::Buyer::from_stripe(session.customer_details.as_ref().unwrap_or(&Value::Null), None);
let (item, comment) = package.invoice_item();
let gross = amount_huf.unwrap_or(i64::from(price_huf));
@@ -215,6 +237,60 @@ async fn complete(state: &AppState, session: &stripe::Session) -> Result<bool, A
Ok(true)
}
/// The purchase confirmation (the "visszaigazolás" of the withdrawal waiver):
/// to the account's address, or Stripe's if the account is gone.
async fn confirm_by_email(
tx: &mut sqlx::PgConnection,
state: &AppState,
session: &stripe::Session,
user_id: Option<Uuid>,
package: &packages::Package,
amount_huf: i64,
) -> Result<(), ApiError> {
let account: Option<(String, String, Option<String>)> = match user_id {
Some(id) => {
sqlx::query_as("SELECT email, locale, display_name FROM users WHERE id = $1")
.bind(id)
.fetch_optional(&mut *tx)
.await?
}
None => None,
};
let stripe_email = session.customer_details.as_ref().and_then(|c| c["email"].as_str()).map(str::to_string);
let (to, locale, name) = match account {
Some((email, locale, name)) => (email, locale, name),
None => match stripe_email {
Some(email) => (email, "hu".to_string(), None),
None => return Ok(()),
},
};
let base = &state.config.public_base_url;
let payload = json!({
"url": format!("{base}/csomagok"),
"display_name": name,
"package_name": package.name,
"contents": package.contents_text(),
"amount": format_huf(amount_huf),
"paid_on": OffsetDateTime::now_utc().date().to_string(),
"terms_url": format!("{base}/aszf"),
"invoices_url": format!("{base}/szamlak"),
});
super::auth::queue_email_to(tx, user_id, &to, "purchase_confirmation", &locale, payload).await
}
/// "6 000 Ft"
fn format_huf(amount: i64) -> String {
let digits = amount.to_string();
let mut out = String::new();
for (i, c) in digits.chars().enumerate() {
if i > 0 && (digits.len() - i).is_multiple_of(3) {
out.push('\u{a0}');
}
out.push(c);
}
format!("{out}\u{a0}Ft")
}
/// Where a payment stands (the return page asks until it is paid). If the
/// webhook has not arrived yet, Stripe is asked directly.
pub async fn checkout_status(