Christmas gifts and timed gift e-mails

- Gifts bought 15 Nov - 6 Jan get a Christmas card ("Boldog karácsonyt és
  csillagos 2027-et!", snowflakes) and a Christmas e-mail subject.
- The buyer can time the gift e-mail (e.g. Christmas morning); "Küldés most"
  replaces a waiting one, a refund takes it back.
- Admin: timed e-mails by hour (waiting / sent / failed), e-mail state per gift.
- /karacsony landing page; seasonal hints on /csomagok and /ajandek.

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-24 13:46:35 +00:00
co-authored by Claude Opus 5.5
parent 227e8b5b80
commit 382bd31271
22 changed files with 1016 additions and 209 deletions
+34 -7
View File
@@ -334,7 +334,13 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result<Con
.as_str()
.map(|e| e.chars().filter(|c| !c.is_control()).take(254).collect::<String>());
let whom = name(&payload["gift"], "recipient_name");
(code, to, whom)
// `2026-12-24 08:00`, Budapest clock: when it is e-mailed.
let when = payload["gift"]["send_at"].as_str().and_then(|t| {
let (day, clock) = t.split_once(' ')?;
let clock: String = clock.chars().filter(|c| c.is_ascii_digit() || *c == ':').take(5).collect();
Some((date(lang, day)?, clock))
});
(code, to, whom, when)
});
let contents_hu = contents.as_ref().map(|c| format!(" Tartalma: {c}.")).unwrap_or_default();
let contents_en = contents.as_ref().map(|c| format!(" It contains: {c}.")).unwrap_or_default();
@@ -359,9 +365,10 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result<Con
unsubscribe: None,
unsubscribe_post_url: None,
},
(Lang::Hu, Some((code, to, whom))) => Content {
(Lang::Hu, Some((code, to, whom, when))) => Content {
subject: format!("Köszönjük a vásárlást: {package} (ajándék)"),
preheader: Some(match &to {
Some(e) if when.is_some() => format!("Az ajándékot időzítve küldjük el ide: {e}."),
Some(e) => format!("Az ajándékot elküldtük ide: {e}."),
None => "Az ajándékutalványt csatoltuk ehhez a levélhez.".into(),
}),
@@ -370,7 +377,10 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result<Con
"Megkaptuk a fizetésed ({amount}, {paid_on}): a(z) „{package}” csomagot ajándékba vetted{}.{contents_hu} {}",
whom.as_ref().map(|w| format!(" {w} részére")).unwrap_or_default(),
match &to {
Some(e) => format!("Az ajándékkódot az utalvánnyal együtt elküldtük ide: {e}. Ha nem e-mailben adnád át, az Ajándékaim oldalon letöltheted az utalványt PDF-ben."),
Some(e) => match &when {
Some((day, clock)) => format!("Az ajándékkódot az utalvánnyal együtt {day}, {clock}-kor küldjük el ide: {e}. Addig az Ajándékaim oldalon letöltheted az utalványt PDF-ben, vagy elküldheted azonnal is."),
None => format!("Az ajándékkódot az utalvánnyal együtt elküldtük ide: {e}. Ha nem e-mailben adnád át, az Ajándékaim oldalon letöltheted az utalványt PDF-ben."),
},
None => "Az ajándékutalványt PDF-ben csatoltuk ehhez a levélhez, és az Ajándékaim oldalon is letöltheted: kinyomtathatod, vagy továbbküldheted annak, akinek szánod.".into(),
}
),
@@ -409,7 +419,7 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result<Con
unsubscribe: None,
unsubscribe_post_url: None,
},
(Lang::En, Some((code, to, whom))) => Content {
(Lang::En, Some((code, to, whom, when))) => Content {
subject: format!("Thank you for your purchase: {package} (gift)"),
preheader: Some(match &to {
Some(e) => format!("We sent the gift to {e}."),
@@ -420,7 +430,10 @@ fn purchase_confirmation(lang: Lang, payload: &Value, url: String) -> Result<Con
"We received your payment ({amount}, {paid_on}): you bought the “{package}” package as a gift{}.{contents_en} {}",
whom.as_ref().map(|w| format!(" for {w}")).unwrap_or_default(),
match &to {
Some(e) => format!("We sent the gift code with the gift card to {e}. To hand it over another way, download the card as a PDF on the My gifts page."),
Some(e) => match &when {
Some((day, clock)) => format!("We send the gift code with the gift card to {e} on {day} at {clock}. Until then you can download the card on the My gifts page, or send it at once."),
None => format!("We sent the gift code with the gift card to {e}. To hand it over another way, download the card as a PDF on the My gifts page."),
},
None => "The gift card is attached to this e-mail as a PDF, and you can download it on the My gifts page: print it, or forward it to the person it is for.".into(),
}
),
@@ -459,16 +472,21 @@ fn gift_package(lang: Lang, payload: &Value, url: String) -> Result<Content, Tem
payload["contents"].as_str().map(|c| c.chars().filter(|c| !c.is_control()).take(300).collect::<String>());
let from = name(payload, "from_name");
let to = name(payload, "recipient_name");
// Bought for Christmas: said so, with the wishes.
let christmas = payload["christmas_year"].as_i64().is_some();
let xmas = if christmas { "karácsonyi " } else { "" };
Ok(match lang {
Lang::Hu => Content {
subject: match &from {
Some(f) => format!("{f} ajándékot küldött neked: „{package}” csomag"),
Some(f) => format!("{f} {xmas}ajándékot küldött neked: „{package}” csomag"),
None if christmas => format!("Karácsonyi ajándékot kaptál: „{package}” csomag a Sorsfonalakon"),
None => format!("Ajándékot kaptál: „{package}” csomag a Sorsfonalakon"),
},
preheader: Some("Születési képlet és személyre szóló elemzések: a kód beváltásával a tiéd.".into()),
greeting: to.as_ref().map_or_else(|| "Szia!".into(), |t| format!("Szia {t}!")),
intro: format!(
"{} egy „{package}” csomagot a Sorsfonalakon.{}",
"{}{} egy „{package}” csomagot a Sorsfonalakon.{}",
if christmas { "Boldog karácsonyt! " } else { "" },
match &from {
Some(f) => format!("{f} ajándékozott neked"),
None => "Ajándékba kaptál".into(),
@@ -497,6 +515,7 @@ fn gift_package(lang: Lang, payload: &Value, url: String) -> Result<Content, Tem
},
Lang::En => Content {
subject: match &from {
Some(f) if christmas => format!("{f} sent you a Christmas gift: the “{package}” package"),
Some(f) => format!("{f} sent you a gift: the “{package}” package"),
None => format!("A gift for you: the “{package}” package on Sorsfonalak"),
},
@@ -1021,6 +1040,11 @@ mod tests {
);
assert!(hu.html.contains("&lt;b&gt;Ölel&lt;/b&gt;") && hu.html.contains(">ABCD-EFGH-JKMN</div>"));
assert!(hu.text.contains("PDF-ben is csatoltuk") && hu.text.contains("mert Ági a Sorsfonalakon"));
let mut xmas = payload.clone();
xmas["christmas_year"] = 2027.into();
let hu = render("gift_package", "hu", &xmas).unwrap();
assert_eq!(hu.subject, "Ági karácsonyi ajándékot küldött neked: „Páros” csomag");
assert!(hu.text.contains("Boldog karácsonyt! Ági ajándékozott neked"));
let anonymous = serde_json::json!({"url": "u", "package_name": "Család", "promo_code": "X1-<script>"});
let hu = render("gift_package", "hu", &anonymous).unwrap();
assert_eq!(hu.subject, "Ajándékot kaptál: „Család” csomag a Sorsfonalakon");
@@ -1046,6 +1070,9 @@ mod tests {
assert!(hu.text.contains("AJÁNDÉKKÓD: ABCD-EFGH-JKMN") && hu.text.contains("14 napon belül"));
assert!(hu.text.contains("a beváltással az elállási jog megszűnik"));
assert!(!hu.text.contains("jóváírtuk"));
payload["gift"]["send_at"] = Value::from("2026-12-24 08:00");
let hu = render("purchase_confirmation", "hu", &payload).unwrap();
assert!(hu.text.contains("2026. december 24., 08:00-kor küldjük el ide: bea@example.com"), "{}", hu.text);
payload["gift"]["recipient_email"] = Value::Null;
let hu = render("purchase_confirmation", "hu", &payload).unwrap();
assert!(hu.text.contains("PDF-ben csatoltuk ehhez a levélhez"));