fix: 包年 CNY / 永久 USD 分币种结账

按档位分别拼 Waffo currency,避免永久商品用 CNY 报不可用。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Logan.LiandCursor committed 2026-08-12 16:18:05 +08:00
1 parent d4c5637168
commit e8d98c993f
3 files changed
+60 -20

No files matched your search

+43 -10
View File
@@ -9,14 +9,16 @@ import (
// WaffoConfig hosted checkout settings for pancake.waffo.ai // Logan.Li
type WaffoConfig struct {
CheckoutURL string
StoreSlug string
ProductID string
ProductIDYearly string
ProductIDPerpetual string
Currency string
Environment string
SuccessURL string
CheckoutURL string
StoreSlug string
ProductID string
ProductIDYearly string
ProductIDPerpetual string
Currency string // fallback / default
CurrencyYearly string
CurrencyPerpetual string
Environment string
SuccessURL string
}
// LoadWaffoConfig reads WAFFO_* env vars (same names as OpsXShell legacy license-server). // Logan.Li
@@ -33,6 +35,19 @@ func LoadWaffoConfig() WaffoConfig {
if currency == "" {
currency = "CNY"
}
currencyYearly := strings.TrimSpace(os.Getenv("WAFFO_CURRENCY_YEARLY"))
if currencyYearly == "" {
currencyYearly = currency
}
currencyPerpetual := strings.TrimSpace(os.Getenv("WAFFO_CURRENCY_PERPETUAL"))
if currencyPerpetual == "" {
// 永久默认 USD(与 pancake 商品一致);可用环境变量覆盖。 // Logan.Li
if currency == "CNY" {
currencyPerpetual = "USD"
} else {
currencyPerpetual = currency
}
}
defaultProduct := strings.TrimSpace(os.Getenv("WAFFO_PRODUCT_ID"))
yearly := strings.TrimSpace(os.Getenv("WAFFO_PRODUCT_ID_YEARLY"))
perpetual := strings.TrimSpace(os.Getenv("WAFFO_PRODUCT_ID_PERPETUAL"))
@@ -49,6 +64,8 @@ func LoadWaffoConfig() WaffoConfig {
ProductIDYearly: yearly,
ProductIDPerpetual: perpetual,
Currency: currency,
CurrencyYearly: currencyYearly,
CurrencyPerpetual: currencyPerpetual,
Environment: env,
SuccessURL: success,
}
@@ -103,6 +120,23 @@ func productIDForPlan(cfg WaffoConfig, planType string) string {
}
}
func currencyForPlan(cfg WaffoConfig, planType string) string {
switch strings.TrimSpace(planType) {
case "yearly", "monthly":
if cfg.CurrencyYearly != "" {
return cfg.CurrencyYearly
}
case "perpetual", "lifetime":
if cfg.CurrencyPerpetual != "" {
return cfg.CurrencyPerpetual
}
}
if cfg.Currency != "" {
return cfg.Currency
}
return "CNY"
}
func checkoutTypeForPlan(planType string) string {
// OpsXShell 包年 / 永久均为 Waffo onetime 商品(包年不再走 subscription)。 // Logan.Li
_ = planType
@@ -110,7 +144,6 @@ func checkoutTypeForPlan(planType string) string {
}
func resolveBaseCheckoutURL(cfg WaffoConfig, planType string) (*url.URL, error) {
// Single WAFFO_CHECKOUT_URL only as absolute fallback when no store/products configured.
// Prefer store + per-plan product IDs so yearly/perpetual map to different Waffo SKUs.
productID := productIDForPlan(cfg, planType)
if cfg.StoreSlug != "" && productID != "" {
@@ -121,7 +154,7 @@ func resolveBaseCheckoutURL(cfg WaffoConfig, planType string) (*url.URL, error)
}
q := u.Query()
q.Set("type", checkoutTypeForPlan(planType))
q.Set("currency", cfg.Currency)
q.Set("currency", currencyForPlan(cfg, planType))
if cfg.Environment == "test" {
q.Set("test", "true")
}