Neutral invoice items; "kártya" instead of "kártyajóslás" on Stripe
CI / test (push) Successful in 1m42s
CI / build (push) Successful in 5m0s
CI / deploy (push) Skipped

Invoices: the add-ons share the item "Online tartalomszolgáltatás –
kiegészítő csomag" and tarot readings are listed as "egyedi szöveges
tartalom"; a test keeps "jóslás" and "kártya" off every invoice.
Stripe's payment page and receipt call the tarot add-on "+5 kártya".
The Telegram notice adds the package id to an add-on, so it still says
which one was bought.

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-22 06:36:16 +00:00
co-authored by Claude Opus 5.5
parent 4247f914ce
commit 4b93dc42e8
5 changed files with 51 additions and 20 deletions
+17 -8
View File
@@ -17,17 +17,20 @@ use crate::telegram::{Telegram, huf};
const BATCH: i64 = 20;
/// The notice of one purchase.
fn text(item: &str, price_huf: i32, live: bool) -> String {
fn text(item: &str, package: &str, price_huf: i32, live: bool) -> String {
// The invoice item without its service prefix ("Online tartalomszolgáltatás – ").
let item = item.rsplit(" – ").next().unwrap_or(item);
format!("🛒 Vásárlás: {item}, {}{}", huf(price_huf), if live { "" } else { " (teszt fizetés)" })
// The add-ons share one neutral invoice name; their id tells them apart.
let what =
if package.starts_with("addon_") && item != package { format!("{item} ({package})") } else { item.into() };
format!("🛒 Vásárlás: {what}, {}{}", huf(price_huf), if live { "" } else { " (teszt fizetés)" })
}
/// Sends the notices of the purchases not notified yet; returns how many went out.
pub async fn run_once(db: &PgPool, telegram: &Telegram) -> Result<usize, sqlx::Error> {
let mut tx = db.begin().await?;
let due: Vec<(String, String, i32, bool)> = sqlx::query_as(
"SELECT c.id, coalesce(i.item_name, c.package), coalesce(c.amount_huf, c.price_huf), c.live \
let due: Vec<(String, String, String, i32, bool)> = sqlx::query_as(
"SELECT c.id, coalesce(i.item_name, c.package), c.package, coalesce(c.amount_huf, c.price_huf), c.live \
FROM stripe_checkouts c LEFT JOIN invoices i ON i.checkout_id = c.id \
WHERE c.completed_at IS NOT NULL AND c.notified_at IS NULL \
ORDER BY c.completed_at LIMIT $1 FOR UPDATE OF c SKIP LOCKED",
@@ -36,8 +39,8 @@ pub async fn run_once(db: &PgPool, telegram: &Telegram) -> Result<usize, sqlx::E
.fetch_all(&mut *tx)
.await?;
let mut sent = 0;
for (id, item, price, live) in due {
match telegram.send(&text(&item, price, live)).await {
for (id, item, package, price, live) in due {
match telegram.send(&text(&item, &package, price, live)).await {
Ok(()) => sent += 1,
Err(e) if e.permanent => {
tracing::error!(checkout = %id, error = %e.message, "telegram refused the purchase notice; check TELEGRAM_*");
@@ -122,11 +125,17 @@ mod tests {
#[test]
fn notice_texts() {
assert_eq!(
text("Online tartalomszolgáltatás – Páros csomag", 6000, true),
text("Online tartalomszolgáltatás – Páros csomag", "couple", 6000, true),
"🛒 Vásárlás: Páros csomag, 6\u{a0}000\u{a0}Ft"
);
// The add-ons share one invoice name: the id says which one it was.
assert_eq!(
text("addon_questions", 1000, false),
text("Online tartalomszolgáltatás – kiegészítő csomag", "addon_tarot", 1000, true),
"🛒 Vásárlás: kiegészítő csomag (addon_tarot), 1\u{a0}000\u{a0}Ft"
);
// No invoice yet: the id alone.
assert_eq!(
text("addon_questions", "addon_questions", 1000, false),
"🛒 Vásárlás: addon_questions, 1\u{a0}000\u{a0}Ft (teszt fizetés)"
);
}