productcatalog

package
v1.0.0-beta.206 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPaymentTerm = InAdvancePaymentTerm

Variables

View Source
var DynamicPriceDefaultMultiplier = decimal.NewFromFloat(1)
View Source
var StripeProductTaxCodeRegexp = regexp.MustCompile(`^txcd_\d{8}$`)

Functions

This section is empty.

Types

type Addon

type Addon struct {
	AddonMeta

	// RateCards
	RateCards RateCards `json:"rateCards"`
}

func (Addon) Equal

func (a Addon) Equal(v Addon) bool

func (Addon) Validate

func (a Addon) Validate() error

type AddonMeta

type AddonMeta struct {
	EffectivePeriod

	// Key is the unique key for Add-on.
	Key string `json:"key"`

	// Version
	Version int `json:"version"`

	// Name
	Name string `json:"name"`

	// Description
	Description *string `json:"description,omitempty"`

	// Currency
	Currency currency.Code `json:"currency"`

	// Metadata
	Metadata models.Metadata `json:"metadata,omitempty"`

	// Annotations
	Annotations models.Annotations `json:"annotations,omitempty"`
}

func (AddonMeta) Equal

func (m AddonMeta) Equal(v AddonMeta) bool

func (AddonMeta) Status

func (a AddonMeta) Status() AddonStatus

Status returns the current status of the Addons

func (AddonMeta) StatusAt

func (a AddonMeta) StatusAt(t time.Time) AddonStatus

StatusAt returns the Addon status relative to time t.

func (AddonMeta) Validate

func (m AddonMeta) Validate() error

type AddonStatus

type AddonStatus string
const (
	AddonStatusDraft    AddonStatus = "draft"
	AddonStatusActive   AddonStatus = "active"
	AddonStatusArchived AddonStatus = "archived"
	AddonStatusInvalid  AddonStatus = "invalid"
)

func (AddonStatus) Values

func (s AddonStatus) Values() []string

type Alignment

type Alignment struct {
	// BillablesMustAlign indicates whether all billable items in a given phase must share the same BillingPeriodDuration.
	BillablesMustAlign bool `json:"billablesMustAlign"`
}

type AlignmentUpdate

type AlignmentUpdate struct {
	BillablesMustAlign *bool `json:"billablesMustAlign,omitempty"`
}

AlignmentUpdate is used for the nil-ish comparison of the plan service only

type BooleanEntitlementTemplate

type BooleanEntitlementTemplate struct {
	// Metadata a set of key/value pairs describing metadata for the RateCard.
	Metadata models.Metadata `json:"metadata,omitempty"`
}

func (*BooleanEntitlementTemplate) Equal

func (*BooleanEntitlementTemplate) Validate

func (t *BooleanEntitlementTemplate) Validate() error

type Commitments

type Commitments struct {
	// MinimumAmount defines the least amount the customer committed to spend.
	MinimumAmount *decimal.Decimal `json:"minimumAmount,omitempty"`

	// MaximumAmount defines the upper limit of amount the customer entitled to spend.
	MaximumAmount *decimal.Decimal `json:"maximumAmount,omitempty"`
}

func (Commitments) Equal

func (c Commitments) Equal(v Commitments) bool

func (Commitments) Validate

func (c Commitments) Validate() error

type Discount

type Discount struct {
	// contains filtered or unexported fields
}

func NewDiscountFrom

func NewDiscountFrom[T PercentageDiscount | UsageDiscount](v T) Discount

func (*Discount) AsPercentage

func (d *Discount) AsPercentage() (PercentageDiscount, error)

func (*Discount) AsUsage

func (d *Discount) AsUsage() (UsageDiscount, error)

func (*Discount) Clone

func (d *Discount) Clone() Discount

func (*Discount) FromPercentage

func (d *Discount) FromPercentage(discount PercentageDiscount)

func (*Discount) FromUsage

func (d *Discount) FromUsage(discount UsageDiscount)

func (*Discount) Hash

func (d *Discount) Hash() hasher.Hash

func (*Discount) MarshalJSON

func (d *Discount) MarshalJSON() ([]byte, error)

func (*Discount) Type

func (d *Discount) Type() DiscountType

func (*Discount) UnmarshalJSON

