forked from Nixius/authelia
Pricing: add Month100 to useForm, TierPremium fallback, logging
Made-with: Cursor
This commit is contained in:
parent
c613dc0863
commit
f70250adc4
|
|
@ -36,7 +36,8 @@ func (a *App) handleLanding(w http.ResponseWriter, r *http.Request) {
|
||||||
tier := pricing.ForCustomer(count, a.cfg.FreeTierLimit, a.cfg.YearTierLimit)
|
tier := pricing.ForCustomer(count, a.cfg.FreeTierLimit, a.cfg.YearTierLimit)
|
||||||
|
|
||||||
useForm := a.cfg.StripePriceID != "" || a.cfg.StripePriceIDFree != "" ||
|
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{
|
data := map[string]any{
|
||||||
"AppURL": a.cfg.AppURL,
|
"AppURL": a.cfg.AppURL,
|
||||||
"Commit": version.Commit,
|
"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)
|
sess, err := a.stripe.CreateCheckoutSession(email, domain, phone, count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, stripe.ErrNoPriceForTier) {
|
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
|
return
|
||||||
}
|
}
|
||||||
log.Printf("stripe checkout error: %v", err)
|
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)
|
sess, err := a.stripe.CreateCheckoutForCustomer(customerID, count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, stripe.ErrNoPriceForTier) {
|
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
|
return
|
||||||
}
|
}
|
||||||
log.Printf("stripe resubscribe error: %v", err)
|
log.Printf("stripe resubscribe error: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,9 @@ func (c *Client) priceForTier(t pricing.Tier) string {
|
||||||
if c.cfg.StripePriceIDMonth200 != "" {
|
if c.cfg.StripePriceIDMonth200 != "" {
|
||||||
return c.cfg.StripePriceIDMonth200
|
return c.cfg.StripePriceIDMonth200
|
||||||
}
|
}
|
||||||
|
if c.cfg.StripePriceIDMonth100 != "" {
|
||||||
|
return c.cfg.StripePriceIDMonth100
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return c.cfg.StripePriceID
|
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)
|
t := pricing.ForCustomer(customerCount, c.cfg.FreeTierLimit, c.cfg.YearTierLimit)
|
||||||
priceID := c.priceForTier(t)
|
priceID := c.priceForTier(t)
|
||||||
if priceID == "" {
|
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
|
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)
|
t := pricing.ForCustomer(customerCount, c.cfg.FreeTierLimit, c.cfg.YearTierLimit)
|
||||||
priceID := c.priceForTier(t)
|
priceID := c.priceForTier(t)
|
||||||
if priceID == "" {
|
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
|
return nil, ErrNoPriceForTier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue