Documentation
¶
Overview ¶
Package stripe provides a block-partitioned, stateful Stripe service for the API Portal's billing.
It answers the Stripe calls the API Portal makes (customers, Checkout Sessions, subscriptions, invoices, webhook endpoints, the billing page and refunds) and sends signed Stripe events to the webhook endpoints registered with it. Control endpoints under /test act as the customer and as Stripe: they pay a checkout or let it expire, change a subscription's payment status, add invoices, resend an event, fail chosen requests, and report the stored state.
Index ¶
- Constants
- type PriceSpec
- type Service
- func (s *Service) AddPrice(key string, spec PriceSpec) error
- func (s *Service) ArchivePrice(key, priceID string) error
- func (s *Service) Handler() http.Handler
- func (s *Service) Name() string
- func (s *Service) PartitionKey() string
- func (s *Service) Port() int
- func (s *Service) RecordUsage(key, subscriptionRef, priceID string, quantity int64) (string, error)
- func (s *Service) Stateful() bool
- type Tier
Constants ¶
const Port = 3022
Port is the container port used by the testbench.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PriceSpec ¶
type PriceSpec struct {
// ID is the price's id.
ID string
// Currency is an ISO 4217 code.
Currency string
// Interval is "month" or "year".
Interval string
// Metered is true for a price charged by reported usage, false for a fixed price.
Metered bool
// UnitAmount is charged per unit, in the currency's minor unit; it may have a fraction.
UnitAmount float64
// Tiers, when given, replace UnitAmount.
Tiers []Tier
// TiersMode is "volume" or "graduated" for a tiered price.
TiersMode string
// DivideBy, above one, charges per block of that many units, rounding up.
DivideBy int64
// Product names the catalog plan the price belongs to.
Product string
// Nickname is the price's name.
Nickname string
// contains filtered or unexported fields
}
PriceSpec is a price in an account, as the Moesif catalog creates it in Stripe.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the Stripe service. Each block has its own account.
func (*Service) AddPrice ¶
AddPrice adds a price to the account of the partition key, replacing a price with the same id.
func (*Service) ArchivePrice ¶
ArchivePrice archives a price of the account of the partition key, so no new subscription can use it.
func (*Service) PartitionKey ¶
func (*Service) RecordUsage ¶
RecordUsage adds a quantity to the current period's usage of a subscription's metered price, as Moesif reports the usage its billing meters count. The subscription is found by its id or by a value in its metadata; its id is returned.
type Tier ¶
type Tier struct {
// UpTo is the last quantity of the tier; zero on the last tier, which has no end.
UpTo int64
// UnitAmount is charged per unit in the tier.
UnitAmount float64
// FlatAmount is charged once when the quantity reaches the tier.
FlatAmount float64
}
Tier is one tier of a tiered price. Amounts are in the currency's minor unit and may have a fraction.