ÁSZF consent on Stripe's page off until the opening (TERMS_CONSENT)
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:
@@ -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(),
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user