Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
ID id.CouponApplicationID `json:"id"`
CouponID id.CouponID `json:"coupon_id"`
SubscriptionID id.SubscriptionID `json:"subscription_id"`
AppliedAt time.Time `json:"applied_at"`
}
Application records that a coupon was applied to a subscription.
The pair (CouponID, SubscriptionID) is unique: a coupon applies to a subscription once. Redemption counting lives on Coupon.TimesRedeemed and is incremented separately, because a store that fails partway through must not leave a count that no application row explains.
type Coupon ¶
type Coupon struct {
types.Entity
ID id.CouponID `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Type CouponType `json:"type"`
Amount types.Money `json:"amount,omitempty"`
Percentage int `json:"percentage,omitempty"`
Currency string `json:"currency"`
MaxRedemptions int `json:"max_redemptions"`
TimesRedeemed int `json:"times_redeemed"`
ValidFrom *time.Time `json:"valid_from,omitempty"`
ValidUntil *time.Time `json:"valid_until,omitempty"`
AppID string `json:"app_id"`
Metadata map[string]string `json:"metadata,omitempty"`
}
type CouponType ¶
type CouponType string
const ( CouponTypePercentage CouponType = "percentage" CouponTypeAmount CouponType = "amount" )
type Store ¶
type Store interface {
Create(ctx context.Context, c *Coupon) error
Get(ctx context.Context, code string, appID string) (*Coupon, error)
GetByID(ctx context.Context, couponID id.CouponID) (*Coupon, error)
List(ctx context.Context, appID string, opts ListOpts) ([]*Coupon, error)
Update(ctx context.Context, c *Coupon) error
Delete(ctx context.Context, couponID id.CouponID) error
// Apply and IncrementRedemptions are low-level operations kept for
// backends and tests that need them separately. Engine code redeems
// through Redeem, which performs both as one unit.
Apply(ctx context.Context, subID id.SubscriptionID, couponID id.CouponID) error
ListApplied(ctx context.Context, subID id.SubscriptionID) ([]*Coupon, error)
IncrementRedemptions(ctx context.Context, couponID id.CouponID) error
// Redeem records a coupon's application and increments its redemption
// count as a single unit, enforcing the redemption cap with a
// conditional increment rather than a read followed by a write.
Redeem(ctx context.Context, subID id.SubscriptionID, couponID id.CouponID) error
}
Click to show internal directories.
Click to hide internal directories.