func (d *Discount) UnmarshalJSON(bytes []byte) error

func (*Discount) Validate

func (d *Discount) Validate() error

func (*Discount) ValidateForPrice

func (d *Discount) ValidateForPrice(price *Price) error

type DiscountType

type DiscountType string
const (
	PercentageDiscountType DiscountType = "percentage"
	UsageDiscountType      DiscountType = "usage"
)

func (DiscountType) StringValues

func (p DiscountType) StringValues() []string

func (DiscountType) Values

func (p DiscountType) Values() []DiscountType

type Discounts

type Discounts []Discount

func (Discounts) Clone

func (d Discounts) Clone() Discounts

func (Discounts) Equal

func (d Discounts) Equal(v Discounts) bool

func (Discounts) ValidateForPrice

func (d Discounts) ValidateForPrice(price *Price) error

type DynamicPrice

type DynamicPrice struct {
	Commitments `json:",inline"`

	// Multiplier defines the multiplier applied to the price.
	Multiplier decimal.Decimal `json:"multiplier"`
}

func (*DynamicPrice) Equal

func (p *DynamicPrice) Equal(v *DynamicPrice) bool

func (DynamicPrice) Validate

func (p DynamicPrice) Validate() error

type EffectivePeriod

type EffectivePeriod struct {
	// EffectiveFrom defines the time from the Plan or Addon becomes active.
	EffectiveFrom *time.Time `json:"effectiveFrom,omitempty"`

	// EffectiveTo defines the time from the Plan or Addon becomes archived.
	EffectiveTo *time.Time `json:"effectiveTo,omitempty"`
}

EffectivePeriod describes lifecycle of resource based on the time period defined by it.

func (EffectivePeriod) Equal

Equal returns true if the two EffectivePeriod objects are equal.

func (EffectivePeriod) Validate

func (p EffectivePeriod) Validate() error

type EntitlementTemplate

type EntitlementTemplate struct {
	// contains filtered or unexported fields
}

EntitlementTemplate is the template used for instantiating entitlement.Entitlement for RateCard.

func (*EntitlementTemplate) AsBoolean

func (*EntitlementTemplate) AsMetered

func (*EntitlementTemplate) AsStatic

func (*EntitlementTemplate) Equal

func (*EntitlementTemplate) FromBoolean

func (*EntitlementTemplate) FromMetered

func (*EntitlementTemplate) FromStatic

func (*EntitlementTemplate) MarshalJSON

func (e *EntitlementTemplate) MarshalJSON() ([]byte, error)

func (*EntitlementTemplate) Type

func (*EntitlementTemplate) UnmarshalJSON

func (e *EntitlementTemplate) UnmarshalJSON(bytes []byte) error

func (*EntitlementTemplate) Validate

func (e *EntitlementTemplate) Validate() error

type FlatFeeRateCard

type FlatFeeRateCard struct {
	RateCardMeta

	// BillingCadence defines the billing cadence of the RateCard in ISO8601 format.
	// When nil (null) it means it is a one time fee.
	// Example: "P1D12H"
	BillingCadence *isodate.Period `json:"billingCadence"`
}

func (*FlatFeeRateCard) AsMeta

func (r *FlatFeeRateCard) AsMeta() RateCardMeta

func (*FlatFeeRateCard) Equal

func (r *FlatFeeRateCard) Equal(v RateCard) bool

func (*FlatFeeRateCard) Feature

func (r *FlatFeeRateCard) Feature() *feature.Feature

func (*FlatFeeRateCard) GetBillingCadence

func (r *FlatFeeRateCard) GetBillingCadence() *isodate.Period

func (*FlatFeeRateCard) Key

func (r *FlatFeeRateCard) Key() string

func (*FlatFeeRateCard) Merge

func (r *FlatFeeRateCard) Merge(v RateCard) error

func (*FlatFeeRateCard) Type

func (r *FlatFeeRateCard) Type() RateCardType

func (*FlatFeeRateCard) Validate

func (r *FlatFeeRateCard) Validate() error

type FlatPrice

type FlatPrice struct {
	// Amount of the flat price.
	Amount decimal.Decimal `json:"amount"`

	// PaymentTerm defines the payment term of the flat price.
	// Defaults to InAdvancePaymentTerm.
	PaymentTerm PaymentTermType `json:"paymentTerm,omitempty"`
}

