Gift packages: buy a main package for someone, with a printable gift card

- /ajandek: the package, whom it is for and from whom, the recipient's
  address typed twice (or "I hand it over"), a message; paid on Stripe
  like any package, the invoice is the buyer's
- On payment the gift gets its own code (not a promo code: it cannot be
  withdrawn, and it adds the whole package); redeemed on /bevaltas
- The recipient's e-mail carries the message and the code, with the gift
  card attached as a PDF; the buyer's confirmation says it was a gift
- /ajandekaim: codes, state, the card to download, sending it by e-mail
  (again, or to another address) up to three times
- crates/gift-card draws the A4 card (example chart, questions avatar,
  QR code) as SVG and makes a PDF with krilla, fonts compiled in; the
  backend draws downloads on a blocking thread, the worker the e-mails
- Telegram notices say "(ajándék)"; unpaid gifts go after a week

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-23 20:28:11 +00:00
co-authored by Claude Opus 5.5
parent 699ce2abbd
commit c90232f40c
46 changed files with 3647 additions and 88 deletions
+44
View File
@@ -0,0 +1,44 @@
//! Writes a sample card as PDF and PNG: `cargo run -p gift-card --example preview -- <dir>`.
fn main() {
let dir = std::env::args().nth(1).unwrap_or_else(|| ".".into());
let contents: Vec<String> = [
"2 részletes képletelemzés",
"1 kapcsolati elemzés",
"2 éves előrejelzés",
"1 személyhely",
"3 kérdés",
"5 kártyajóslás",
]
.map(String::from)
.to_vec();
let message = std::env::var("MESSAGE").unwrap_or_else(|_| {
"Boldog születésnapot! Remélem, legalább annyira élvezni fogod, mint én. Nézd meg a kettőnk képletét is, \
kíváncsi vagyok, mit mond rólunk. Ölel: Ági"
.into()
});
let from = std::env::var("FROM").unwrap_or_else(|_| "Ági".into());
let to = std::env::var("TO").unwrap_or_else(|_| "Bea".into());
// A sample code can use letters real codes never have (I, O, 0).
let code = std::env::var("CODE").unwrap_or_else(|_| "ABCD-EFGH-JKMN".into());
let url = format!("https://sorsfonalak.hu/bevaltas?kod={code}");
let card = gift_card::Card {
package: "Páros",
contents: &contents,
code: &code,
redeem_url: &url,
recipient_name: Some(to.as_str()),
from_name: Some(from.as_str()),
message: (!message.is_empty()).then_some(message.as_str()),
};
let started = std::time::Instant::now();
let pdf = gift_card::pdf(&card).unwrap();
println!("pdf: {} bytes in {:?}", pdf.len(), started.elapsed());
std::fs::write(format!("{dir}/card.pdf"), pdf).unwrap();
let tree = gift_card::tree(&card).unwrap();
let scale: f32 = std::env::var("SCALE").ok().and_then(|s| s.parse().ok()).unwrap_or(2.0);
let size = tree.size().to_int_size().scale_by(scale).unwrap();
let mut pixmap = resvg::tiny_skia::Pixmap::new(size.width(), size.height()).unwrap();
resvg::render(&tree, resvg::tiny_skia::Transform::from_scale(scale, scale), &mut pixmap.as_mut());
pixmap.save_png(format!("{dir}/card.png")).unwrap();
}