ÁSZF consent on Stripe's page off until the opening (TERMS_CONSENT)
CI / test (push) Successful in 1m28s
CI / build (push) Successful in 5m2s
CI / deploy (push) Skipped

Stripe refuses the terms consent until the terms URL is set in its
Public details, so purchases would fail. TERMS_CONSENT=false (the
default) leaves the consent out; then the package cards do not mention
the withdrawal waiver and no purchase confirmation is sent.

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 14:03:12 +00:00
co-authored by Claude Opus 5.5
parent e326095f3f
commit 54af54cd39
9 changed files with 58 additions and 16 deletions
+6
View File
@@ -58,6 +58,10 @@ pub struct Config {
/// Until the opening only admins can (and with a test key always only
/// admins), so nobody types a real card into a test or unfinished setup.
pub purchases_open: bool,
/// `TERMS_CONSENT` (default `false`): Stripe's payment page asks every
/// buyer to accept the ÁSZF and give up the withdrawal right. Needs the
/// terms URL in Stripe's Public details; off until the opening.
pub terms_consent: bool,
/// `USER_INVITES` (default `false`): users may invite others ("how
/// compatible are we?" links, which also let the invitee sign up). Off
/// until the launch; admins may always.
@@ -187,6 +191,7 @@ impl Config {
.trim_end_matches('/')
.to_string(),
purchases_open: parsed("PURCHASES_OPEN", false)?,
terms_consent: parsed("TERMS_CONSENT", false)?,
user_invites: parsed("USER_INVITES", false)?,
referral_rewards: parsed("REFERRAL_REWARDS", false)?,
google_client_ids: list("GOOGLE_CLIENT_IDS"),
@@ -231,6 +236,7 @@ impl Config {
billingo_api_key: Some("billingo-fake".into()),
billingo_api_url: format!("{horoscope_api_url}/billingo"),
purchases_open: true,
terms_consent: true,
user_invites: true,
referral_rewards: true,
google_client_ids: vec!["test-client.apps.googleusercontent.com".into()],
+2
View File
@@ -175,6 +175,8 @@ async fn public_config(State(state): St) -> Json<Value> {
"payments_test": c.stripe.as_ref().is_some_and(|s| s.test_mode()),
// "AAM" (alanyi adómentes: the prices carry no VAT) or a rate like "27%".
"vat": c.invoice_vat.code(),
// Buyers accept the ÁSZF on Stripe's page (off until the opening).
"terms_consent": c.terms_consent,
"user_invites": c.user_invites,
"referral_rewards": c.referral_rewards,
"signup_mode": c.signup_mode.as_str(),
+14 -9
View File
@@ -132,7 +132,7 @@ pub async fn checkout(
let package = packages::find(&req.package).ok_or(ApiError::NotFound("package"))?;
let back = format!("{}{}", state.config.public_base_url, return_path(req.return_path.as_deref()));
let field = |k: &str, v: &str| (k.to_string(), v.to_string());
let form = vec![
let mut form = vec![
field("mode", "payment"),
field("locale", "hu"),
field("client_reference_id", &auth.id().to_string()),
@@ -152,21 +152,23 @@ 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),
field("success_url", &format!("{back}?fizetes={{CHECKOUT_SESSION_ID}}")),
field("cancel_url", &format!("{back}?fizetes=megszakitva")),
];
if state.config.terms_consent {
// 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(
form.push(field("consent_collection[terms_of_service]", "required"));
form.push(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")),
];
));
}
let session = state.stripe.create_session(config, &form).await?;
let url = session.url.ok_or_else(|| ApiError::Internal(format!("checkout session {} has no url", session.id)))?;
sqlx::query("INSERT INTO stripe_checkouts (id, user_id, package, price_huf, live) VALUES ($1, $2, $3, $4, $5)")
@@ -210,7 +212,7 @@ async fn complete(state: &AppState, session: &stripe::Session) -> Result<bool, A
}
None => None,
};
if !session.terms_accepted() {
if state.config.terms_consent && !session.terms_accepted() {
tracing::warn!(session = %session.id, "paid without the terms consent");
}
sqlx::query(
@@ -227,7 +229,10 @@ async fn complete(state: &AppState, session: &stripe::Session) -> Result<bool, A
.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?;
// The confirmation confirms the withdrawal waiver: only when it was given.
if session.terms_accepted() {
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));
+8
View File
@@ -2312,6 +2312,7 @@ async fn stripe_checkout_grants_the_paid_package_once(pool: PgPool) {
assert_eq!(r.body["payments"], "stripe");
assert_eq!(r.body["payments_test"], false);
assert_eq!(r.body["vat"], "AAM");
assert_eq!(r.body["terms_consent"], true);
// Stripe replaces the stand-in payment.
assert_eq!(r.body["mock_payments"], false);
let anna = app.register("anna@example.com", "Anna").await;
@@ -2549,14 +2550,21 @@ async fn stripe_purchases_wait_for_the_opening(pool: PgPool) {
let app = TestApp::with_config(pool, |c| {
with_stripe(c, "sk_live_fake");
c.purchases_open = false;
c.terms_consent = false;
})
.await;
let r = app.get("/v1/config", None).await;
assert_eq!((&r.body["payments_test"], &r.body["payments_admins_only"]), (&json!(false), &json!(true)));
assert_eq!(r.body["terms_consent"], false);
let anna = app.register("anna@example.com", "Anna").await;
let r = app.post("/v1/payments/checkout", Some(&anna), json!({"package": "single"})).await;
assert_eq!(r.status, StatusCode::FORBIDDEN);
let admin = app.register("admin@example.com", "Admin").await;
let r = app.post("/v1/payments/checkout", Some(&admin), json!({"package": "single"})).await;
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
// Until the opening Stripe's page does not ask for the ÁSZF (TERMS_CONSENT).
let id = r.body["url"].as_str().unwrap().rsplit('/').next().unwrap().to_string();
assert_eq!(stripe_form(&id, "billing_address_collection").as_deref(), Some("required"));
assert_eq!(stripe_form(&id, "consent_collection[terms_of_service]"), None);
assert_eq!(stripe_form(&id, "custom_text[terms_of_service_acceptance][message]"), None);
}