Neutral invoice items; "kártya" instead of "kártyajóslás" on Stripe
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:
@@ -245,11 +245,13 @@ impl Package {
|
||||
|
||||
/// The invoice item: a name that says what the service is (online,
|
||||
/// software-made content; no profession implied), and what the package
|
||||
/// contains (Áfa tv. 169. § e).
|
||||
/// contains (Áfa tv. 169. § e). Kept neutral: the main packages keep
|
||||
/// their plain names, the add-ons share one name, and tarot readings are
|
||||
/// listed as text content.
|
||||
pub fn invoice_item(&self) -> (String, String) {
|
||||
let name = match self.tier {
|
||||
Tier::Main => format!("Online tartalomszolgáltatás – {} csomag", self.name),
|
||||
Tier::Addon => format!("Online tartalomszolgáltatás – {} kiegészítő", self.name),
|
||||
Tier::Addon => "Online tartalomszolgáltatás – kiegészítő csomag".to_string(),
|
||||
};
|
||||
let lines: Vec<String> = [
|
||||
(self.natal, "képletelemzés"),
|
||||
@@ -257,7 +259,7 @@ impl Package {
|
||||
(self.forecast, "éves előrejelzés"),
|
||||
(self.persons, "további személy felvétele"),
|
||||
(self.questions, "kérdés"),
|
||||
(self.tarot, "kártyaértelmezés"),
|
||||
(self.tarot, "egyedi szöveges tartalom"),
|
||||
]
|
||||
.into_iter()
|
||||
.filter(|&(n, _)| n > 0)
|
||||
@@ -271,6 +273,13 @@ impl Package {
|
||||
(name, comment)
|
||||
}
|
||||
|
||||
/// The name and description on Stripe's payment page and receipt: as on
|
||||
/// the site, but tarot readings are called "kártya" there.
|
||||
pub fn checkout_text(&self) -> (String, String) {
|
||||
let plain = |s: &str| s.replace("kártyajóslás", "kártya");
|
||||
(format!("Sorsfonalak – {}", plain(self.name)), plain(self.tagline))
|
||||
}
|
||||
|
||||
/// What the package gives, unit by unit.
|
||||
pub fn contents(&self) -> [(Unit, i64); 6] {
|
||||
[
|
||||
@@ -420,12 +429,24 @@ mod tests {
|
||||
comment,
|
||||
"Hozzáférés a sorsfonalak.hu szoftveresen előállított, személyre szabott szöveges tartalmaihoz: \
|
||||
2 képletelemzés, 1 kapcsolati elemzés, 2 éves előrejelzés, 1 további személy felvétele, 3 kérdés, \
|
||||
5 kártyaértelmezés. Digitális tartalom."
|
||||
5 egyedi szöveges tartalom. Digitális tartalom."
|
||||
);
|
||||
let (name, comment) = find("addon_persons").unwrap().invoice_item();
|
||||
assert_eq!(name, "Online tartalomszolgáltatás – +5 személy kiegészítő");
|
||||
assert_eq!(name, "Online tartalomszolgáltatás – kiegészítő csomag");
|
||||
assert!(comment.ends_with("tartalmaihoz: 5 további személy felvétele. Digitális tartalom."), "{comment}");
|
||||
// No profession is implied.
|
||||
assert!(CATALOG.iter().all(|p| !format!("{:?}", p.invoice_item()).to_lowercase().contains("asztrol")));
|
||||
// No profession and no fortune-telling is implied.
|
||||
for package in &CATALOG {
|
||||
let item = format!("{:?}", package.invoice_item()).to_lowercase();
|
||||
assert!(!item.contains("asztrol") && !item.contains("jóslás") && !item.contains("kártya"), "{item}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stripe_says_kartya_instead_of_kartyajoslas() {
|
||||
let (name, description) = find("addon_tarot").unwrap().checkout_text();
|
||||
assert_eq!(name, "Sorsfonalak – +5 kártya");
|
||||
assert_eq!(description, "Öt újabb kártya a saját kérdéseidre.");
|
||||
assert_eq!(find("couple").unwrap().checkout_text().0, "Sorsfonalak – Páros");
|
||||
assert!(CATALOG.iter().all(|p| !format!("{:?}", p.checkout_text()).contains("jóslás")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ pub async fn checkout(
|
||||
let config = stripe_for(&state, &auth)?;
|
||||
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 (checkout_name, checkout_description) = package.checkout_text();
|
||||
let field = |k: &str, v: &str| (k.to_string(), v.to_string());
|
||||
let mut form = vec![
|
||||
field("mode", "payment"),
|
||||
@@ -147,11 +148,11 @@ pub async fn checkout(
|
||||
field("line_items[0][price_data][currency]", "huf"),
|
||||
// Stripe counts forints in fillér.
|
||||
field("line_items[0][price_data][unit_amount]", &(package.price_huf * 100).to_string()),
|
||||
field("line_items[0][price_data][product_data][name]", &format!("Sorsfonalak – {}", package.name)),
|
||||
field("line_items[0][price_data][product_data][description]", package.tagline),
|
||||
field("line_items[0][price_data][product_data][name]", &checkout_name),
|
||||
field("line_items[0][price_data][product_data][description]", &checkout_description),
|
||||
field("metadata[package]", package.id),
|
||||
field("metadata[user_id]", &auth.id().to_string()),
|
||||
field("payment_intent_data[description]", &format!("Sorsfonalak – {}", package.name)),
|
||||
field("payment_intent_data[description]", &checkout_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")),
|
||||
|
||||
@@ -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)"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user