func (*FlatPrice) Equal

func (f *FlatPrice) Equal(v *FlatPrice) bool

func (*FlatPrice) Validate

func (f *FlatPrice) Validate() error

type MeteredEntitlementTemplate

type MeteredEntitlementTemplate struct {
	// Metadata a set of key/value pairs describing metadata for the RateCard.
	Metadata models.Metadata `json:"metadata,omitempty"`

	// IsSoftLimit set to `true` for allowing the subject to use the feature even if the entitlement is exhausted.
	IsSoftLimit bool `json:"isSoftLimit,omitempty"`

	// IssueAfterReset defines the amount to be automatically granted at entitlement.Entitlement creation or reset.
	IssueAfterReset *float64 `json:"issueAfterReset,omitempty"`

	// IssueAfterResetPriority defines the grant priority for the default grant.
	IssueAfterResetPriority *uint8 `json:"issueAfterResetPriority,omitempty"`

	// PreserveOverageAtReset defines whether the overage is preserved after reset.
	PreserveOverageAtReset *bool `json:"preserveOverageAtReset,omitempty"`

	// UsagePeriod defines the interval of the entitlement in ISO8601 format.
	// Defaults to the billing cadence of the rate card.
	// Example: "P1D12H"
	UsagePeriod isodate.Period `json:"usagePeriod,omitempty"`
}

func (*MeteredEntitlementTemplate) Equal

func (*MeteredEntitlementTemplate) Validate

func (t *MeteredEntitlementTemplate) Validate() error

type PackagePrice

type PackagePrice struct {
	Commitments `json:",inline"`

	Amount             decimal.Decimal `json:"amount"`
	QuantityPerPackage decimal.Decimal `json:"quantityPerPackage"`
}

func (*PackagePrice) Equal

func (p *PackagePrice) Equal(v *PackagePrice) bool

func (PackagePrice) Validate

func (p PackagePrice) Validate() error

type PaymentTermType

type PaymentTermType string
const (
	InAdvancePaymentTerm PaymentTermType = "in_advance"
	InArrearsPaymentTerm PaymentTermType = "in_arrears"
)

func (PaymentTermType) StringValues

func (p PaymentTermType) StringValues() []string

func (PaymentTermType) Values

func (p PaymentTermType) Values() []string

type PercentageDiscount

type PercentageDiscount struct {
	// Percentage defines percentage of the discount.
	Percentage models.Percentage `json:"percentage"`
}

func (PercentageDiscount) Clone

func (PercentageDiscount) Hash

func (f PercentageDiscount) Hash() hasher.Hash

func (PercentageDiscount) Validate

func (f PercentageDiscount) Validate() error

func (PercentageDiscount) ValidateForPrice

func (f PercentageDiscount) ValidateForPrice(price *Price) error

type Phase

type Phase struct {
	PhaseMeta

	// RateCards
	RateCards RateCards `json:"rateCards"`
}

func (Phase) Equal

func (p Phase) Equal(v Phase) bool

Equal returns true if the two Phases are equal.

func (Phase) Validate

func (p Phase) Validate() error

Validate validates the Phase.

type PhaseMeta

type PhaseMeta struct {
	// Key is the unique key for Phase.
	Key string `json:"key"`

	// Name is the name of the Phase.
	Name string `json:"name"`

	// Description is the detailed description of the Phase.
	Description *string `json:"description,omitempty"`

	// Metadata stores user defined metadata for Phase.
	Metadata models.Metadata `json:"metadata,omitempty"`

	// Duration is the duration of the Phase.
	Duration *isodate.Period `json:"duration"`
}

func (PhaseMeta) Equal

func (p PhaseMeta) Equal(v PhaseMeta) bool

Equal returns true if the two PhaseMetas are equal.

func (PhaseMeta) Validate

func (p PhaseMeta) Validate() error

Validate validates the PhaseMeta.

type Plan

type Plan struct {
	PlanMeta

	// Phases
	Phases []Phase `json:"phases"`
}

func (Plan) Equal

func (p Plan) Equal(o Plan) bool

