Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BillingConfig ¶ added in v0.4.0
BillingConfig exposes only the fields the subscription handler needs from the global config. Keeping this a local struct avoids coupling the subscription package to the full config.Config type.
type CheckoutResponse ¶ added in v0.4.0
type CheckoutResponse struct {
CheckoutURL string `json:"checkout_url"`
}
CheckoutResponse is the response body for POST /api/v1/subscription/checkout. It carries the hosted Stripe Checkout URL that the caller must redirect to.
type CheckoutSessionParams ¶ added in v0.4.0
type CheckoutSessionParams struct {
CustomerID string
PriceID string
SuccessURL string
CancelURL string
}
CheckoutSessionParams carries the inputs required to create a checkout session.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles subscription-related HTTP requests.
func NewHandler ¶
func NewHandler( usersRepo usersRepository, notesRepo notesRepository, freeNoteLimit int, billing BillingConfig, stripeClient StripeClient, ) *Handler
NewHandler constructs a subscription Handler. stripeClient may be nil when billing is disabled — CreateCheckout will return 501 Not Implemented in that case.
func (*Handler) CreateCheckout ¶ added in v0.4.0
CreateCheckout handles POST /api/v1/subscription/checkout. It creates a Stripe Checkout session for the authenticated user, provisioning a Stripe customer on first use. It returns 501 Not Implemented when BILLING_ENABLED is false (self-hosted mode).
type StripeClient ¶ added in v0.4.0
type StripeClient interface {
// CreateCustomer provisions a new Stripe customer for the given email and
// returns the new customer id.
CreateCustomer(ctx context.Context, email string) (string, error)
// CreateCheckoutSession creates a Stripe Checkout session in subscription
// mode for the given customer and price, using the configured success /
// cancel URLs, and returns the hosted checkout URL.
CreateCheckoutSession(ctx context.Context, params CheckoutSessionParams) (string, error)
}
StripeClient is the minimal surface the checkout handler needs from Stripe. It exists as an interface so the handler can be tested without any network or SDK dependency — tests provide a fake implementation.
func NewStripeClient ¶ added in v0.4.0
func NewStripeClient(apiKey string) StripeClient
NewStripeClient returns a StripeClient that talks to the real Stripe API. It panics if apiKey is empty — the caller (route wiring) is responsible for only constructing this when BILLING_ENABLED=true with valid config.
type SubscriptionResponse ¶
type SubscriptionResponse struct {
Plan string `json:"plan"`
NoteCount int64 `json:"note_count"`
NoteLimit *int `json:"note_limit"`
}
SubscriptionResponse is the response body for GET /api/v1/subscription. NoteLimit is nil when the user is on the pro plan (unlimited notes).
type UserRecord ¶
UserRecord holds the user fields needed by the subscription handler. It is exported so that adapters in other packages can satisfy the usersRepository interface without importing the users package into subscription.