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
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package referral
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/zap-proto/zip"
|
|
|
|
"github.com/hanzoai/commerce/config"
|
|
"github.com/hanzoai/commerce/middleware"
|
|
mdlreferral "github.com/hanzoai/commerce/models/referral"
|
|
"github.com/hanzoai/commerce/models/referrer"
|
|
"github.com/hanzoai/commerce/util/rest"
|
|
)
|
|
|
|
// loadProgramConfig returns the parsed referral program config.
|
|
func loadProgramConfig() *config.ReferralProgram {
|
|
return config.GetReferralProgram()
|
|
}
|
|
|
|
// Route registers referral and referrer routes.
|
|
// This is the base layer: tracking referral codes, claims, credits, fraud.
|
|
// Affiliate/contributor routes are registered separately via api/affiliate.
|
|
func Route(r *zip.Group, args ...zip.Handler) {
|
|
tokenRequired := middleware.TokenRequired()
|
|
|
|
// --- Referral model auto-CRUD ---
|
|
rest.New(mdlreferral.Referral{}).Route(r, args...)
|
|
|
|
// --- Referral claim ---
|
|
claimGroup := r.Group("referral")
|
|
claimGroup.Use(tokenRequired)
|
|
claimGroup.Raw(http.MethodPost, "/claim", ClaimReferral)
|
|
|
|
// --- Referrer CRUD + custom endpoints ---
|
|
referrerRest := rest.New(referrer.Referrer{})
|
|
referrerRest.Create = referrerCreate(referrerRest)
|
|
referrerRest.Get = referrerGet(referrerRest)
|
|
referrerRest.GET("/me", append(args, getMyReferrer)...)
|
|
referrerRest.GET("/code/:code", append(args, getByCode)...)
|
|
referrerRest.Route(r, args...)
|
|
}
|