Equal returns true if the two Plans are equal.

func (Plan) ValidForCreatingSubscriptions

func (p Plan) ValidForCreatingSubscriptions() error

ValidForCreatingSubscriptions checks if the Plan is valid for creating Subscriptions, a stricter version of Validate

func (Plan) Validate

func (p Plan) Validate() error

type PlanMeta

type PlanMeta struct {
	EffectivePeriod
	Alignment

	// Key is the unique key for Plan.
	Key string `json:"key"`

	// Version
	Version int `json:"version"`

	// Name
	Name string `json:"name"`

	// Description
	Description *string `json:"description,omitempty"`

	// Currency
	Currency currency.Code `json:"currency"`

	// Metadata
	Metadata models.Metadata `json:"metadata,omitempty"`
}

func (PlanMeta) Equal

func (p PlanMeta) Equal(o PlanMeta) bool

Equal returns true if the two PlanMetas are equal.

func (PlanMeta) Status

func (p PlanMeta) Status() PlanStatus

Status returns the current status of the Plan

func (PlanMeta) StatusAt

func (p PlanMeta) StatusAt(t time.Time) PlanStatus

StatusAt returns the plan status relative to time t.

func (PlanMeta) Validate

func (p PlanMeta) Validate() error

Validate validates the PlanMeta.

type PlanStatus

type PlanStatus string
const (
	DraftStatus     PlanStatus = "draft"
	ActiveStatus    PlanStatus = "active"
	ArchivedStatus  PlanStatus = "archived"
	ScheduledStatus PlanStatus = "scheduled"
	InvalidStatus   PlanStatus = "invalid"
)

func (PlanStatus) Values

func (s PlanStatus) Values() []string

type Price

type Price struct {
	// contains filtered or unexported fields
}

func NewPriceFrom

func NewPriceFrom[T FlatPrice | UnitPrice | TieredPrice | DynamicPrice | PackagePrice](v T) *Price

func (*Price) AsDynamic

func (p *Price) AsDynamic() (DynamicPrice, error)

func (*Price) AsFlat

func (p *Price) AsFlat() (FlatPrice, error)

func (*Price) AsPackage

func (p *Price) AsPackage() (PackagePrice, error)

func (*Price) AsTiered

func (p *Price) AsTiered() (TieredPrice, error)

func (*Price) AsUnit

func (p *Price) AsUnit() (UnitPrice, error)

func (*Price) Equal

func (p *Price) Equal(v *Price) bool

func (*Price) FromDynamic

func (p *Price) FromDynamic(price DynamicPrice)

func (*Price) FromFlat

func (p *Price) FromFlat(price FlatPrice)

func (*Price) FromPackage

func (p *Price) FromPackage(price PackagePrice)

func (*Price) FromTiered

func (p *Price) FromTiered(price TieredPrice)

func (*Price) FromUnit

func (p *Price) FromUnit(price UnitPrice)

func (*Price) MarshalJSON

func (p *Price) MarshalJSON() ([]byte, error)

func (*Price) Type

func (p *Price) Type() PriceType

func (*Price) UnmarshalJSON

func (p *Price) UnmarshalJSON(bytes []byte) error

func (*Price) Validate

func (p *Price) Validate() error

type PriceTier

type PriceTier struct {
	// UpToAmount defines the quantity will be contained in the tier. Inclusive.
	// If null, the tier is open-ended.
	UpToAmount *decimal.Decimal `json:"upToAmount,omitempty"`

	// FlatPrice defines the flat price component of the tier.
	FlatPrice *PriceTierFlatPrice `json:"flatPrice,omitempty"`

	// UnitPrice defines the unit price component of the tier.
	UnitPrice *PriceTierUnitPrice `json:"unitPrice,omitempty"`
}

PriceTier describes a tier of price(s).

func (PriceTier) Equal

func (p PriceTier) Equal(v PriceTier) bool

func (PriceTier) Validate

func (p PriceTier) Validate() error

type PriceTierFlatPrice

type PriceTierFlatPrice struct {
	// Amount of the flat price.
	Amount decimal.Decimal `json:"amount"`
}

func (PriceTierFlatPrice) Equal

func (PriceTierFlatPrice) Validate

