[insight] Goals and rewards: a goal this month (its tank, what is needed, the pace, the split between its ways, where money could come from), medals and challenges from complete periods, the cancel letter in Czech

This commit is contained in:
2026-11-07 22:39:54 +01:00
parent c3cb1dd060
commit 03d2afd4dc
9 changed files with 1079 additions and 20 deletions
+44 -15
View File
@@ -1,6 +1,7 @@
//! The cancel kit: where to cancel a known provider, and a polite email to send when there is no page.
use crate::subscriptions::Subscription;
use fiscus_ledger::invoice::Language;
use serde::{Deserialize, Serialize};
/// `(a word in the merchant key, provider, the page where its subscription is cancelled)`.
@@ -46,24 +47,52 @@ fn percent(s: &str) -> String {
out
}
/// The kit with its email in English.
pub fn cancel_kit(sub: &Subscription) -> CancelKit {
cancel_kit_in(sub, Language::En)
}
/// The kit with its email in Czech or English (the app's language: most Czech providers read Czech).
pub fn cancel_kit_in(sub: &Subscription, language: Language) -> CancelKit {
let words: Vec<&str> = sub.merchant_key.split(' ').collect();
let known = PROVIDERS.iter().find(|(w, _, _)| words.contains(w));
let name = known.map(|(_, p, _)| p.to_string()).unwrap_or_else(|| sub.merchant.clone());
let cadence = match sub.cadence {
crate::subscriptions::Cadence::Monthly => "monthly",
crate::subscriptions::Cadence::Yearly => "yearly",
};
let last = sub.charges.last().map(|c| c.date.to_string()).unwrap_or_default();
CancelKit {
provider: known.map(|(_, p, _)| p.to_string()),
url: known.map(|(_, _, u)| u.to_string()),
email_subject: format!("Cancel my {name} subscription"),
email_body: format!(
"Hello,\n\nplease cancel my {name} subscription ({cadence}, {} CZK, last charged on {last}) \
with effect from the end of the current period, and confirm the cancellation by email.\n\n\
Please do not charge my card again.\n\nThank you.",
sub.cost.to_czk()
let monthly = sub.cadence == crate::subscriptions::Cadence::Monthly;
let last = sub.charges.last().map(|c| c.date);
let cost = sub.cost.to_czk();
let (email_subject, email_body) = match language {
Language::En => (
format!("Cancel my {name} subscription"),
format!(
"Hello,
please cancel my {name} subscription ({}, {cost} CZK, last charged on {}) with effect from the end of the current period, and confirm the cancellation by email.
Please do not charge my card again.
Thank you.",
if monthly { "monthly" } else { "yearly" },
last.map(|d| d.to_string()).unwrap_or_default(),
),
),
}
Language::Cs => (
format!("Zrušení předplatného {name}"),
format!(
"Dobrý den,
prosím o zrušení mého předplatného {name} ({}, {cost} Kč, naposledy strženo {}) ke konci aktuálního období a o potvrzení zrušení e-mailem.
Prosím, dále mi nestrhávejte platby z karty.
Děkuji.",
if monthly { "měsíční" } else { "roční" },
last.map(|d| {
let (y, m, day) = d.ymd();
format!("{day}. {m}. {y}")
})
.unwrap_or_default(),
),
),
};
CancelKit { provider: known.map(|(_, p, _)| p.to_string()), url: known.map(|(_, _, u)| u.to_string()), email_subject, email_body }
}