Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Remove MSP signup trial checkout

rcourtmanb8e47ab7fafa
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md
index d518bc8625..5c7924a20c 100644
--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md
+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md
@@ -239,8 +239,11 @@ or other self-hosted uncapped continuity plans.
`msp_growth`, and `msp_scale` plan versions, and the MSP signup routes stay
gated behind the same `PublicCloudSignupEnabled` flag as the individual
cloud signup front door. Checkout metadata produced by the MSP front door
- must mark `account_kind=msp` so provisioning seeds an operator workspace
- rather than an individual tenant.
+ must mark `account_kind=msp`, `signup_source=public_msp_signup`, and
+ `checkout_billing_mode=immediate` so provisioning seeds an operator
+ workspace as an immediately active paid account rather than an individual
+ trial tenant. Individual public Cloud signup may keep using the hosted trial
+ checkout helper; MSP public signup must not set Stripe `trial_period_days`.
6. Add or change the hosted account portal API, Pulse Account access/auth/session handling, task-first browser shell, maintained portal frontend/bundle, or account-scoped workspace/access/billing handoff through `internal/cloudcp/account/audit.go`, `internal/cloudcp/account/handlers.go`, `internal/cloudcp/auth/handlers.go`, `internal/cloudcp/auth/session.go`, `internal/cloudcp/portal/`, and `internal/cloudcp/routes.go`
That same customer-entry boundary owns the canonical hosted Cloud handoff:
public Cloud entry, secure checkout return, and returning-customer sign-in
@@ -707,8 +710,13 @@ served only when its Stripe price is configured (`CP_MSP_STARTER_PRICE_ID`,
`CP_MSP_GROWTH_PRICE_ID`, `CP_MSP_SCALE_PRICE_ID`); the signup page renders an
explicit "not open for self-serve signup yet" notice when no MSP tier price is
configured rather than offering an unbacked checkout. Checkout sessions started
-from this front door carry `account_kind=msp` and `signup_source=public_msp_signup`
-metadata so the provisioner seeds an isolated operator workspace.
+from this front door carry `account_kind=msp`, `signup_source=public_msp_signup`,
+and `checkout_billing_mode=immediate` metadata and do not set Stripe
+`trial_period_days`; MSP self-serve checkout is paid-first, while manual pilots
+or discounts belong in operator-controlled Stripe/customer support workflows
+rather than the public front door. The provisioner reads that billing-mode
+metadata so the initial Stripe account mapping is stored as active instead of
+trial before subscription webhooks catch up.
Cloud paid readiness is materially behind architecture work. The main concern is
contract coherence between pricing, entitlements, and runtime enforcement.
diff --git a/internal/cloudcp/public_cloud_signup_handlers.go b/internal/cloudcp/public_cloud_signup_handlers.go
index 82c5098499..4d76a674f7 100644
--- a/internal/cloudcp/public_cloud_signup_handlers.go
+++ b/internal/cloudcp/public_cloud_signup_handlers.go
@@ -15,6 +15,7 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/cpsec"
cpemail "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/email"
"github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/registry"
+ cpstripe "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/stripe"
pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
"github.com/rs/zerolog/log"
stripe "github.com/stripe/stripe-go/v82"
@@ -24,6 +25,9 @@ import (
const (
publicCloudSignupRequestBodyLimit = 64 * 1024
publicCloudTrialDays = 14
+ checkoutBillingModeMetadataKey = cpstripe.CheckoutBillingModeMetadataKey
+ checkoutBillingModeTrial = cpstripe.CheckoutBillingModeTrial
+ checkoutBillingModeImmediate = cpstripe.CheckoutBillingModeImmediate
)
// cloudTier represents a Cloud plan tier for public signup.
@@ -548,10 +552,22 @@ func (h *PublicCloudSignupHandlers) createCheckout(email, orgName string, tier c
}
// createTrialCheckoutSession builds a subscription-mode Stripe Checkout session
-// for a single recurring price with the standard public-signup trial, and
-// returns the redirect URL. Shared by the individual Cloud and MSP signup paths;
-// callers own price resolution, success/cancel URLs, and metadata.
+// for a single recurring price with the standard public Cloud signup trial.
func (h *PublicCloudSignupHandlers) createTrialCheckoutSession(email, priceID, successURL, cancelURL string, metadata map[string]string) (string, error) {
+ return h.createSubscriptionCheckoutSession(email, priceID, successURL, cancelURL, metadata, publicCloudTrialDays)
+}
+
+// createImmediateCheckoutSession builds a subscription-mode Stripe Checkout
+// session without a Stripe trial period.
+func (h *PublicCloudSignupHandlers) createImmediateCheckoutSession(email, priceID, successURL, cancelURL string, metadata map[string]string) (string, error) {
+ return h.createSubscriptionCheckoutSession(email, priceID, successURL, cancelURL, metadata, 0)
+}
+
+func (h *PublicCloudSignupHandlers) createSubscriptionCheckoutSession(
+ email, priceID, successURL, cancelURL string,
+ metadata map[string]string,
+ trialDays int,
+) (string, error) {
if h.cfg == nil {
return "", fmt.Errorf("control plane config is missing")
}
@@ -575,11 +591,13 @@ func (h *PublicCloudSignupHandlers) createTrialCheckoutSession(email, priceID, s
Quantity: stripe.Int64(1),
},
},
- SubscriptionData: &stripe.CheckoutSessionSubscriptionDataParams{
- TrialPeriodDays: stripe.Int64(publicCloudTrialDays),
- },
Metadata: metadata,
}
+ if trialDays > 0 {
+ params.SubscriptionData = &stripe.CheckoutSessionSubscriptionDataParams{
+ TrialPeriodDays: stripe.Int64(int64(trialDays)),
+ }
+ }
session, err := h.createCheckoutSession(params)
if err != nil {
return "", err
@@ -592,10 +610,11 @@ func (h *PublicCloudSignupHandlers) createTrialCheckoutSession(email, priceID, s
func (h *PublicCloudSignupHandlers) buildCheckoutMetadata(priceID, orgName string) map[string]string {
meta := map[string]string{
- "account_kind": string(registry.AccountKindIndividual),
- "account_display_name": orgName,
- "display_name": orgName,
- "signup_source": "public_cloud_signup",
+ "account_kind": string(registry.AccountKindIndividual),
+ "account_display_name": orgName,
+ "display_name": orgName,
+ "signup_source": "public_cloud_signup",
+ checkoutBillingModeMetadataKey: checkoutBillingModeTrial,
}
// Only accept cloud_* plan versions for public individual signup.
// MSP plans require a different signup path; reject them here to prevent
diff --git a/internal/cloudcp/public_cloud_signup_handlers_test.go b/internal/cloudcp/public_cloud_signup_handlers_test.go
index 7dbe754916..ad971b0851 100644
--- a/internal/cloudcp/public_cloud_signup_handlers_test.go
+++ b/internal/cloudcp/public_cloud_signup_handlers_test.go
@@ -125,6 +125,12 @@ func TestPublicCloudSignupHandleSignupPagePostValidRedirectsToStripe(t *testing.
if got := strings.TrimSpace(params.Metadata["signup_source"]); got != "public_cloud_signup" {
t.Fatalf("metadata signup_source=%q, want %q", got, "public_cloud_signup")
}
+ if got := strings.TrimSpace(params.Metadata[checkoutBillingModeMetadataKey]); got != checkoutBillingModeTrial {
+ t.Fatalf("metadata checkout_billing_mode=%q, want %q", got, checkoutBillingModeTrial)
+ }
+ if params.SubscriptionData == nil || params.SubscriptionData.TrialPeriodDays == nil || *params.SubscriptionData.TrialPeriodDays != int64(publicCloudTrialDays) {
+ t.Fatalf("expected individual Cloud checkout trial days %d, got %+v", publicCloudTrialDays, params.SubscriptionData)
+ }
return &stripe.CheckoutSession{URL: "https://checkout.stripe.com/c/pay/cs_test"}, nil
}
diff --git a/internal/cloudcp/public_msp_signup_handlers.go b/internal/cloudcp/public_msp_signup_handlers.go
index 9b39636739..a0ad85c147 100644
--- a/internal/cloudcp/public_msp_signup_handlers.go
+++ b/internal/cloudcp/public_msp_signup_handlers.go
@@ -140,8 +140,8 @@ var publicMSPSignupPageTemplate = template.Must(template.New("public-msp-signup-
<body>
<div class="wrap">
<div class="card">
- <h1>Start your {{.TrialDays}}-day Pulse Cloud for MSPs trial</h1>
- <p>Run Pulse for multiple clients from one hosted operator account. Each client gets an isolated workspace; you manage them all from the MSP portal. Stripe checkout securely collects a payment method, but the subscription starts with a {{.TrialDays}}-day trial and no upfront charge.</p>
+ <h1>Start Pulse Cloud for MSPs</h1>
+ <p>Run Pulse for multiple clients from one hosted operator account. Each client gets an isolated workspace; you manage them all from the MSP portal. Stripe checkout starts the selected monthly subscription and provisions your operator account after payment succeeds.</p>
{{if .ErrorMessage}}<div class="error">{{.ErrorMessage}}</div>{{end}}
{{if .Cancelled}}<div class="note">Checkout was cancelled. You can start again below.</div>{{end}}
@@ -153,9 +153,9 @@ var publicMSPSignupPageTemplate = template.Must(template.New("public-msp-signup-
{{if .ShowTierChoice}}
<label>Plan</label>
<div class="tier-group">
- {{if .HasStarter}}<label class="tier-option"><input type="radio" name="tier" value="starter" {{if eq .Tier "starter"}}checked{{end}}> <strong>Starter</strong> — up to 10 client workspaces, $149/mo after trial</label>{{end}}
- {{if .HasGrowth}}<label class="tier-option"><input type="radio" name="tier" value="growth" {{if eq .Tier "growth"}}checked{{end}}> <strong>Growth</strong> — up to 25 client workspaces, $249/mo after trial</label>{{end}}
- {{if .HasScale}}<label class="tier-option"><input type="radio" name="tier" value="scale" {{if eq .Tier "scale"}}checked{{end}}> <strong>Scale</strong> — up to 50 client workspaces, $399/mo after trial</label>{{end}}
+ {{if .HasStarter}}<label class="tier-option"><input type="radio" name="tier" value="starter" {{if eq .Tier "starter"}}checked{{end}}> <strong>Starter</strong> — up to 10 client workspaces, $149/mo</label>{{end}}
+ {{if .HasGrowth}}<label class="tier-option"><input type="radio" name="tier" value="growth" {{if eq .Tier "growth"}}checked{{end}}> <strong>Growth</strong> — up to 25 client workspaces, $249/mo</label>{{end}}
+ {{if .HasScale}}<label class="tier-option"><input type="radio" name="tier" value="scale" {{if eq .Tier "scale"}}checked{{end}}> <strong>Scale</strong> — up to 50 client workspaces, $399/mo</label>{{end}}
</div>
{{else}}
<input type="hidden" name="tier" value="{{.Tier}}">
@@ -172,8 +172,8 @@ var publicMSPSignupPageTemplate = template.Must(template.New("public-msp-signup-
<p class="fine">After checkout, we will email a Pulse Account sign-in link so you can open your MSP portal.</p>
<ol>
- <li>Stripe starts your {{.TrialDays}}-day trial securely.</li>
- <li>Pulse Cloud provisions your MSP operator account.</li>
+ <li>Stripe securely starts your MSP subscription.</li>
+ <li>Pulse Cloud provisions your MSP operator account after checkout completes.</li>
<li>The email link opens Pulse Account, where you add client workspaces and continue setup.</li>
</ol>
{{else}}
@@ -203,8 +203,8 @@ var publicMSPSignupCompleteTemplate = template.Must(template.New("public-msp-sig
<body>
<div class="wrap">
<div class="card">
- <h1>Trial checkout complete</h1>
- <p>Your {{.TrialDays}}-day Pulse Cloud for MSPs trial checkout completed. Pulse Cloud is provisioning your MSP operator account.</p>
+ <h1>Checkout complete</h1>
+ <p>Your Pulse Cloud for MSPs checkout completed. Pulse Cloud is provisioning your MSP operator account.</p>
<p>Watch your inbox for a Pulse Account sign-in link. That link lands in Pulse Account, where you can open the MSP portal, add client workspaces, and continue setup.</p>
</div>
</div>
@@ -225,7 +225,6 @@ type publicMSPSignupPageData struct {
HasStarter bool
HasGrowth bool
HasScale bool
- TrialDays int
}
// newMSPSignupPageData seeds page data from the currently configured MSP tiers
@@ -247,7 +246,6 @@ func (h *PublicCloudSignupHandlers) newMSPSignupPageData() publicMSPSignupPageDa
HasScale: hasScale,
Available: count > 0,
ShowTierChoice: count > 1,
- TrialDays: publicCloudTrialDays,
}
if def, ok := h.defaultMSPTier(); ok {
data.Tier = string(def)
@@ -257,9 +255,6 @@ func (h *PublicCloudSignupHandlers) newMSPSignupPageData() publicMSPSignupPageDa
func (h *PublicCloudSignupHandlers) renderMSPSignupPage(w http.ResponseWriter, r *http.Request, status int, data publicMSPSignupPageData) {
data.Nonce = cpsec.NonceFromContext(r.Context())
- if data.TrialDays <= 0 {
- data.TrialDays = publicCloudTrialDays
- }
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(status)
if err := publicMSPSignupPageTemplate.Execute(w, data); err != nil {
@@ -335,8 +330,7 @@ func (h *PublicCloudSignupHandlers) HandleMSPSignupComplete(w http.ResponseWrite
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := publicMSPSignupCompleteTemplate.Execute(w, publicCloudSignupCompleteData{
- Nonce: cpsec.NonceFromContext(r.Context()),
- TrialDays: publicCloudTrialDays,
+ Nonce: cpsec.NonceFromContext(r.Context()),
}); err != nil {
log.Error().Err(err).Msg("public msp signup complete page render failed")
}
@@ -346,7 +340,7 @@ func (h *PublicCloudSignupHandlers) HandleMSPPublicSignup(w http.ResponseWriter,
h.servePublicSignupCheckout(w, r,
"Invalid plan tier. Must be one of: starter, growth, scale",
"public msp signup API checkout creation failed",
- fmt.Sprintf("Checkout session created. Continue in Stripe to start your %d-day Pulse Cloud for MSPs trial and provision your operator account.", publicCloudTrialDays),
+ "Checkout session created. Continue in Stripe to start your Pulse Cloud for MSPs subscription and provision your operator account.",
func(tierRaw string) (bool, bool, func(email, orgName string) (string, error)) {
tier, ok := parseMSPTier(tierRaw)
if !ok {
@@ -379,15 +373,16 @@ func (h *PublicCloudSignupHandlers) createMSPCheckout(email, orgName string, tie
"org_name": {orgName},
"tier": {string(tier)},
})
- return h.createTrialCheckoutSession(email, priceID, successURL, cancelURL, h.buildMSPCheckoutMetadata(priceID, orgName))
+ return h.createImmediateCheckoutSession(email, priceID, successURL, cancelURL, h.buildMSPCheckoutMetadata(priceID, orgName))
}
func (h *PublicCloudSignupHandlers) buildMSPCheckoutMetadata(priceID, orgName string) map[string]string {
meta := map[string]string{
- "account_kind": string(registry.AccountKindMSP),
- "account_display_name": orgName,
- "display_name": orgName,
- "signup_source": "public_msp_signup",
+ "account_kind": string(registry.AccountKindMSP),
+ "account_display_name": orgName,
+ "display_name": orgName,
+ "signup_source": "public_msp_signup",
+ checkoutBillingModeMetadataKey: checkoutBillingModeImmediate,
}
// Only accept msp_* plan versions on the MSP signup path. This is the
// mirror of the individual path's cloud_* guard: it prevents granting
diff --git a/internal/cloudcp/public_msp_signup_handlers_test.go b/internal/cloudcp/public_msp_signup_handlers_test.go
index cac73fd8ab..e9a23cf45d 100644
--- a/internal/cloudcp/public_msp_signup_handlers_test.go
+++ b/internal/cloudcp/public_msp_signup_handlers_test.go
@@ -2,7 +2,6 @@ package cloudcp
import (
"encoding/json"
- "fmt"
"net/http"
"net/http/httptest"
"net/url"
@@ -108,8 +107,11 @@ func TestMSPSignupPageRendersFormWhenTierConfigured(t *testing.T) {
if !strings.Contains(body, "<form") {
t.Fatal("expected signup form when an MSP tier is configured")
}
- if !strings.Contains(body, fmt.Sprintf("Start your %d-day Pulse Cloud for MSPs trial", publicCloudTrialDays)) {
- t.Fatal("expected MSP trial heading")
+ if !strings.Contains(body, "Start Pulse Cloud for MSPs") {
+ t.Fatal("expected MSP paid signup heading")
+ }
+ if strings.Contains(strings.ToLower(body), "trial") {
+ t.Fatal("MSP signup page should not advertise a trial")
}
if !strings.Contains(body, `action="/cloud/msp/signup"`) {
t.Fatal("expected form to post to the canonical MSP signup path")
@@ -152,9 +154,9 @@ func TestMSPSignupPostValidRedirectsToStripeWithMSPMetadata(t *testing.T) {
CloudMSPStarterPriceID: testMSPStarterPriceID,
}, nil, nil, nil)
- var meta map[string]string
+ var captured *stripe.CheckoutSessionParams
h.createCheckoutSession = func(params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) {
- meta = params.Metadata
+ captured = params
return &stripe.CheckoutSession{URL: "https://checkout.stripe.com/c/pay/cs_msp"}, nil
}
@@ -171,9 +173,13 @@ func TestMSPSignupPostValidRedirectsToStripeWithMSPMetadata(t *testing.T) {
if loc := rec.Header().Get("Location"); loc != "https://checkout.stripe.com/c/pay/cs_msp" {
t.Fatalf("location=%q, want stripe URL", loc)
}
- if meta == nil {
+ if captured == nil || captured.Metadata == nil {
t.Fatal("expected checkout metadata")
}
+ if captured.SubscriptionData != nil {
+ t.Fatalf("MSP checkout should not set trial subscription data, got %+v", captured.SubscriptionData)
+ }
+ meta := captured.Metadata
if got := meta["account_kind"]; got != "msp" {
t.Fatalf("account_kind=%q, want %q", got, "msp")
}
@@ -186,6 +192,9 @@ func TestMSPSignupPostValidRedirectsToStripeWithMSPMetadata(t *testing.T) {
if got := meta["account_display_name"]; got != "Quesys MSP" {
t.Fatalf("account_display_name=%q, want %q", got, "Quesys MSP")
}
+ if got := meta[checkoutBillingModeMetadataKey]; got != checkoutBillingModeImmediate {
+ t.Fatalf("checkout_billing_mode=%q, want %q", got, checkoutBillingModeImmediate)
+ }
}
func TestMSPSignupPostTierSelectionPicksPrice(t *testing.T) {
@@ -291,8 +300,10 @@ func TestMSPSignupAPICreatesCheckout(t *testing.T) {
CloudMSPGrowthPriceID: testMSPGrowthPriceID,
}, nil, nil, nil)
+ var captured *stripe.CheckoutSessionParams
var priceID string
h.createCheckoutSession = func(params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) {
+ captured = params
if len(params.LineItems) > 0 && params.LineItems[0].Price != nil {
priceID = *params.LineItems[0].Price
}
@@ -307,6 +318,15 @@ func TestMSPSignupAPICreatesCheckout(t *testing.T) {
if rec.Code != http.StatusCreated {
t.Fatalf("status=%d, want %d body=%q", rec.Code, http.StatusCreated, rec.Body.String())
}
+ if captured == nil {
+ t.Fatal("expected checkout session params")
+ }
+ if captured.SubscriptionData != nil {
+ t.Fatalf("MSP API checkout should not set trial subscription data, got %+v", captured.SubscriptionData)
+ }
+ if got := captured.Metadata[checkoutBillingModeMetadataKey]; got != checkoutBillingModeImmediate {
+ t.Fatalf("checkout_billing_mode=%q, want %q", got, checkoutBillingModeImmediate)
+ }
if priceID != testMSPGrowthPriceID {
t.Fatalf("price_id=%q, want %q", priceID, testMSPGrowthPriceID)
}
@@ -354,9 +374,12 @@ func TestMSPSignupCompleteRendersHandoff(t *testing.T) {
t.Fatalf("status=%d, want %d", rec.Code, http.StatusOK)
}
body := rec.Body.String()
- if !strings.Contains(body, "Trial checkout complete") {
+ if !strings.Contains(body, "Checkout complete") {
t.Fatal("expected completion heading")
}
+ if strings.Contains(strings.ToLower(body), "trial") {
+ t.Fatal("MSP checkout completion should not advertise a trial")
+ }
if !strings.Contains(body, "MSP portal") {
t.Fatal("expected MSP portal handoff copy")
}
diff --git a/internal/cloudcp/stripe/helpers.go b/internal/cloudcp/stripe/helpers.go
index a04069e708..633b7d5b95 100644
--- a/internal/cloudcp/stripe/helpers.go
+++ b/internal/cloudcp/stripe/helpers.go
@@ -1,9 +1,17 @@
package stripe
import (
+ "strings"
+
pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
)
+const (
+ CheckoutBillingModeMetadataKey = "checkout_billing_mode"
+ CheckoutBillingModeTrial = "trial"
+ CheckoutBillingModeImmediate = "immediate"
+)
+
// MapSubscriptionStatus converts a Stripe subscription status string to the
// internal SubscriptionState. Unknown statuses fail closed (expired).
func MapSubscriptionStatus(status string) pkglicensing.SubscriptionState {
@@ -22,6 +30,15 @@ func DerivePlanVersion(metadata map[string]string, priceID string) string {
return pkglicensing.DeriveStripePlanVersion(metadata, priceID)
}
+// InitialSubscriptionStateForCheckout resolves the initial stored billing
+// state for a checkout-created account before subscription webhooks catch up.
+func InitialSubscriptionStateForCheckout(metadata map[string]string) string {
+ if strings.EqualFold(strings.TrimSpace(metadata[CheckoutBillingModeMetadataKey]), CheckoutBillingModeImmediate) {
+ return "active"
+ }
+ return "trial"
+}
+
// IsSafeStripeID validates that a Stripe ID (cus_..., sub_...) is safe for
// use as a lookup key. Keeps the check strict to avoid filesystem surprises.
func IsSafeStripeID(stripeID string) bool {
diff --git a/internal/cloudcp/stripe/helpers_test.go b/internal/cloudcp/stripe/helpers_test.go
index 89e6cb7e88..81b958f0cb 100644
--- a/internal/cloudcp/stripe/helpers_test.go
+++ b/internal/cloudcp/stripe/helpers_test.go
@@ -127,6 +127,27 @@ func TestDerivePlanVersion(t *testing.T) {
}
}
+func TestInitialSubscriptionStateForCheckout(t *testing.T) {
+ tests := []struct {
+ name string
+ metadata map[string]string
+ want string
+ }{
+ {"missing metadata defaults to trial for legacy cloud checkouts", nil, "trial"},
+ {"explicit trial metadata", map[string]string{CheckoutBillingModeMetadataKey: CheckoutBillingModeTrial}, "trial"},
+ {"explicit immediate metadata", map[string]string{CheckoutBillingModeMetadataKey: CheckoutBillingModeImmediate}, "active"},
+ {"immediate metadata is case-insensitive", map[string]string{CheckoutBillingModeMetadataKey: " Immediate "}, "active"},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := InitialSubscriptionStateForCheckout(tt.metadata); got != tt.want {
+ t.Fatalf("InitialSubscriptionStateForCheckout() = %q, want %q", got, tt.want)
+ }
+ })
+ }
+}
+
func TestPlanVersionFromMetadata(t *testing.T) {
tests := []struct {
name string
diff --git a/internal/cloudcp/stripe/provisioner.go b/internal/cloudcp/stripe/provisioner.go
index 0da96976cd..2cf70d05bb 100644
--- a/internal/cloudcp/stripe/provisioner.go
+++ b/internal/cloudcp/stripe/provisioner.go
@@ -714,7 +714,7 @@ func (p *Provisioner) HandleCheckout(ctx context.Context, session CheckoutSessio
StripeCustomerID: customerID,
StripeSubscriptionID: strings.TrimSpace(session.Subscription),
PlanVersion: planVersion,
- SubscriptionState: "trial",
+ SubscriptionState: InitialSubscriptionStateForCheckout(session.Metadata),
StripeSubItemWorkspacesID: "",
}
if err := p.registry.CreateStripeAccount(newSA); err != nil {
diff --git a/internal/cloudcp/stripe/provisioner_rollback_test.go b/internal/cloudcp/stripe/provisioner_rollback_test.go
index 377d4b0efa..53937f45dc 100644
--- a/internal/cloudcp/stripe/provisioner_rollback_test.go
+++ b/internal/cloudcp/stripe/provisioner_rollback_test.go
@@ -67,6 +67,54 @@ func newTestProvisioner(t *testing.T, reg *registry.TenantRegistry, tenantsDir s
)
}
+func TestHandleCheckoutImmediateBillingMetadataCreatesActiveStripeAccount(t *testing.T) {
+ reg := newStripeTestRegistry(t)
+ provisioner := newTestProvisioner(t, reg, t.TempDir(), nil, true)
+
+ session := CheckoutSession{
+ Customer: "cus_msp_immediate",
+ Subscription: "sub_msp_immediate",
+ CustomerEmail: "[email protected]",
+ Metadata: map[string]string{
+ "account_kind": string(registry.AccountKindMSP),
+ "account_display_name": "Quesys MSP",
+ "plan_version": "msp_starter",
+ CheckoutBillingModeMetadataKey: CheckoutBillingModeImmediate,
+ },
+ }
+ if err := provisioner.HandleCheckout(context.Background(), session); err != nil {
+ t.Fatalf("HandleCheckout: %v", err)
+ }
+
+ tenant, err := reg.GetByStripeCustomerID(session.Customer)
+ if err != nil {
+ t.Fatalf("GetByStripeCustomerID: %v", err)
+ }
+ if tenant == nil {
+ t.Fatal("expected tenant after checkout")
+ }
+ if tenant.PlanVersion != "msp_starter" {
+ t.Fatalf("tenant.PlanVersion = %q, want %q", tenant.PlanVersion, "msp_starter")
+ }
+ account, err := reg.GetAccount(tenant.AccountID)
+ if err != nil {
+ t.Fatalf("GetAccount: %v", err)
+ }
+ if account == nil || account.Kind != registry.AccountKindMSP {
+ t.Fatalf("account.Kind = %v, want %q", account, registry.AccountKindMSP)
+ }
+ sa, err := reg.GetStripeAccountByCustomerID(session.Customer)
+ if err != nil {
+ t.Fatalf("GetStripeAccountByCustomerID: %v", err)
+ }
+ if sa == nil {
+ t.Fatal("expected StripeAccount mapping")
+ }
+ if sa.SubscriptionState != "active" {
+ t.Fatalf("StripeAccount.SubscriptionState = %q, want %q", sa.SubscriptionState, "active")
+ }
+}
+
func TestProvisionWorkspaceRollbackOnContainerFailure(t *testing.T) {
reg := newStripeTestRegistry(t)
tenantsDir := t.TempDir()