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
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/zap-proto/zip"
|
|
|
|
"github.com/hanzoai/commerce/datastore"
|
|
"github.com/hanzoai/commerce/log"
|
|
"github.com/hanzoai/commerce/middleware"
|
|
"github.com/hanzoai/commerce/models/order"
|
|
"github.com/hanzoai/commerce/models/types/fulfillment"
|
|
|
|
. "github.com/hanzoai/commerce/thirdparty/shipwire/types"
|
|
)
|
|
|
|
func convertHold(h Hold) fulfillment.Hold {
|
|
return fulfillment.Hold{
|
|
Type: h.Type + ":" + h.SubType,
|
|
Description: h.Description,
|
|
ExternalId: h.ExternalOrderID,
|
|
AppliedAt: h.AppliedDate.Time,
|
|
}
|
|
}
|
|
|
|
func updateHolds(c *zip.Ctx, topic string, holds []Hold) {
|
|
log.Info("Holds:\n%v", holds, c)
|
|
|
|
org := middleware.GetOrganization(c)
|
|
db := datastore.New(org.Namespaced(c.Context()))
|
|
|
|
// Handle no holds
|
|
if len(holds) == 0 {
|
|
return
|
|
}
|
|
|
|
// Grab first hold
|
|
h := holds[0]
|
|
|
|
ord := order.New(db)
|
|
id := h.ExternalOrderID
|
|
err := ord.GetById(id)
|
|
if err != nil {
|
|
log.Warn("Unable to find order '%s': %v", id, err, c)
|
|
return
|
|
}
|
|
|
|
if err := ord.GetById(id); err != nil {
|
|
log.Error("Failed decode request body: %v", err, c)
|
|
return
|
|
}
|
|
|
|
ord.Fulfillment.Status = fulfillment.Held
|
|
ord.Fulfillment.Holds = make([]fulfillment.Hold, len(holds))
|
|
for i := range holds {
|
|
ord.Fulfillment.Holds[i] = convertHold(holds[i])
|
|
}
|
|
|
|
ord.MustPut()
|
|
}
|