Files
Pulse/pkg/licensing/upgrade.go
rcourtman 52c0c831e8 licensing: send in-app Buy to the licence server purchase page
Every Buy, Upgrade and Renew action opened the Pulse Account portal on cloud.pulserelay.pro, which has returned a Cloudflare 522 since hosted Cloud was hibernated on 2026-06-01, so no one could buy from inside Pulse. The licence server now serves the same handoff-to-checkout page at https://license.pulserelay.pro/buy, using the existing portal handoff and checkout session APIs, so payment still returns to the instance and activates it.
2026-10-21 09:17:45 +01:00

104 lines
3.4 KiB
Go

package licensing
import (
"strings"
"github.com/rcourtman/pulse-go-rewrite/pkg/securityutil"
)
// DefaultUpgradeURL is used when no feature-specific URL mapping exists.
const DefaultUpgradeURL = "https://pulserelay.pro/pricing?utm_source=pulse&utm_medium=app&utm_campaign=upgrade"
// DefaultProTrialSignupURL is the legacy hosted commercial base URL used by
// compatibility paths that derive hosted entitlement refresh endpoints.
const DefaultProTrialSignupURL = "https://cloud.pulserelay.pro"
// DefaultPulseAccountPortalURL is where in-app Buy sends the operator to choose
// a plan and pay. The licence server hosts it; the earlier page on the Cloud
// host stopped answering when hosted Cloud was hibernated on 2026-06-01.
const DefaultPulseAccountPortalURL = "https://license.pulserelay.pro/buy"
// ProTrialSignupURLEnvVar overrides the legacy hosted commercial base URL.
const ProTrialSignupURLEnvVar = "PULSE_PRO_TRIAL_SIGNUP_URL"
// PulseAccountPortalURLEnvVar overrides the Pulse Account portal URL.
const PulseAccountPortalURLEnvVar = "PULSE_ACCOUNT_PORTAL_URL"
// ResolveProTrialSignupURL returns the canonical legacy hosted commercial base URL.
// Invalid overrides are ignored and the default URL is returned.
func ResolveProTrialSignupURL(override string) string {
if normalized, ok := validateExternalUpgradeURLOverride(override); ok {
return normalized
}
return DefaultProTrialSignupURL
}
// ResolvePulseAccountPortalURL returns the canonical Pulse Account portal URL.
// Invalid overrides are ignored and the default URL is returned.
func ResolvePulseAccountPortalURL(override string) string {
if normalized, ok := validateExternalUpgradeURLOverride(override); ok {
return normalized
}
return DefaultPulseAccountPortalURL
}
func validateExternalUpgradeURLOverride(raw string) (string, bool) {
raw = strings.TrimSpace(raw)
if raw == "" {
return "", false
}
parsed, err := securityutil.NormalizeAbsoluteHTTPURL(raw)
if err != nil {
return "", false
}
switch strings.ToLower(parsed.Scheme) {
case "https":
parsed.Scheme = "https"
case "http":
if !securityutil.IsLoopbackHost(parsed.Hostname()) {
return "", false
}
parsed.Scheme = "http"
default:
return "", false
}
parsed.Host = strings.ToLower(parsed.Host)
parsed.Fragment = ""
return parsed.String(), true
}
// UpgradeURLForFeature returns the canonical upgrade URL for a capability key.
func UpgradeURLForFeature(feature string) string {
if IsCompatibilityOnlyFeature(feature) {
return DefaultUpgradeURL
}
switch feature {
case FeatureRelay:
return DefaultUpgradeURL + "&feature=relay"
case FeatureMobileApp:
return DefaultUpgradeURL + "&feature=mobile_app"
case FeaturePushNotifications:
return DefaultUpgradeURL + "&feature=push_notifications"
case FeatureLongTermMetrics:
return DefaultUpgradeURL + "&feature=long_term_metrics"
case FeatureAIAutoFix:
return DefaultUpgradeURL + "&feature=ai_autofix"
case FeatureAIAlerts:
return DefaultUpgradeURL + "&feature=ai_alerts"
case FeatureRBAC:
return DefaultUpgradeURL + "&feature=rbac"
case FeatureAgentProfiles:
return DefaultUpgradeURL + "&feature=agent_profiles"
case FeatureAuditLogging:
return DefaultUpgradeURL + "&feature=audit_logging"
case FeatureAdvancedReporting:
return DefaultUpgradeURL + "&feature=advanced_reporting"
case FeatureExternalProbe:
return DefaultUpgradeURL + "&feature=external_probe"
default:
return DefaultUpgradeURL
}
}