payit/internal/web/server.go
Ruidy 7e1e6e1df9
feat(stripe): add Stripe Checkout session API and tests
- Integrate Stripe Go SDK and implement a checkout service for creating
  Stripe Checkout sessions for a demo product.
- Add request/response types for checkout sessions.
- Create HTTP handler for /api/checkout to initiate sessions via POST.
- Provide comprehensive unit tests for Stripe client and web handler.
- Wire Stripe-backed endpoint in server setup.
2025-09-27 11:32:34 +02:00

31 lines
777 B
Go

package web
import (
"context"
"net/http"
stripe "github.com/rjNemo/payit/internal/stripe"
"github.com/rjNemo/payit/config"
)
type checkoutService interface {
CreateSession(context.Context, stripe.CheckoutSessionRequest) (stripe.CheckoutSessionResult, error)
}
// Handler aggregates dependencies required by HTTP handlers.
type Handler struct {
cfg config.Config
checkout checkoutService
}
// NewServer constructs the root HTTP handler, wiring Stripe-backed endpoints as they are implemented.
func NewServer(cfg config.Config) http.Handler {
checkoutSvc := stripe.NewService(cfg.StripeSecretKey, cfg.Product)
h := &Handler{cfg: cfg, checkout: checkoutSvc}
mux := http.NewServeMux()
mux.HandleFunc("/api/checkout", h.createCheckoutSession)
return mux
}