coupon

package
v1.46.39 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	Flat         Type = "flat"
	Percent           = "percent"
	FreeShipping      = "free-shipping"
	FreeItem          = "free-item"
)

Variables

Functions

func Query

Types

type Coupon

type Coupon struct {
	mixin.Model[Coupon]

	Name string `json:"name"`

	// Possible values: flat, percent, free_shipping.
	Type Type `json:"type"`

	// Coupon code (must be unique).
	Code_   string `json:"code" datastore:"Code"`
	RawCode string `json:"-" datastore:"-"`

	// Indicates whether or not the Code is dynamically checked (for something like user-generated coupons)
	Dynamic bool `json:"dynamic"`

	CampaignId string `json:"campaignId,omitempty"`
	ReferrerId string `json:"referrerId,omitempty"`

	// Range in which coupon is valid
	StartDate time.Time `json:"startDate"`
	EndDate   time.Time `json:"endDate"`

	// Possible values: order, product.
	Filter string `json:"filter"`

	// Indicates whether this coupon may be applied once or more than once at checkout.
	Once bool `json:"once"`

	// The number of times this coupon can be used before it is used up and useless.  0 = unlimited
	Limit int `json:"limit"`

	// Product id for product-specific coupons.
	ProductId string `json:"productId,omitempty"`

	// Whether coupon is valid.
	Enabled bool `json:"enabled" orm:"default:true"`

	// Coupon amount. $5 should be 500 (prices in basic currency unit, like cents). 10% should be 10.
	// TODO: This needs to be currency.Cents in Hanzo.
	Amount int `json:"amount"`

	// Number of times coupon was redeemed.
	Used int `json:"used"`

	// Free product with coupon
	FreeProductId string `json:"freeProductId"`
	FreeVariantId string `json:"freeVariantId"`
	FreeQuantity  int    `json:"freeQuantity"`
}

func Fake

func Fake(db *datastore.Datastore) *Coupon

func New

func New(db *datastore.Datastore) *Coupon

func (Coupon) Code

func (c Coupon) Code() string

func (*Coupon) CodeFromId

func (c *Coupon) CodeFromId(uniqueid string) string

func (Coupon) DynamicCode

func (c Coupon) DynamicCode() string

func (Coupon) ItemId

func (c Coupon) ItemId() string

func (*Coupon) Load

func (co *Coupon) Load(ps []datastore.Property) (err error)

func (*Coupon) Redeemable

func (c *Coupon) Redeemable() bool

func (*Coupon) Redemptions

func (c *Coupon) Redemptions() int

func (*Coupon) Save

func (co *Coupon) Save() (ps []datastore.Property, err error)

func (*Coupon) SaveRedemption

func (c *Coupon) SaveRedemption() error

func (Coupon) ValidFor

func (c Coupon) ValidFor(t time.Time) bool

type Redemption

type Redemption struct {
	// Time coupon was used
	CreatedAt time.Time `json:"createdAt"`

	// Coupon code or dynamic code
	Code string `json:"code"`
}

type Type

type Type string

Jump to

Keyboard shortcuts

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