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
34 lines
674 B
Go
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)
|
|
}
|
|
}
|