Á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
+30 -7
View File
@@ -2335,6 +2335,12 @@ async fn stripe_checkout_grants_the_paid_package_once(pool: PgPool) {
assert_eq!(stripe_form(&id, "customer_email").as_deref(), Some("anna@example.com"));
assert_eq!(stripe_form(&id, "tax_id_collection[enabled]").as_deref(), Some("true"));
assert_eq!(stripe_form(&id, "billing_address_collection").as_deref(), Some("required"));
// Every purchase accepts the terms and gives up the withdrawal right.
assert_eq!(stripe_form(&id, "consent_collection[terms_of_service]").as_deref(), Some("required"));
let consent = stripe_form(&id, "custom_text[terms_of_service_acceptance][message]").unwrap();
assert!(
consent.contains("[ÁSZF-et](https://sorsfonalak.test/aszf)") && consent.contains("14 napos elállási jogomat")
);
assert_eq!(
stripe_form(&id, "success_url").as_deref(),
Some("https://sorsfonalak.test/kepletek/abc?fizetes={CHECKOUT_SESSION_ID}")
@@ -2362,6 +2368,7 @@ async fn stripe_checkout_grants_the_paid_package_once(pool: PgPool) {
// and Stripe's retries do not grant it again.
let event = json!({"id": "evt_1", "type": "checkout.session.completed",
"data": {"object": {"id": id, "payment_status": "paid", "status": "complete",
"consent": {"terms_of_service": "accepted"},
"amount_total": 600000, "currency": "huf", "payment_intent": "pi_1",
"customer_details": {"name": "Kovács Anna", "email": "anna@example.com",
"business_name": "Csillag Kft.",
@@ -2384,13 +2391,29 @@ async fn stripe_checkout_grants_the_paid_package_once(pool: PgPool) {
}
assert_eq!(stripe_orders(&app.pool, "anna@example.com").await, vec![("couple".to_string(), 6000)]);
// What the invoice needs is kept, and the invoice is queued.
let (intent, amount, customer): (String, i32, Value) =
sqlx::query_as("SELECT payment_intent, amount_huf, customer FROM stripe_checkouts WHERE id = $1")
.bind(&id)
.fetch_one(&app.pool)
.await
.unwrap();
assert_eq!((intent.as_str(), amount), ("pi_1", 6000));
let (intent, amount, customer, terms): (String, i32, Value, Option<String>) = sqlx::query_as(
"SELECT payment_intent, amount_huf, customer, terms_version FROM stripe_checkouts \
WHERE id = $1 AND terms_accepted_at IS NOT NULL",
)
.bind(&id)
.fetch_one(&app.pool)
.await
.unwrap();
assert_eq!(
(intent.as_str(), amount, terms.as_deref()),
("pi_1", 6000, Some(crate::routes::payments::TERMS_VERSION))
);
// The confirmation e-mail (once, though the webhook came twice).
let mails: Vec<(Value,)> = sqlx::query_as(
"SELECT payload FROM email_outbox WHERE to_email = 'anna@example.com' AND template = 'purchase_confirmation'",
)
.fetch_all(&app.pool)
.await
.unwrap();
assert_eq!(mails.len(), 1);
assert_eq!((&mails[0].0["package_name"], &mails[0].0["amount"]), (&json!("Páros"), &json!("6\u{a0}000\u{a0}Ft")));
assert!(mails[0].0["contents"].as_str().unwrap().starts_with("2 részletes képletelemzés"));
email_templates::render("purchase_confirmation", "hu", &mails[0].0).unwrap();
assert_eq!(customer["tax_ids"][0]["value"], "12345678-1-23");
#[derive(sqlx::FromRow, Debug)]
struct Queued {