Files
commerce/models/user/hooks.go
zeekay 1943f1c093 Hanzo Commerce
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
2026-09-23 21:52:16 -07:00

42 lines
873 B
Go

package user
import (
"strings"
"github.com/hanzoai/commerce/util/crypto/sha256"
"github.com/hanzoai/commerce/util/json"
"github.com/hanzoai/commerce/util/webhook"
)
// Hooks
func (u *User) BeforeCreate() error {
u.Username = strings.ToLower(u.Username)
u.Email = strings.ToLower(u.Email)
return nil
}
func (u *User) BeforeUpdate(prev *User) error {
u.Username = strings.ToLower(u.Username)
u.Email = strings.ToLower(u.Email)
u.KYC.Hash = sha256.Hash(string(json.EncodeBytes(&u.KYC.KYCData)))
return nil
}
func (u *User) AfterCreate() error {
webhook.Emit(u.Context(), u.Namespace(), "user.created", u)
return nil
}
func (u *User) AfterUpdate(prev *User) error {
webhook.Emit(u.Context(), u.Namespace(), "user.updated", u)
return nil
}
func (u *User) AfterDelete() error {
webhook.Emit(u.Context(), u.Namespace(), "user.deleted", u)
return nil
}