You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1547,6 +1563,7 @@ impl SubscriptionService for SubscriptionServiceImpl {
1547
1563
let customer_id = self.get_or_create_stripe_customer(user_id,None).await?;
1548
1564
1549
1565
let base_client = self.get_stripe_client();
1566
+
// Hour-granular idempotency: same user+credits within the same clock hour reuses Stripe session (avoids duplicate checkouts; retry after hour gets new session).
1550
1567
let idempotency_key = format!(
1551
1568
"credit_checkout_{}_{}_{}",
1552
1569
user_id,
@@ -1603,6 +1620,20 @@ impl SubscriptionService for SubscriptionServiceImpl {
1603
1620
.and_then(|c| c.subscription_plans)
1604
1621
.unwrap_or_default();
1605
1622
1623
+
// Use monthly_credits when set (nano USD); else monthly_tokens → nano USD at 1.5 USD per M tokens. Never fail for missing config.
1624
+
let plan_limit_max = |config:&SubscriptionPlanConfig| {
1625
+
ifletSome(ref lim) = config.monthly_credits{
1626
+
return lim.max;
1627
+
}
1628
+
ifletSome(ref lim) = config.monthly_tokens{
1629
+
// fallback: 1.5 USD per M tokens => limit_nano_usd = (monthly_tokens / M) * 1.5 * 1e9
1630
+
let nano_usd = (lim.maxasu128*NANO_USD_PER_1_5_USDasu128
0 commit comments