Promo codes; purchases off in production
CI / test (push) Successful in 1m11s
CI / build (push) Successful in 5m38s
CI / deploy (push) Skipped

Admins make promo codes for a package (Admin → Promókódok: batch, note, copy
all), list them filtered (unused by default, used, revoked; by package; by
code, note or redeemer) and withdraw unused ones. A logged-in user redeems a
code once (header link, /bevaltas?kod=... prefilled, packages page, and the
analysis and question offers point there) and gets the package as an order
with source 'promo'. Failed redemptions are rate limited.

Production purchases are off: MOCK_PAYMENTS now defaults to false in the
deploy compose, so package cards say 'Hamarosan'.

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-19 09:45:42 +00:00
co-authored by Claude Opus 5.5
parent 19df36369c
commit 054fb930f5
19 changed files with 863 additions and 5 deletions
+9
View File
@@ -104,6 +104,15 @@ pub fn random_token(bytes: usize) -> String {
URL_SAFE_NO_PAD.encode(buf)
}
/// Letters and digits that cannot be mixed up when typed (no 0/O, 1/I/L).
pub const CODE_ALPHABET: &[u8] = b"23456789ABCDEFGHJKMNPQRSTUVWXYZ";
/// A random code of `len` characters from [`CODE_ALPHABET`] (about 5 bits each).
pub fn random_code(len: usize) -> String {
let mut rng = rand::rng();
(0..len).map(|_| CODE_ALPHABET[rand::Rng::random_range(&mut rng, 0..CODE_ALPHABET.len())] as char).collect()
}
/// Stored form of a secret token.
pub fn token_hash(token: &str) -> Vec<u8> {
Sha256::digest(token.as_bytes()).to_vec()