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:
@@ -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