Drop the unlimited package, new prices, AI quality note
CI / test (push) Successful in 53s
CI / build (push) Successful in 6m41s
CI / deploy (push) Skipped

- The unlimited package is gone (easy to resell, e.g. by an astrologer):
  catalog, fair-use cap, UNLIMITED_DAILY_LIMIT, /v1/me unlimited_until,
  admin badge. Migration 0014 removes the 'unlimited' entitlements; old
  orders of it are skipped in the header.
- New prices: single 2 000 Ft, couple 4 500, family 8 000, +1 synastry
  2 500, +5 persons 1 500 (list prices 2 000 / 2 500 / 300).
- Login page, packages page and the analysis offer say the analyses are
  written by top AI models, close to a professional astrologer's written
  reading, for a fraction of the price (the packages page names the model).

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-18 06:20:31 +00:00
co-authored by Claude Opus 5.5
parent 742b88183b
commit 6d2ad4aa0c
27 changed files with 147 additions and 280 deletions
+24 -102
View File
@@ -2,8 +2,8 @@
//! fixed here; see `docs/csomagok.md` for the reasoning behind it.
//!
//! A package gives analysis units and person slots (`credit_ledger` rows
//! with reason `package`) that never expire, or a time-limited `unlimited`
//! entitlement: analyses and persons without limit, with a daily fair-use cap.
//! with reason `package`) that never expire. There is no unlimited package on
//! purpose: it would be easy to resell (e.g. by an astrologer).
use serde_json::{Value, json};
use sqlx::PgConnection;
@@ -14,9 +14,9 @@ use crate::credits::Unit;
use crate::error::ApiError;
/// List prices of the single items, for showing what a package saves.
const NATAL_PRICE: i64 = 2_990;
const SYNASTRY_PRICE: i64 = 3_490;
const PERSON_PRICE: i64 = 398; // 1 990 Ft for five
const NATAL_PRICE: i64 = 2_000;
const SYNASTRY_PRICE: i64 = 2_500;
const PERSON_PRICE: i64 = 300; // 1 500 Ft for five
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Tier {
@@ -37,23 +37,20 @@ pub struct Package {
pub natal: i64,
pub synastry: i64,
pub persons: i64,
/// Months of unlimited analyses and persons.
pub unlimited_months: Option<i64>,
/// Badge on the card ("Legnépszerűbb").
pub badge: Option<&'static str>,
}
pub const CATALOG: [Package; 6] = [
pub const CATALOG: [Package; 5] = [
Package {
id: "single",
name: "Egy elemzés",
tagline: "Egy részletes képletelemzés: neked vagy egy felvett személynek.",
tier: Tier::Main,
price_huf: 2_990,
price_huf: 2_000,
natal: 1,
synastry: 0,
persons: 0,
unlimited_months: None,
badge: None,
},
Package {
@@ -61,11 +58,10 @@ pub const CATALOG: [Package; 6] = [
name: "Páros",
tagline: "Te és ő: mindkettőtök képlete és a kapcsolati elemzés.",
tier: Tier::Main,
price_huf: 6_990,
price_huf: 4_500,
natal: 2,
synastry: 1,
persons: 1,
unlimited_months: None,
badge: None,
},
Package {
@@ -73,35 +69,21 @@ pub const CATALOG: [Package; 6] = [
name: "Család",
tagline: "Az egész család: öt személy, mindenki képlete, és öt kapcsolat.",
tier: Tier::Main,
price_huf: 11_990,
price_huf: 8_000,
natal: 6,
synastry: 5,
persons: 5,
unlimited_months: None,
badge: Some("Legnépszerűbb"),
},
Package {
id: "unlimited",
name: "Korlátlan",
tagline: "Egy évig bárki, bármennyi elemzés és összevetés.",
tier: Tier::Main,
price_huf: 17_990,
natal: 0,
synastry: 0,
persons: 0,
unlimited_months: Some(12),
badge: None,
},
Package {
id: "addon_synastry",
name: "+1 kapcsolati elemzés",
tagline: "Egy újabb összevetés részletes elemzése.",
tier: Tier::Addon,
price_huf: 3_490,
price_huf: 2_500,
natal: 0,
synastry: 1,
persons: 0,
unlimited_months: None,
badge: None,
},
Package {
@@ -109,11 +91,10 @@ pub const CATALOG: [Package; 6] = [
name: "+5 személy",
tagline: "Még öt ember képlete (az elemzés külön jár).",
tier: Tier::Addon,
price_huf: 1_990,
price_huf: 1_500,
natal: 0,
synastry: 0,
persons: 5,
unlimited_months: None,
badge: None,
},
];
@@ -123,19 +104,15 @@ pub fn find(id: &str) -> Option<&'static Package> {
}
impl Package {
/// What the contents would cost one by one (`None` for the unlimited one).
fn list_price(&self) -> Option<i64> {
self.unlimited_months
.is_none()
.then(|| self.natal * NATAL_PRICE + self.synastry * SYNASTRY_PRICE + self.persons * PERSON_PRICE)
/// What the contents would cost one by one.
fn list_price(&self) -> i64 {
self.natal * NATAL_PRICE + self.synastry * SYNASTRY_PRICE + self.persons * PERSON_PRICE
}
pub fn view(&self) -> Value {
let analyses = self.natal + self.synastry;
let savings = self
.list_price()
.filter(|&list| list > self.price_huf)
.map(|list| ((list - self.price_huf) * 100 + list / 2) / list);
let list = self.list_price();
let savings = (list > self.price_huf).then(|| ((list - self.price_huf) * 100 + list / 2) / list);
json!({
"id": self.id,
"name": self.name,
@@ -145,9 +122,8 @@ impl Package {
"natal": self.natal,
"synastry": self.synastry,
"persons": self.persons,
"unlimited_months": self.unlimited_months,
"badge": self.badge,
"list_price_huf": self.list_price(),
"list_price_huf": list,
"savings_percent": savings,
"per_analysis_huf": (analyses > 0).then(|| (self.price_huf + analyses / 2) / analyses),
})
@@ -216,76 +192,22 @@ pub async fn grant(
.execute(&mut *tx)
.await?;
}
if let Some(months) = package.unlimited_months {
// Buying again extends from the current end, not from today.
sqlx::query(
"INSERT INTO entitlements (user_id, entitlement, note, created_by, expires_at) \
VALUES ($1, 'unlimited', $2, $3, now() + make_interval(months => $4)) \
ON CONFLICT (user_id, entitlement) DO UPDATE SET \
expires_at = greatest(entitlements.expires_at, now()) + make_interval(months => $4), \
note = EXCLUDED.note, created_by = EXCLUDED.created_by",
)
.bind(user_id)
.bind(package.name)
.bind(created_by)
.bind(months as i32)
.execute(&mut *tx)
.await?;
}
Ok(order)
}
/// Until when the user's unlimited package runs (`None`: none, or it ended).
pub async fn unlimited_until(conn: &mut PgConnection, user_id: Uuid) -> Result<Option<OffsetDateTime>, ApiError> {
let until: Option<OffsetDateTime> = sqlx::query_scalar(
"SELECT expires_at FROM entitlements \
WHERE user_id = $1 AND entitlement = 'unlimited' AND expires_at > now()",
)
.bind(user_id)
.fetch_optional(conn)
.await?
.flatten();
Ok(until)
}
/// The package to show for the user (header, profile): the running
/// unlimited one, or else the latest bought or given package of the main
/// ladder (top-ups do not count). `None`: no package.
/// The package to show for the user (header, profile): the latest bought or
/// given package of the main ladder (top-ups do not count). `None`: no package.
pub async fn current(
conn: &mut PgConnection,
user_id: Uuid,
unlimited_until: Option<OffsetDateTime>,
) -> Result<Option<(&'static Package, OffsetDateTime)>, ApiError> {
let orders: Vec<(String, OffsetDateTime)> =
sqlx::query_as("SELECT package, created_at FROM package_orders WHERE user_id = $1 ORDER BY created_at DESC")
.bind(user_id)
.fetch_all(conn)
.await?;
Ok(orders.into_iter().find_map(|(id, at)| {
let p = find(&id).filter(|p| p.tier == Tier::Main)?;
// While an unlimited package runs, only that is shown; an ended one never.
(p.unlimited_months.is_some() == unlimited_until.is_some()).then_some((p, at))
}))
}
/// The fair-use cap of the unlimited package: new detailed analyses in 24 hours.
pub async fn check_fair_use(conn: &mut PgConnection, user_id: Uuid, daily_limit: i64) -> Result<(), ApiError> {
let (count,): (i64,) = sqlx::query_as(
"SELECT count(*) FROM analyses WHERE requested_by = $1 AND kind IN ('natal', 'synastry') \
AND created_at > now() - interval '24 hours'",
)
.bind(user_id)
.fetch_one(conn)
.await?;
if count >= daily_limit {
return Err(ApiError::Limited {
code: "fair_use_limit",
message: format!(
"A korlátlan csomaggal naponta legfeljebb {daily_limit} új részletes elemzés kérhető. Holnap folytathatod."
),
});
}
Ok(())
// Orders of packages no longer sold (the former unlimited one) are skipped.
Ok(orders.into_iter().find_map(|(id, at)| find(&id).filter(|p| p.tier == Tier::Main).map(|p| (p, at))))
}
#[cfg(test)]
@@ -296,10 +218,10 @@ mod tests {
fn bigger_packages_are_cheaper_per_analysis() {
let per = |id: &str| find(id).unwrap().view()["per_analysis_huf"].as_i64().unwrap();
assert!(per("single") > per("couple") && per("couple") > per("family"));
assert_eq!(find("family").unwrap().view()["savings_percent"], 68);
assert_eq!(find("couple").unwrap().view()["savings_percent"], 29);
assert_eq!(find("family").unwrap().view()["savings_percent"], 69);
assert_eq!(find("couple").unwrap().view()["savings_percent"], 34);
assert!(find("single").unwrap().view()["savings_percent"].is_null());
assert!(find("unlimited").unwrap().view()["list_price_huf"].is_null());
assert!(find("unlimited").is_none());
assert!(CATALOG.iter().all(|p| find(p.id).is_some()));
}
}