func (f PriceTierFlatPrice) Validate() error

type PriceTierUnitPrice

type PriceTierUnitPrice struct {
	// Amount of the flat price.
	Amount decimal.Decimal `json:"amount"`
}

func (PriceTierUnitPrice) Equal

func (PriceTierUnitPrice) Validate

func (u PriceTierUnitPrice) Validate() error

type PriceType

type PriceType string
const (
	FlatPriceType    PriceType = "flat"
	UnitPriceType    PriceType = "unit"
	TieredPriceType  PriceType = "tiered"
	DynamicPriceType PriceType = "dynamic"
	PackagePriceType PriceType = "package"
)

func (PriceType) Values

func (p PriceType) Values() []string

type RateCard

type RateCard interface {
	models.Validator
	models.Equaler[RateCard]

	Type() RateCardType
	AsMeta() RateCardMeta
	Feature() *feature.Feature
	Key() string
	Merge(RateCard) error
	GetBillingCadence() *isodate.Period
}

type RateCardMeta

type RateCardMeta struct {
	// Key is the unique key for Plan.
	Key string `json:"key"`

	// Name of the RateCard
	Name string `json:"name"`

	// Description for the RateCard
	Description *string `json:"description,omitempty"`

	// Metadata a set of key/value pairs describing metadata for the RateCard
	Metadata models.Metadata `json:"metadata,omitempty"`

	// Feature defines optional Feature assigned to RateCard
	Feature *feature.Feature `json:"feature,omitempty"`

	// EntitlementTemplate defines the template used for instantiating entitlement.Entitlement.
	// If Feature is set then template must be provided as well.
	EntitlementTemplate *EntitlementTemplate `json:"entitlementTemplate,omitempty"`

	// TaxConfig defines provider specific tax information.
	TaxConfig *TaxConfig `json:"taxConfig,omitempty"`

	// Price defines the price for the RateCard
	Price *Price `json:"price"`

	// Discounts defines a list of discounts for the RateCard
	Discounts Discounts `json:"discounts,omitempty"`
}

func (RateCardMeta) Equal

func (r RateCardMeta) Equal(v RateCardMeta) bool

func (RateCardMeta) Validate

func (r RateCardMeta) Validate() error

type RateCardSerde

type RateCardSerde struct {
	Type RateCardType `json:"type"`
}

type RateCardType

type RateCardType string
const (
	FlatFeeRateCardType    RateCardType = "flat_fee"
	UsageBasedRateCardType RateCardType = "usage_based"
)

func (RateCardType) Values

func (s RateCardType) Values() []string

type RateCards

type RateCards []RateCard

func (RateCards) At

func (c RateCards) At(idx int) RateCard

func (RateCards) Billables

func (c RateCards) Billables() RateCards

func (RateCards) Equal

func (c RateCards) Equal(v RateCards) bool

func (RateCards) IsAligned

func (c RateCards) IsAligned() bool

func (RateCards) Validate

func (c RateCards) Validate() error

type StaticEntitlementTemplate

type StaticEntitlementTemplate struct {
	// Metadata a set of key/value pairs describing metadata for the RateCard.
	Metadata models.Metadata `json:"metadata,omitempty"`

	// Config stores a JSON parsable configuration for the entitlement.Entitlement.
	// This value is also returned when checking entitlement access, and
	// it is useful for configuring fine-grained access settings to the feature implemented in customers own system.
	Config json.RawMessage `json:"config,omitempty"`
}

func (*StaticEntitlementTemplate) Equal

func (*StaticEntitlementTemplate) Validate

func (t *StaticEntitlementTemplate) Validate() error

type StripeTaxConfig

type StripeTaxConfig struct {
	// Code stores the product tax code.
	// See: https://docs.stripe.com/tax/tax-codes
	// Example:"txcd_10000000"
	Code string `json:"code"`
}

func (*StripeTaxConfig) Equal

func (s *StripeTaxConfig) Equal(v *StripeTaxConfig) bool

func (*StripeTaxConfig) Validate

func (s *StripeTaxConfig) Validate() error

type TaxBehavior

type TaxBehavior string
const (
	InclusiveTaxBehavior TaxBehavior = "inclusive"
	ExclusiveTaxBehavior TaxBehavior = "exclusive"
)

