forked from Nixius/authelia
1
0
Fork 0

Pricing: add Month100 to useForm, TierPremium fallback, logging

Made-with: Cursor
This commit is contained in:
Leopere 2026-03-04 18:01:54 -05:00
parent c613dc0863
commit f70250adc4
Signed by: colin
SSH Key Fingerprint: SHA256:nRPCQTeMFLdGytxRQmPVK9VXY3/ePKQ5lGRyJhT5DY8
2 changed files with 10 additions and 3 deletions

View File

@ -36,7 +36,8 @@ func (a *App) handleLanding(w http.ResponseWriter, r *http.Request) {
tier := pricing.ForCustomer(count, a.cfg.FreeTierLimit, a.cfg.YearTierLimit)
useForm := a.cfg.StripePriceID != "" || a.cfg.StripePriceIDFree != "" ||
a.cfg.StripePriceIDYear != "" || a.cfg.StripePriceIDMonth200 != ""
a.cfg.StripePriceIDYear != "" || a.cfg.StripePriceIDMonth100 != "" ||
a.cfg.StripePriceIDMonth200 != ""
data := map[string]any{
"AppURL": a.cfg.AppURL,
"Commit": version.Commit,
@ -89,7 +90,7 @@ func (a *App) handleCreateCheckout(w http.ResponseWriter, r *http.Request) {
sess, err := a.stripe.CreateCheckoutSession(email, domain, phone, count)
if err != nil {
if errors.Is(err, stripe.ErrNoPriceForTier) {
http.Error(w, "pricing not configured for current tier", http.StatusServiceUnavailable)
http.Error(w, "pricing not configured for current tier — set STRIPE_PRICE_ID or tier prices in env", http.StatusServiceUnavailable)
return
}
log.Printf("stripe checkout error: %v", err)
@ -213,7 +214,7 @@ func (a *App) handleResubscribe(w http.ResponseWriter, r *http.Request) {
sess, err := a.stripe.CreateCheckoutForCustomer(customerID, count)
if err != nil {
if errors.Is(err, stripe.ErrNoPriceForTier) {
http.Error(w, "pricing not configured for current tier", http.StatusServiceUnavailable)
http.Error(w, "pricing not configured for current tier — set STRIPE_PRICE_ID or tier prices in env", http.StatusServiceUnavailable)
return
}
log.Printf("stripe resubscribe error: %v", err)

View File

@ -45,6 +45,9 @@ func (c *Client) priceForTier(t pricing.Tier) string {
if c.cfg.StripePriceIDMonth200 != "" {
return c.cfg.StripePriceIDMonth200
}
if c.cfg.StripePriceIDMonth100 != "" {
return c.cfg.StripePriceIDMonth100
}
}
return c.cfg.StripePriceID
}
@ -53,6 +56,8 @@ func (c *Client) CreateCheckoutSession(email, customerDomain, customerPhone stri
t := pricing.ForCustomer(customerCount, c.cfg.FreeTierLimit, c.cfg.YearTierLimit)
priceID := c.priceForTier(t)
if priceID == "" {
log.Printf("stripe: no price for tier %d (count=%d freeLimit=%d yearLimit=%d); set STRIPE_PRICE_ID or tier-specific price",
t, customerCount, c.cfg.FreeTierLimit, c.cfg.YearTierLimit)
return nil, ErrNoPriceForTier
}
@ -81,6 +86,7 @@ func (c *Client) CreateCheckoutForCustomer(customerID string, customerCount int)
t := pricing.ForCustomer(customerCount, c.cfg.FreeTierLimit, c.cfg.YearTierLimit)
priceID := c.priceForTier(t)
if priceID == "" {
log.Printf("stripe: no price for tier %d (count=%d); set STRIPE_PRICE_ID or tier-specific price", t, customerCount)
return nil, ErrNoPriceForTier
}