Files
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

34 lines
674 B
Go

package webhook
import (
"context"
"github.com/zap-proto/zip"
"github.com/hanzoai/commerce/models/mixin"
"github.com/hanzoai/commerce/models/webhook/tasks"
)
func Emit(ctx interface{}, org string, event string, data interface{}) {
var reqCtx context.Context
switch v := ctx.(type) {
case *zip.Ctx:
if c := v.Context(); c != nil {
reqCtx = c.(context.Context)
} else {
reqCtx = v.Context()
}
case context.Context:
reqCtx = v
}
// If we have a model, fire off a json-safe copy of it
model, ok := data.(mixin.Entity)
if ok {
tasks.Emit.Call(reqCtx, org, event, model.CloneFromJSON())
} else {
tasks.Emit.Call(reqCtx, org, event, data)
}
}