func (TaxBehavior) Validate

func (t TaxBehavior) Validate() error

func (TaxBehavior) Values

func (t TaxBehavior) Values() []string

type TaxConfig

type TaxConfig struct {
	Behavior *TaxBehavior     `json:"behavior,omitempty"`
	Stripe   *StripeTaxConfig `json:"stripe,omitempty"`
}

TaxConfig stores the provider specific tax configs.

func MergeTaxConfigs

func MergeTaxConfigs(base, overrides *TaxConfig) *TaxConfig

func (*TaxConfig) Equal

func (c *TaxConfig) Equal(v *TaxConfig) bool

func (*TaxConfig) Validate

func (c *TaxConfig) Validate() error

type TieredPrice

type TieredPrice struct {
	Commitments `json:",inline"`

	// Mode defines whether the tier is volume-based or graduated.
	// * VolumeTieredPrice: the maximum quantity within a period determines the per-unit price
	// * GraduatedTieredPrice: pricing can change as the quantity grows
	Mode TieredPriceMode `json:"mode"`

	// Tiers defines the list of PriceTier.
	Tiers []PriceTier `json:"tiers"`
}

func (*TieredPrice) Equal

func (t *TieredPrice) Equal(v *TieredPrice) bool

func (*TieredPrice) Validate

func (t *TieredPrice) Validate() error

func (*TieredPrice) WithSortedTiers

func (t *TieredPrice) WithSortedTiers() TieredPrice

type TieredPriceMode

type TieredPriceMode string
const (
	// In `volume`-based tiering, the maximum quantity within a period determines the per unit price.
	VolumeTieredPrice TieredPriceMode = "volume"
	// In `graduated` tiering, pricing can change as the quantity grows.
	GraduatedTieredPrice TieredPriceMode = "graduated"
)

func NewTieredPriceMode

func NewTieredPriceMode(s string) (TieredPriceMode, error)

func (TieredPriceMode) StringValues

func (p TieredPriceMode) StringValues() []string

func (TieredPriceMode) Values

func (p TieredPriceMode) Values() []TieredPriceMode

type UnitPrice

type UnitPrice struct {
	Commitments `json:",inline"`

	// Amount of the unit price.
	Amount decimal.Decimal `json:"amount"`
}

func (*UnitPrice) Equal

func (u *UnitPrice) Equal(v *UnitPrice) bool

func (*UnitPrice) Validate

func (u *UnitPrice) Validate() error

type UsageBasedRateCard

type UsageBasedRateCard struct {
	RateCardMeta

	// BillingCadence defines the billing cadence of the RateCard in ISO8601 format.
	// Example: "P1D12H"
	BillingCadence isodate.Period `json:"billingCadence"`
}

func (*UsageBasedRateCard) AsMeta

func (r *UsageBasedRateCard) AsMeta() RateCardMeta

func (*UsageBasedRateCard) Equal

func (r *UsageBasedRateCard) Equal(v RateCard) bool

func (*UsageBasedRateCard) Feature

func (r *UsageBasedRateCard) Feature() *feature.Feature

func (*UsageBasedRateCard) GetBillingCadence

func (r *UsageBasedRateCard) GetBillingCadence() *isodate.Period

func (*UsageBasedRateCard) Key

func (r *UsageBasedRateCard) Key() string

func (*UsageBasedRateCard) Merge

func (r *UsageBasedRateCard) Merge(v RateCard) error

func (*UsageBasedRateCard) Type

func (r *UsageBasedRateCard) Type() RateCardType

func (*UsageBasedRateCard) Validate

func (r *UsageBasedRateCard) Validate() error

type UsageDiscount

type UsageDiscount struct {
	Quantity decimal.Decimal `json:"quantity"`
}

func (UsageDiscount) Clone

func (f UsageDiscount) Clone() UsageDiscount

func (UsageDiscount) Hash

func (f UsageDiscount) Hash() hasher.Hash

func (UsageDiscount) Validate

func (f UsageDiscount) Validate() error

func (UsageDiscount) ValidateForPrice

func (f UsageDiscount) ValidateForPrice(price *Price) error

Jump to

Keyboard shortcuts

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