summaryrefslogtreecommitdiff
path: root/internal/billing/operations.go
diff options
context:
space:
mode:
authorChia <Chia@93.nz>2026-08-06 15:58:57 +1200
committerChia <Chia@93.nz>2026-08-06 15:58:57 +1200
commit3f702084d20b3c3a3ea916f3110e99b22bda60b3 (patch)
tree517f76c51025ce1ee085ea4898c60f799e5c37ea /internal/billing/operations.go
parent41e322c53d7b4b796eb377d0df9c29ecd10ba431 (diff)
feat: complete commercial developer workflowspublish-commercial-control-plane
Add tenant-safe usage observability, prepaid billing controls, API key lifecycle management, Embeddings metering, configurable billing alerts, and resilient provider health propagation. Harden Stripe failure handling, migrations, readiness, and the authenticated control-plane UI with end-to-end verification evidence.
Diffstat (limited to '')
-rw-r--r--internal/billing/operations.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/internal/billing/operations.go b/internal/billing/operations.go
index 461c59a..508ebd5 100644
--- a/internal/billing/operations.go
+++ b/internal/billing/operations.go
@@ -15,8 +15,10 @@ import (
"github.com/stripe/stripe-go/v86"
)
+type stripePortalSessionCreator func(context.Context, *stripe.BillingPortalSessionCreateParams) (*stripe.BillingPortalSession, error)
+
func (s *Service) CreatePortalSession(ctx context.Context, tenantID string) (PortalResult, error) {
- if !s.stripeEnabled || s.stripeClient == nil {
+ if !s.stripeEnabled || s.createStripePortalSession == nil {
return PortalResult{}, ErrStripeDisabled
}
customerID, err := s.ensureStripeCustomer(ctx, tenantID)
@@ -26,13 +28,13 @@ func (s *Service) CreatePortalSession(ctx context.Context, tenantID string) (Por
if customerID == "" {
return PortalResult{}, errors.New("no Stripe customer exists for this account")
}
- session, err := s.stripeClient.V1BillingPortalSessions.Create(ctx, &stripe.BillingPortalSessionCreateParams{
+ session, err := s.createStripePortalSession(ctx, &stripe.BillingPortalSessionCreateParams{
Customer: stripe.String(customerID), ReturnURL: stripe.String(s.stripePortalReturnURL),
})
if err != nil {
return PortalResult{}, fmt.Errorf("create Stripe customer portal session: %w", err)
}
- if session.URL == "" {
+ if session == nil || session.URL == "" {
return PortalResult{}, errors.New("Stripe returned an incomplete portal session")
}
return PortalResult{URL: session.URL}, nil