tenseleyflow/shithub / 5ec555b

Browse files

web/auth_wiring: construct Stripe Remote + thread user billing deps

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
5ec555b6ce30f3942835a63bb69f209855f9f5d4
Parents
e53d09d
Tree
9a1556e

1 changed file

StatusFile+-
M internal/web/auth_wiring.go 22 0
internal/web/auth_wiring.gomodified
@@ -24,6 +24,7 @@ import (
2424
 	"github.com/tenseleyFlow/shithub/internal/auth/secretbox"
2525
 	"github.com/tenseleyFlow/shithub/internal/auth/session"
2626
 	"github.com/tenseleyFlow/shithub/internal/auth/throttle"
27
+	"github.com/tenseleyFlow/shithub/internal/billing/stripebilling"
2728
 	"github.com/tenseleyFlow/shithub/internal/infra/config"
2829
 	"github.com/tenseleyFlow/shithub/internal/infra/storage"
2930
 	"github.com/tenseleyFlow/shithub/internal/ratelimit"
@@ -162,6 +163,20 @@ func buildAuthHandlers(
162163
 		logger.Warn("auth: no totp_key_b64 configured; 2FA enrollment routes disabled",
163164
 			"hint", "set SHITHUB_TOTP_KEY=$(openssl rand -base64 32) to enable 2FA")
164165
 	}
166
+	var stripeRemote stripebilling.Remote
167
+	if cfg.Billing.Enabled {
168
+		remote, err := stripebilling.New(stripebilling.Config{
169
+			SecretKey:     cfg.Billing.Stripe.SecretKey,
170
+			WebhookSecret: cfg.Billing.Stripe.WebhookSecret,
171
+			TeamPriceID:   cfg.Billing.Stripe.TeamPriceID,
172
+			ProPriceID:    cfg.Billing.Stripe.ProPriceID,
173
+			AutomaticTax:  cfg.Billing.Stripe.AutomaticTax,
174
+		})
175
+		if err != nil {
176
+			return nil, err
177
+		}
178
+		stripeRemote = remote
179
+	}
165180
 	return authh.New(authh.Deps{
166181
 		Logger:       logger,
167182
 		Render:       rr,
@@ -187,6 +202,13 @@ func buildAuthHandlers(
187202
 		Audit:                    audit.NewRecorder(),
188203
 		ObjectStore:              objectStore,
189204
 		OrgBillingEnabled:        cfg.Billing.Enabled,
205
+		BillingEnabled:           cfg.Billing.Enabled,
206
+		BillingGracePeriod:       cfg.Billing.GracePeriod,
207
+		Stripe:                   stripeRemote,
208
+		StripeSuccessURL:         cfg.Billing.Stripe.SuccessURL,
209
+		StripeCancelURL:          cfg.Billing.Stripe.CancelURL,
210
+		StripePortalReturnURL:    cfg.Billing.Stripe.PortalReturnURL,
211
+		BaseURL:                  cfg.Auth.BaseURL,
190212
 	})
191213
 }
192214