Purchases for admins only until the opening; brand images for Stripe
PURCHASES_OPEN (default false) keeps Stripe purchases to admins, also with a live key, so nobody types a real card before the opening. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -165,8 +165,10 @@ async fn public_config(State(state): St) -> Json<Value> {
|
||||
"locales": c.supported_locales,
|
||||
"password_login": c.password_login,
|
||||
"mock_payments": payments::method(c) == Some("mock"),
|
||||
// "stripe", "mock" or null; with a Stripe test key only admins can buy.
|
||||
// "stripe", "mock" or null; Stripe purchases are for admins only
|
||||
// until PURCHASES_OPEN (and always with a test key).
|
||||
"payments": payments::method(c),
|
||||
"payments_admins_only": payments::admins_only(c),
|
||||
"payments_test": c.stripe.as_ref().is_some_and(|s| s.test_mode()),
|
||||
"user_invites": c.user_invites,
|
||||
"referral_rewards": c.referral_rewards,
|
||||
|
||||
@@ -84,11 +84,17 @@ pub fn method(config: &crate::config::Config) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Stripe, if this user may pay through it (with a test key: admins only, so
|
||||
/// nobody gets packages with Stripe's test cards).
|
||||
/// Only admins can buy through Stripe: until purchases open, and always with a
|
||||
/// test key (nobody gets packages with Stripe's test cards, nobody types a
|
||||
/// real card into a test page).
|
||||
pub fn admins_only(config: &crate::config::Config) -> bool {
|
||||
!config.purchases_open || config.stripe.as_ref().is_some_and(StripeConfig::test_mode)
|
||||
}
|
||||
|
||||
/// Stripe, if this user may pay through it.
|
||||
fn stripe_for<'a>(state: &'a AppState, auth: &AuthUser) -> Result<&'a StripeConfig, ApiError> {
|
||||
let config = state.config.stripe.as_ref().ok_or(ApiError::NotFound("payment method"))?;
|
||||
if config.test_mode() && !auth.user.has_role(Role::Admin) {
|
||||
if admins_only(&state.config) && !auth.user.has_role(Role::Admin) {
|
||||
return Err(ApiError::Forbidden("purchases are being tested; they open soon".into()));
|
||||
}
|
||||
Ok(config)
|
||||
|
||||
Reference in New Issue
Block a user