Documentation
¶
Overview ¶
Package fakebilling is an in-memory billing server implementing the mcp-billing/v1 protocol (see docs/COMMERCE.md) for tests and local e2e runs: signature verification (same scheme as the real servers), Idempotency-Key replay on mutations, and failure injection.
srv := fakebilling.New("client-1", "secret")
defer srv.Close()
srv.FailNext("POST", "/accounts", 503, 2) // next two creates fail
Index ¶
- Constants
- type Account
- type Call
- type Plan
- type Server
- func (s *Server) Account(id string) (Account, bool)
- func (s *Server) CallCount(method, path string) int
- func (s *Server) Calls() []Call
- func (s *Server) ClearFailures()
- func (s *Server) FailNext(method, path string, status, times int)
- func (s *Server) SetAccountStatus(id, status string)
- func (s *Server) SetPeriodEndAnswer(v any)
- func (s *Server) SetPlans(p ...Plan)
Constants ¶
const MaxSkew = 5 * time.Minute
MaxSkew is the accepted clock difference for X-MCBB-Timestamp.
const Prefix = "/mcp-billing/v1"
Prefix is the protocol path prefix.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
ExternalID string `json:"external_id"`
PlanCode string `json:"plan_code"`
Status string `json:"status"`
PeriodEnd string `json:"period_end"`
Orders []string `json:"orders"`
}
Account is a provisioned account, keyed by external id.
type Call ¶
type Call struct {
Method, Path, IdempotencyKey string
Body map[string]any
RawBody string // exactly as received (signed bytes)
Replayed bool // answered from the idempotency store
Failed int // rejected (injected failure or missing key): the status, else 0
}
Call records one request that passed signature verification.
type Plan ¶
type Plan struct {
Code string `json:"code"`
Name string `json:"name"`
NameAr string `json:"name_ar,omitempty"`
}
Plan is a catalog plan.
type Server ¶
type Server struct {
*httptest.Server
ClientID, Secret string
// contains filtered or unexported fields
}
Server is the fake billing server. All methods are safe for concurrent use.
func (*Server) CallCount ¶
CallCount counts verified, non-replayed, non-failed requests for method path.
func (*Server) ClearFailures ¶
func (s *Server) ClearFailures()
ClearFailures drops every pending injected failure.
func (*Server) FailNext ¶
FailNext makes the next times requests matching method and path (relative to the prefix; a trailing "*" matches a prefix) answer status.
func (*Server) SetAccountStatus ¶
SetAccountStatus changes an account's status (e.g. to test reconcile).
func (*Server) SetPeriodEndAnswer ¶
SetPeriodEndAnswer makes POST /accounts answer period_end v (e.g. an epoch number or an unparseable string) instead of the stored value; nil restores the default.