mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
41 lines
808 B
Go
41 lines
808 B
Go
package coupon
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/hanzoai/commerce/datastore"
|
|
"github.com/hanzoai/commerce/models/mixin"
|
|
"github.com/hanzoai/orm"
|
|
)
|
|
|
|
func init() { orm.Register[Redemption]("redemption") }
|
|
|
|
type Redemption struct {
|
|
mixin.Model[Redemption]
|
|
|
|
// Coupon code (need not be unique).
|
|
Code string `json:"code"`
|
|
}
|
|
|
|
func (r *Redemption) Load(props []datastore.Property) (err error) {
|
|
// Load supported properties
|
|
return datastore.LoadStruct(r, props)
|
|
}
|
|
|
|
func (r *Redemption) Save() (props []datastore.Property, err error) {
|
|
r.Code = strings.ToUpper(r.Code)
|
|
|
|
// Save properties
|
|
return datastore.SaveStruct(r)
|
|
}
|
|
|
|
func New(db *datastore.Datastore) *Redemption {
|
|
r := new(Redemption)
|
|
r.Init(db)
|
|
return r
|
|
}
|
|
|
|
func Query(db *datastore.Datastore) datastore.Query {
|
|
return db.Query("redemption")
|
|
}
|