stripe

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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

View Source
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 New

func New() *Service

New returns a Stripe service with no accounts.

func (*Service) AddPrice

func (s *Service) AddPrice(key string, spec PriceSpec) error

AddPrice adds a price to the account of the partition key, replacing a price with the same id.

func (*Service) ArchivePrice

func (s *Service) ArchivePrice(key, priceID string) error

ArchivePrice archives a price of the account of the partition key, so no new subscription can use it.

func (*Service) Handler

func (s *Service) Handler() http.Handler

func (*Service) Name

func (s *Service) Name() string

func (*Service) PartitionKey

func (s *Service) PartitionKey() string

func (*Service) Port

func (s *Service) Port() int

func (*Service) RecordUsage

func (s *Service) RecordUsage(key, subscriptionRef, priceID string, quantity int64) (string, error)

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.

func (*Service) Stateful

func (s *Service) Stateful() bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL