coupon

package
v1.36.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 10 Imported by: 0

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:"code"`

	// 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