price change while ordering2

This commit is contained in:
Priec
2026-06-28 23:45:48 +02:00
parent 4c12972422
commit 6c341e9f28
5 changed files with 75 additions and 9 deletions

View File

@@ -398,6 +398,15 @@ async fn payment_page(
.as_ref()
.is_some_and(|pr| pr.address.is_some() && pr.city.is_some() && pr.zip.is_some());
// The old/new order totals carried by the price-change bounce (display only;
// the actual price is always re-verified server-side on submit).
let price_old = params.get("old").and_then(|s| s.parse::<i64>().ok());
let price_new = params.get("new").and_then(|s| s.parse::<i64>().ok());
let price_delta = match (price_old, price_new) {
(Some(o), Some(n)) => Some(n - o),
_ => None,
};
let response = format::view(
&v,
"shop/checkout_payment.html",
@@ -416,8 +425,13 @@ async fn payment_page(
"profile_filled": profile_filled,
"can_create_account": user.is_none(),
// Set when the buyer was bounced back because a price changed between
// viewing this page and submitting; shows a re-confirm notice.
// viewing this page and submitting; opens a dialog with the old/new
// totals and the difference so they can accept or return to the basket.
"price_changed": params.contains_key("price_changed"),
"price_old": price_old.map(format_price),
"price_new": price_new.map(format_price),
"price_diff_abs": price_delta.map(|d| format_price(d.abs())),
"price_increased": price_delta.map(|d| d > 0),
"lang": current_lang(&jar),
}),
)?;
@@ -514,8 +528,14 @@ async fn place_order(
Some(shown) => quote.subtotal_cents + shown,
None => return format::redirect("/checkout/payment?price_changed=1"),
};
if subtotal + method.price_cents != expected_total {
return format::redirect("/checkout/payment?price_changed=1");
let charge_total = subtotal + method.price_cents;
if charge_total != expected_total {
// Bounce back with the old/new totals so the payment page can show the
// buyer a dialog with the difference and let them accept or return to the
// basket.
return format::redirect(&format!(
"/checkout/payment?price_changed=1&old={expected_total}&new={charge_total}"
));
}
// The address/contact captured in the info step, ready to seed a profile (for