mirror of
https://github.com/rjNemo/payit
synced 2026-06-06 02:16:40 +00:00
- 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.
31 lines
777 B
Go
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
|
|
}
|