Merge branch 'main' of https://git.tornberg.me/mats/go-cart-actor
All checks were successful
Build and Publish / Metadata (push) Successful in 10s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m11s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m14s

This commit is contained in:
2025-10-19 16:46:15 +02:00
17 changed files with 1433 additions and 476 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io"
"io/fs" "io/fs"
"net/http" "net/http"
"os" "os"
@@ -155,6 +156,78 @@ func (fs *FileServer) CartsHandler(w http.ResponseWriter, r *http.Request) {
}) })
} }
func (fs *FileServer) PromotionsHandler(w http.ResponseWriter, r *http.Request) {
fileName := filepath.Join(fs.dataDir, "promotions.json")
if r.Method == http.MethodGet {
file, err := os.Open(fileName)
if err != nil {
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
defer file.Close()
io.Copy(w, file)
return
}
if r.Method == http.MethodPost {
file, err := os.Create(fileName)
if err != nil {
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
defer file.Close()
io.Copy(file, r.Body)
return
}
w.WriteHeader(http.StatusMethodNotAllowed)
}
func (fs *FileServer) VoucherHandler(w http.ResponseWriter, r *http.Request) {
fileName := filepath.Join(fs.dataDir, "vouchers.json")
if r.Method == http.MethodGet {
file, err := os.Open(fileName)
if err != nil {
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
defer file.Close()
io.Copy(w, file)
return
}
if r.Method == http.MethodPost {
file, err := os.Create(fileName)
if err != nil {
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
defer file.Close()
io.Copy(file, r.Body)
return
}
w.WriteHeader(http.StatusMethodNotAllowed)
}
func (fs *FileServer) PromotionPartHandler(w http.ResponseWriter, r *http.Request) {
idStr := r.PathValue("id")
if idStr == "" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "missing id")
return
}
_, ok := isValidId(idStr)
if !ok {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "invalid id %s", idStr)
return
}
w.WriteHeader(http.StatusNotImplemented)
}
type JsonError struct { type JsonError struct {
Error string `json:"error"` Error string `json:"error"`
} }

View File

@@ -89,6 +89,10 @@ func main() {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("GET /carts", fs.CartsHandler) mux.HandleFunc("GET /carts", fs.CartsHandler)
mux.HandleFunc("GET /cart/{id}", fs.CartHandler) mux.HandleFunc("GET /cart/{id}", fs.CartHandler)
mux.HandleFunc("/promotions", fs.PromotionsHandler)
mux.HandleFunc("/vouchers", fs.VoucherHandler)
mux.HandleFunc("/promotion/{id}", fs.PromotionPartHandler)
mux.HandleFunc("/ws", hub.ServeWS) mux.HandleFunc("/ws", hub.ServeWS)
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View File

@@ -138,9 +138,18 @@ func main() {
pool: pool, pool: pool,
} }
klarnaClient := NewKlarnaClient(KlarnaPlaygroundUrl, os.Getenv("KLARNA_API_USERNAME"), os.Getenv("KLARNA_API_PASSWORD"))
syncedServer := NewPoolServer(pool, fmt.Sprintf("%s, %s", name, podIp), klarnaClient)
mux := http.NewServeMux()
if amqpUrl == "" {
log.Printf("no connection to amqp defined")
} else {
conn, err := amqp.Dial(amqpUrl) conn, err := amqp.Dial(amqpUrl)
if err != nil { if err != nil {
fmt.Errorf("failed to connect to RabbitMQ: %w", err) log.Fatalf("failed to connect to RabbitMQ: %w", err)
} }
amqpListener := actor.NewAmqpListener(conn, func(id uint64, msg []actor.ApplyResult) (any, error) { amqpListener := actor.NewAmqpListener(conn, func(id uint64, msg []actor.ApplyResult) (any, error) {
@@ -151,6 +160,47 @@ func main() {
}) })
amqpListener.DefineTopics() amqpListener.DefineTopics()
pool.AddListener(amqpListener) pool.AddListener(amqpListener)
orderHandler := NewAmqpOrderHandler(conn)
orderHandler.DefineTopics()
mux.HandleFunc("/push", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
orderId := r.URL.Query().Get("order_id")
log.Printf("Order confirmation push: %s", orderId)
order, err := klarnaClient.GetOrder(orderId)
if err != nil {
log.Printf("Error creating request: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = confirmOrder(order, orderHandler)
if err != nil {
log.Printf("Error confirming order: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = triggerOrderCompleted(syncedServer, order)
if err != nil {
log.Printf("Error processing cart message: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = klarnaClient.AcknowledgeOrder(orderId)
if err != nil {
log.Printf("Error acknowledging order: %v\n", err)
}
w.WriteHeader(http.StatusOK)
})
}
grpcSrv, err := actor.NewControlServer[*cart.CartGrain](controlPlaneConfig, pool) grpcSrv, err := actor.NewControlServer[*cart.CartGrain](controlPlaneConfig, pool)
if err != nil { if err != nil {
@@ -188,13 +238,6 @@ func main() {
} }
}(GetDiscovery()) }(GetDiscovery())
orderHandler := NewAmqpOrderHandler(conn)
orderHandler.DefineTopics()
klarnaClient := NewKlarnaClient(KlarnaPlaygroundUrl, os.Getenv("KLARNA_API_USERNAME"), os.Getenv("KLARNA_API_PASSWORD"))
syncedServer := NewPoolServer(pool, fmt.Sprintf("%s, %s", name, podIp), klarnaClient)
mux := http.NewServeMux()
mux.Handle("/cart/", http.StripPrefix("/cart", syncedServer.Serve())) mux.Handle("/cart/", http.StripPrefix("/cart", syncedServer.Serve()))
// only for local // only for local
mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) {
@@ -295,43 +338,7 @@ func main() {
//} //}
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
}) })
mux.HandleFunc("/push", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
orderId := r.URL.Query().Get("order_id")
log.Printf("Order confirmation push: %s", orderId)
order, err := klarnaClient.GetOrder(orderId)
if err != nil {
log.Printf("Error creating request: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = confirmOrder(order, orderHandler)
if err != nil {
log.Printf("Error confirming order: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = triggerOrderCompleted(syncedServer, order)
if err != nil {
log.Printf("Error processing cart message: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = klarnaClient.AcknowledgeOrder(orderId)
if err != nil {
log.Printf("Error acknowledging order: %v\n", err)
}
w.WriteHeader(http.StatusOK)
})
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte("1.0.0")) w.Write([]byte("1.0.0"))

View File

@@ -456,6 +456,10 @@ func (s *PoolServer) AddVoucherHandler(w http.ResponseWriter, r *http.Request, c
v := voucher.Service{} v := voucher.Service{}
msg, err := v.GetVoucher(data.VoucherCode) msg, err := v.GetVoucher(data.VoucherCode)
if err != nil { if err != nil {
s.ApplyLocal(cartId, &messages.PreConditionFailed{
Operation: "AddVoucher",
Error: err.Error(),
})
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error())) w.Write([]byte(err.Error()))
return err return err

View File

@@ -93,7 +93,9 @@ type CartGrain struct {
type Voucher struct { type Voucher struct {
Code string `json:"code"` Code string `json:"code"`
Rules []*messages.VoucherRule `json:"rules"` Applied bool `json:"applied"`
Rules []string `json:"rules"`
Description string `json:"description,omitempty"`
Id uint32 `json:"id"` Id uint32 `json:"id"`
Value int64 `json:"value"` Value int64 `json:"value"`
} }
@@ -127,8 +129,8 @@ func (v *Voucher) AppliesTo(cart *CartGrain) ([]*CartItem, bool) {
} }
// All voucher rules must pass (logical AND) // All voucher rules must pass (logical AND)
for _, rule := range v.Rules { for _, expr := range v.Rules {
expr := rule.GetCondition()
if expr == "" { if expr == "" {
// Empty condition treated as pass (acts like a comment / placeholder) // Empty condition treated as pass (acts like a comment / placeholder)
continue continue
@@ -249,31 +251,36 @@ func (c *CartGrain) UpdateTotals() {
for _, item := range c.Items { for _, item := range c.Items {
rowTotal := MultiplyPrice(item.Price, int64(item.Quantity)) rowTotal := MultiplyPrice(item.Price, int64(item.Quantity))
item.TotalPrice = *rowTotal
c.TotalPrice.Add(*rowTotal)
if item.OrgPrice != nil { if item.OrgPrice != nil {
diff := NewPrice() diff := NewPrice()
diff.Add(*item.OrgPrice) diff.Add(*item.OrgPrice)
diff.Subtract(item.Price) diff.Subtract(item.Price)
diff.Multiply(int64(item.Quantity))
rowTotal.Subtract(*diff)
item.Discount = diff
if diff.IncVat > 0 { if diff.IncVat > 0 {
c.TotalDiscount.Add(*diff) c.TotalDiscount.Add(*diff)
} }
} }
item.TotalPrice = *rowTotal
c.TotalPrice.Add(*rowTotal)
} }
for _, delivery := range c.Deliveries { for _, delivery := range c.Deliveries {
c.TotalPrice.Add(delivery.Price) c.TotalPrice.Add(delivery.Price)
} }
for _, voucher := range c.Vouchers { for _, voucher := range c.Vouchers {
if _, ok := voucher.AppliesTo(c); ok { _, ok := voucher.AppliesTo(c)
voucher.Applied = false
if ok {
value := NewPriceFromIncVat(voucher.Value, 25) value := NewPriceFromIncVat(voucher.Value, 25)
if c.TotalPrice.IncVat <= value.IncVat { if c.TotalPrice.IncVat <= value.IncVat {
// don't apply discounts to more than the total price // don't apply discounts to more than the total price
continue continue
} }
voucher.Applied = true
c.TotalDiscount.Add(*value) c.TotalDiscount.Add(*value)
c.TotalPrice.Subtract(*value) c.TotalPrice.Subtract(*value)
} }

View File

@@ -45,6 +45,9 @@ func NewCartMultationRegistry() actor.MutationRegistry {
actor.NewMutation(UpsertSubscriptionDetails, func() *messages.UpsertSubscriptionDetails { actor.NewMutation(UpsertSubscriptionDetails, func() *messages.UpsertSubscriptionDetails {
return &messages.UpsertSubscriptionDetails{} return &messages.UpsertSubscriptionDetails{}
}), }),
actor.NewMutation(PreConditionFailed, func() *messages.PreConditionFailed {
return &messages.PreConditionFailed{}
}),
) )
return reg return reg

View File

@@ -55,6 +55,8 @@ func AddVoucher(g *CartGrain, m *messages.AddVoucher) error {
g.lastVoucherId++ g.lastVoucherId++
g.Vouchers = append(g.Vouchers, &Voucher{ g.Vouchers = append(g.Vouchers, &Voucher{
Id: g.lastVoucherId, Id: g.lastVoucherId,
Applied: false,
Description: m.Description,
Code: m.Code, Code: m.Code,
Rules: m.VoucherRules, Rules: m.VoucherRules,
Value: m.Value, Value: m.Value,

View File

@@ -0,0 +1,7 @@
package cart
import messages "git.tornberg.me/go-cart-actor/pkg/messages"
func PreConditionFailed(g *CartGrain, m *messages.PreConditionFailed) error {
return nil
}

View File

@@ -66,7 +66,7 @@ func msgClearCart() *messages.ClearCartRequest {
return &messages.ClearCartRequest{} return &messages.ClearCartRequest{}
} }
func msgAddVoucher(code string, value int64, rules ...*messages.VoucherRule) *messages.AddVoucher { func msgAddVoucher(code string, value int64, rules ...string) *messages.AddVoucher {
return &messages.AddVoucher{Code: code, Value: value, VoucherRules: rules} return &messages.AddVoucher{Code: code, Value: value, VoucherRules: rules}
} }

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.5 // protoc-gen-go v1.36.10
// protoc v5.29.3 // protoc v6.32.1
// source: control_plane.proto // source: control_plane.proto
package messages package messages
@@ -453,65 +453,38 @@ func (x *ExpiryAnnounce) GetIds() []uint64 {
var File_control_plane_proto protoreflect.FileDescriptor var File_control_plane_proto protoreflect.FileDescriptor
var file_control_plane_proto_rawDesc = string([]byte{ const file_control_plane_proto_rawDesc = "" +
0x0a, 0x13, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x5f, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, "\n" +
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x22, "\x13control_plane.proto\x12\bmessages\"\a\n" +
0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x3c, 0x0a, 0x09, 0x50, 0x69, 0x6e, 0x67, "\x05Empty\"<\n" +
0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x01, 0x20, "\tPingReply\x12\x12\n" +
0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x6e, 0x69, "\x04host\x18\x01 \x01(\tR\x04host\x12\x1b\n" +
0x78, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x75, 0x6e, "\tunix_time\x18\x02 \x01(\x03R\bunixTime\"3\n" +
0x69, 0x78, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x33, 0x0a, 0x10, 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, "\x10NegotiateRequest\x12\x1f\n" +
0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x6b, 0x6e, "\vknown_hosts\x18\x01 \x03(\tR\n" +
0x6f, 0x77, 0x6e, 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, "knownHosts\"&\n" +
0x0a, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x48, 0x6f, 0x73, 0x74, 0x73, 0x22, 0x26, 0x0a, 0x0e, 0x4e, "\x0eNegotiateReply\x12\x14\n" +
0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x14, 0x0a, "\x05hosts\x18\x01 \x03(\tR\x05hosts\"!\n" +
0x05, 0x68, 0x6f, 0x73, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x68, 0x6f, "\rActorIdsReply\x12\x10\n" +
0x73, 0x74, 0x73, 0x22, 0x21, 0x0a, 0x0d, 0x41, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x73, 0x52, "\x03ids\x18\x01 \x03(\x04R\x03ids\"F\n" +
0x65, 0x70, 0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, "\x0eOwnerChangeAck\x12\x1a\n" +
0x04, 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0x46, 0x0a, 0x0e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x43, "\baccepted\x18\x01 \x01(\bR\baccepted\x12\x18\n" +
0x68, 0x61, 0x6e, 0x67, 0x65, 0x41, 0x63, 0x6b, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x65, "\amessage\x18\x02 \x01(\tR\amessage\"#\n" +
0x70, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x61, 0x63, 0x63, 0x65, "\rClosingNotice\x12\x12\n" +
0x70, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, "\x04host\x18\x01 \x01(\tR\x04host\"9\n" +
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x23, "\x11OwnershipAnnounce\x12\x12\n" +
0x0a, 0x0d, 0x43, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x4e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x12, "\x04host\x18\x01 \x01(\tR\x04host\x12\x10\n" +
0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, "\x03ids\x18\x02 \x03(\x04R\x03ids\"6\n" +
0x6f, 0x73, 0x74, 0x22, 0x39, 0x0a, 0x11, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, "\x0eExpiryAnnounce\x12\x12\n" +
0x41, 0x6e, 0x6e, 0x6f, 0x75, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, "\x04host\x18\x01 \x01(\tR\x04host\x12\x10\n" +
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, "\x03ids\x18\x02 \x03(\x04R\x03ids2\x8d\x03\n" +
0x69, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x04, 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0x36, "\fControlPlane\x12,\n" +
0x0a, 0x0e, 0x45, 0x78, 0x70, 0x69, 0x72, 0x79, 0x41, 0x6e, 0x6e, 0x6f, 0x75, 0x6e, 0x63, 0x65, "\x04Ping\x12\x0f.messages.Empty\x1a\x13.messages.PingReply\x12A\n" +
0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, "\tNegotiate\x12\x1a.messages.NegotiateRequest\x1a\x18.messages.NegotiateReply\x12<\n" +
0x68, 0x6f, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, "\x10GetLocalActorIds\x12\x0f.messages.Empty\x1a\x17.messages.ActorIdsReply\x12J\n" +
0x04, 0x52, 0x03, 0x69, 0x64, 0x73, 0x32, 0x8d, 0x03, 0x0a, 0x0c, 0x43, 0x6f, 0x6e, 0x74, 0x72, "\x11AnnounceOwnership\x12\x1b.messages.OwnershipAnnounce\x1a\x18.messages.OwnerChangeAck\x12D\n" +
0x6f, 0x6c, 0x50, 0x6c, 0x61, 0x6e, 0x65, 0x12, 0x2c, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, "\x0eAnnounceExpiry\x12\x18.messages.ExpiryAnnounce\x1a\x18.messages.OwnerChangeAck\x12<\n" +
0x0f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, "\aClosing\x12\x17.messages.ClosingNotice\x1a\x18.messages.OwnerChangeAckB.Z,git.tornberg.me/go-cart-actor/proto;messagesb\x06proto3"
0x1a, 0x13, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x50, 0x69, 0x6e, 0x67,
0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x41, 0x0a, 0x09, 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61,
0x74, 0x65, 0x12, 0x1a, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x4e, 0x65,
0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18,
0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69,
0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x3c, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4c,
0x6f, 0x63, 0x61, 0x6c, 0x41, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x73, 0x12, 0x0f, 0x2e, 0x6d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x17, 0x2e,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x41, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64,
0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x4a, 0x0a, 0x11, 0x41, 0x6e, 0x6e, 0x6f, 0x75, 0x6e,
0x63, 0x65, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x12, 0x1b, 0x2e, 0x6d, 0x65,
0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70,
0x41, 0x6e, 0x6e, 0x6f, 0x75, 0x6e, 0x63, 0x65, 0x1a, 0x18, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x73, 0x2e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x41,
0x63, 0x6b, 0x12, 0x44, 0x0a, 0x0e, 0x41, 0x6e, 0x6e, 0x6f, 0x75, 0x6e, 0x63, 0x65, 0x45, 0x78,
0x70, 0x69, 0x72, 0x79, 0x12, 0x18, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e,
0x45, 0x78, 0x70, 0x69, 0x72, 0x79, 0x41, 0x6e, 0x6e, 0x6f, 0x75, 0x6e, 0x63, 0x65, 0x1a, 0x18,
0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x43,
0x68, 0x61, 0x6e, 0x67, 0x65, 0x41, 0x63, 0x6b, 0x12, 0x3c, 0x0a, 0x07, 0x43, 0x6c, 0x6f, 0x73,
0x69, 0x6e, 0x67, 0x12, 0x17, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x43,
0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x4e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x1a, 0x18, 0x2e, 0x6d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x43, 0x68, 0x61,
0x6e, 0x67, 0x65, 0x41, 0x63, 0x6b, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x2e, 0x74, 0x6f,
0x72, 0x6e, 0x62, 0x65, 0x72, 0x67, 0x2e, 0x6d, 0x65, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x61, 0x72,
0x74, 0x2d, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x6d, 0x65,
0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var ( var (
file_control_plane_proto_rawDescOnce sync.Once file_control_plane_proto_rawDescOnce sync.Once

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT. // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions: // versions:
// - protoc-gen-go-grpc v1.5.1 // - protoc-gen-go-grpc v1.5.1
// - protoc v5.29.3 // - protoc v6.32.1
// source: control_plane.proto // source: control_plane.proto
package messages package messages

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.5 // protoc-gen-go v1.36.10
// protoc v5.29.3 // protoc v6.32.1
// source: messages.proto // source: messages.proto
package messages package messages
@@ -926,86 +926,19 @@ func (x *InitializeCheckout) GetPaymentInProgress() bool {
return false return false
} }
type VoucherRule struct {
state protoimpl.MessageState `protogen:"open.v1"`
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
Condition string `protobuf:"bytes,4,opt,name=condition,proto3" json:"condition,omitempty"`
Action string `protobuf:"bytes,5,opt,name=action,proto3" json:"action,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *VoucherRule) Reset() {
*x = VoucherRule{}
mi := &file_messages_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *VoucherRule) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*VoucherRule) ProtoMessage() {}
func (x *VoucherRule) ProtoReflect() protoreflect.Message {
mi := &file_messages_proto_msgTypes[12]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use VoucherRule.ProtoReflect.Descriptor instead.
func (*VoucherRule) Descriptor() ([]byte, []int) {
return file_messages_proto_rawDescGZIP(), []int{12}
}
func (x *VoucherRule) GetType() string {
if x != nil {
return x.Type
}
return ""
}
func (x *VoucherRule) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
func (x *VoucherRule) GetCondition() string {
if x != nil {
return x.Condition
}
return ""
}
func (x *VoucherRule) GetAction() string {
if x != nil {
return x.Action
}
return ""
}
type AddVoucher struct { type AddVoucher struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"` Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
VoucherRules []*VoucherRule `protobuf:"bytes,3,rep,name=voucherRules,proto3" json:"voucherRules,omitempty"` VoucherRules []string `protobuf:"bytes,3,rep,name=voucherRules,proto3" json:"voucherRules,omitempty"`
Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
func (x *AddVoucher) Reset() { func (x *AddVoucher) Reset() {
*x = AddVoucher{} *x = AddVoucher{}
mi := &file_messages_proto_msgTypes[13] mi := &file_messages_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -1017,7 +950,7 @@ func (x *AddVoucher) String() string {
func (*AddVoucher) ProtoMessage() {} func (*AddVoucher) ProtoMessage() {}
func (x *AddVoucher) ProtoReflect() protoreflect.Message { func (x *AddVoucher) ProtoReflect() protoreflect.Message {
mi := &file_messages_proto_msgTypes[13] mi := &file_messages_proto_msgTypes[12]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -1030,7 +963,7 @@ func (x *AddVoucher) ProtoReflect() protoreflect.Message {
// Deprecated: Use AddVoucher.ProtoReflect.Descriptor instead. // Deprecated: Use AddVoucher.ProtoReflect.Descriptor instead.
func (*AddVoucher) Descriptor() ([]byte, []int) { func (*AddVoucher) Descriptor() ([]byte, []int) {
return file_messages_proto_rawDescGZIP(), []int{13} return file_messages_proto_rawDescGZIP(), []int{12}
} }
func (x *AddVoucher) GetCode() string { func (x *AddVoucher) GetCode() string {
@@ -1047,13 +980,20 @@ func (x *AddVoucher) GetValue() int64 {
return 0 return 0
} }
func (x *AddVoucher) GetVoucherRules() []*VoucherRule { func (x *AddVoucher) GetVoucherRules() []string {
if x != nil { if x != nil {
return x.VoucherRules return x.VoucherRules
} }
return nil return nil
} }
func (x *AddVoucher) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
type RemoveVoucher struct { type RemoveVoucher struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
@@ -1063,7 +1003,7 @@ type RemoveVoucher struct {
func (x *RemoveVoucher) Reset() { func (x *RemoveVoucher) Reset() {
*x = RemoveVoucher{} *x = RemoveVoucher{}
mi := &file_messages_proto_msgTypes[14] mi := &file_messages_proto_msgTypes[13]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -1075,7 +1015,7 @@ func (x *RemoveVoucher) String() string {
func (*RemoveVoucher) ProtoMessage() {} func (*RemoveVoucher) ProtoMessage() {}
func (x *RemoveVoucher) ProtoReflect() protoreflect.Message { func (x *RemoveVoucher) ProtoReflect() protoreflect.Message {
mi := &file_messages_proto_msgTypes[14] mi := &file_messages_proto_msgTypes[13]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -1088,7 +1028,7 @@ func (x *RemoveVoucher) ProtoReflect() protoreflect.Message {
// Deprecated: Use RemoveVoucher.ProtoReflect.Descriptor instead. // Deprecated: Use RemoveVoucher.ProtoReflect.Descriptor instead.
func (*RemoveVoucher) Descriptor() ([]byte, []int) { func (*RemoveVoucher) Descriptor() ([]byte, []int) {
return file_messages_proto_rawDescGZIP(), []int{14} return file_messages_proto_rawDescGZIP(), []int{13}
} }
func (x *RemoveVoucher) GetId() uint32 { func (x *RemoveVoucher) GetId() uint32 {
@@ -1110,7 +1050,7 @@ type UpsertSubscriptionDetails struct {
func (x *UpsertSubscriptionDetails) Reset() { func (x *UpsertSubscriptionDetails) Reset() {
*x = UpsertSubscriptionDetails{} *x = UpsertSubscriptionDetails{}
mi := &file_messages_proto_msgTypes[15] mi := &file_messages_proto_msgTypes[14]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -1122,7 +1062,7 @@ func (x *UpsertSubscriptionDetails) String() string {
func (*UpsertSubscriptionDetails) ProtoMessage() {} func (*UpsertSubscriptionDetails) ProtoMessage() {}
func (x *UpsertSubscriptionDetails) ProtoReflect() protoreflect.Message { func (x *UpsertSubscriptionDetails) ProtoReflect() protoreflect.Message {
mi := &file_messages_proto_msgTypes[15] mi := &file_messages_proto_msgTypes[14]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -1135,7 +1075,7 @@ func (x *UpsertSubscriptionDetails) ProtoReflect() protoreflect.Message {
// Deprecated: Use UpsertSubscriptionDetails.ProtoReflect.Descriptor instead. // Deprecated: Use UpsertSubscriptionDetails.ProtoReflect.Descriptor instead.
func (*UpsertSubscriptionDetails) Descriptor() ([]byte, []int) { func (*UpsertSubscriptionDetails) Descriptor() ([]byte, []int) {
return file_messages_proto_rawDescGZIP(), []int{15} return file_messages_proto_rawDescGZIP(), []int{14}
} }
func (x *UpsertSubscriptionDetails) GetId() string { func (x *UpsertSubscriptionDetails) GetId() string {
@@ -1166,167 +1106,194 @@ func (x *UpsertSubscriptionDetails) GetData() *anypb.Any {
return nil return nil
} }
type PreConditionFailed struct {
state protoimpl.MessageState `protogen:"open.v1"`
Operation string `protobuf:"bytes,1,opt,name=operation,proto3" json:"operation,omitempty"`
Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"`
Input *anypb.Any `protobuf:"bytes,3,opt,name=input,proto3" json:"input,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *PreConditionFailed) Reset() {
*x = PreConditionFailed{}
mi := &file_messages_proto_msgTypes[15]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *PreConditionFailed) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PreConditionFailed) ProtoMessage() {}
func (x *PreConditionFailed) ProtoReflect() protoreflect.Message {
mi := &file_messages_proto_msgTypes[15]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PreConditionFailed.ProtoReflect.Descriptor instead.
func (*PreConditionFailed) Descriptor() ([]byte, []int) {
return file_messages_proto_rawDescGZIP(), []int{15}
}
func (x *PreConditionFailed) GetOperation() string {
if x != nil {
return x.Operation
}
return ""
}
func (x *PreConditionFailed) GetError() string {
if x != nil {
return x.Error
}
return ""
}
func (x *PreConditionFailed) GetInput() *anypb.Any {
if x != nil {
return x.Input
}
return nil
}
var File_messages_proto protoreflect.FileDescriptor var File_messages_proto protoreflect.FileDescriptor
var file_messages_proto_rawDesc = string([]byte{ const file_messages_proto_rawDesc = "" +
0x0a, 0x0e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, "\n" +
0x12, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, "\x0emessages.proto\x12\bmessages\x1a\x19google/protobuf/any.proto\"\x12\n" +
0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, "\x10ClearCartRequest\"\xb7\x05\n" +
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x12, 0x0a, 0x10, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x43, 0x61, "\aAddItem\x12\x17\n" +
0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xb7, 0x05, 0x0a, 0x07, 0x41, 0x64, "\aitem_id\x18\x01 \x01(\rR\x06itemId\x12\x1a\n" +
0x64, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x74, 0x65, 0x6d, 0x5f, 0x69, 0x64, "\bquantity\x18\x02 \x01(\x05R\bquantity\x12\x14\n" +
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x1a, "\x05price\x18\x03 \x01(\x03R\x05price\x12\x1a\n" +
0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, "\borgPrice\x18\t \x01(\x03R\borgPrice\x12\x10\n" +
0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, "\x03sku\x18\x04 \x01(\tR\x03sku\x12\x12\n" +
0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, "\x04name\x18\x05 \x01(\tR\x04name\x12\x14\n" +
0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x72, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x09, 0x20, 0x01, "\x05image\x18\x06 \x01(\tR\x05image\x12\x14\n" +
0x28, 0x03, 0x52, 0x08, 0x6f, 0x72, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x10, 0x0a, 0x03, "\x05stock\x18\a \x01(\x05R\x05stock\x12\x10\n" +
0x73, 0x6b, 0x75, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x6b, 0x75, 0x12, 0x12, "\x03tax\x18\b \x01(\x05R\x03tax\x12\x14\n" +
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, "\x05brand\x18\r \x01(\tR\x05brand\x12\x1a\n" +
0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, "\bcategory\x18\x0e \x01(\tR\bcategory\x12\x1c\n" +
0x09, 0x52, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x6f, 0x63, "\tcategory2\x18\x0f \x01(\tR\tcategory2\x12\x1c\n" +
0x6b, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x12, 0x10, "\tcategory3\x18\x10 \x01(\tR\tcategory3\x12\x1c\n" +
0x0a, 0x03, 0x74, 0x61, 0x78, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x74, 0x61, 0x78, "\tcategory4\x18\x11 \x01(\tR\tcategory4\x12\x1c\n" +
0x12, 0x14, 0x0a, 0x05, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, "\tcategory5\x18\x12 \x01(\tR\tcategory5\x12\x1e\n" +
0x05, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, "\n" +
0x72, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, "disclaimer\x18\n" +
0x72, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x32, 0x18, " \x01(\tR\n" +
0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x32, "disclaimer\x12 \n" +
0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x33, 0x18, 0x10, 0x20, "\varticleType\x18\v \x01(\tR\varticleType\x12\x1a\n" +
0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x33, 0x12, 0x1c, "\bsellerId\x18\x13 \x01(\tR\bsellerId\x12\x1e\n" +
0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x34, 0x18, 0x11, 0x20, 0x01, 0x28, "\n" +
0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x34, 0x12, 0x1c, 0x0a, 0x09, "sellerName\x18\x14 \x01(\tR\n" +
0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x35, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, "sellerName\x12\x18\n" +
0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x35, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x69, "\acountry\x18\x15 \x01(\tR\acountry\x12\x1e\n" +
0x73, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x72, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, "\n" +
0x64, 0x69, 0x73, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x61, 0x72, "saleStatus\x18\x18 \x01(\tR\n" +
0x74, 0x69, 0x63, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, "saleStatus\x12\x1b\n" +
0x0b, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, "\x06outlet\x18\f \x01(\tH\x00R\x06outlet\x88\x01\x01\x12\x1d\n" +
0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, "\astoreId\x18\x16 \x01(\tH\x01R\astoreId\x88\x01\x01\x12\x1f\n" +
0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x65, 0x6c, 0x6c, "\bparentId\x18\x17 \x01(\rH\x02R\bparentId\x88\x01\x01B\t\n" +
0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, "\a_outletB\n" +
0x6c, 0x6c, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, "\n" +
0x74, 0x72, 0x79, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, "\b_storeIdB\v\n" +
0x72, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x61, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, "\t_parentId\"\x1c\n" +
0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x61, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x74, "\n" +
0x75, 0x73, 0x12, 0x1b, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x6c, 0x65, 0x74, 0x18, 0x0c, 0x20, 0x01, "RemoveItem\x12\x0e\n" +
0x28, 0x09, 0x48, 0x00, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x6c, 0x65, 0x74, 0x88, 0x01, 0x01, 0x12, "\x02Id\x18\x01 \x01(\rR\x02Id\"<\n" +
0x1d, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, "\x0eChangeQuantity\x12\x0e\n" +
0x48, 0x01, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x1f, "\x02Id\x18\x01 \x01(\rR\x02Id\x12\x1a\n" +
0x0a, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x17, 0x20, 0x01, 0x28, 0x0d, "\bquantity\x18\x02 \x01(\x05R\bquantity\"\x86\x02\n" +
0x48, 0x02, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x88, 0x01, 0x01, 0x42, "\vSetDelivery\x12\x1a\n" +
0x09, 0x0a, 0x07, 0x5f, 0x6f, 0x75, 0x74, 0x6c, 0x65, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x73, "\bprovider\x18\x01 \x01(\tR\bprovider\x12\x14\n" +
0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x70, 0x61, 0x72, 0x65, 0x6e, "\x05items\x18\x02 \x03(\rR\x05items\x12<\n" +
0x74, 0x49, 0x64, 0x22, 0x1c, 0x0a, 0x0a, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x49, 0x74, 0x65, "\vpickupPoint\x18\x03 \x01(\v2\x15.messages.PickupPointH\x00R\vpickupPoint\x88\x01\x01\x12\x18\n" +
0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x49, "\acountry\x18\x04 \x01(\tR\acountry\x12\x10\n" +
0x64, 0x22, 0x3c, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x51, 0x75, 0x61, 0x6e, 0x74, "\x03zip\x18\x05 \x01(\tR\x03zip\x12\x1d\n" +
0x69, 0x74, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, "\aaddress\x18\x06 \x01(\tH\x01R\aaddress\x88\x01\x01\x12\x17\n" +
0x02, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, "\x04city\x18\a \x01(\tH\x02R\x04city\x88\x01\x01B\x0e\n" +
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22, "\f_pickupPointB\n" +
0x86, 0x02, 0x0a, 0x0b, 0x53, 0x65, 0x74, 0x44, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x12, "\n" +
0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, "\b_addressB\a\n" +
0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x69, "\x05_city\"\xf9\x01\n" +
0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, "\x0eSetPickupPoint\x12\x1e\n" +
0x73, 0x12, 0x3c, 0x0a, 0x0b, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, "\n" +
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, "deliveryId\x18\x01 \x01(\rR\n" +
0x73, 0x2e, 0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x48, 0x00, 0x52, "deliveryId\x12\x0e\n" +
0x0b, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x88, 0x01, 0x01, 0x12, "\x02id\x18\x02 \x01(\tR\x02id\x12\x17\n" +
0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, "\x04name\x18\x03 \x01(\tH\x00R\x04name\x88\x01\x01\x12\x1d\n" +
0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x7a, 0x69, 0x70, "\aaddress\x18\x04 \x01(\tH\x01R\aaddress\x88\x01\x01\x12\x17\n" +
0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x7a, 0x69, 0x70, 0x12, 0x1d, 0x0a, 0x07, 0x61, "\x04city\x18\x05 \x01(\tH\x02R\x04city\x88\x01\x01\x12\x15\n" +
0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x07, "\x03zip\x18\x06 \x01(\tH\x03R\x03zip\x88\x01\x01\x12\x1d\n" +
0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x63, 0x69, "\acountry\x18\a \x01(\tH\x04R\acountry\x88\x01\x01B\a\n" +
0x74, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x48, 0x02, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, "\x05_nameB\n" +
0x88, 0x01, 0x01, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, "\n" +
0x69, 0x6e, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x42, "\b_addressB\a\n" +
0x07, 0x0a, 0x05, 0x5f, 0x63, 0x69, 0x74, 0x79, 0x22, 0xf9, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x74, "\x05_cityB\x06\n" +
0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x64, "\x04_zipB\n" +
0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, "\n" +
0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x49, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, "\b_country\"\xd6\x01\n" +
0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x04, 0x6e, "\vPickupPoint\x12\x0e\n" +
0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x6e, 0x61, 0x6d, "\x02id\x18\x01 \x01(\tR\x02id\x12\x17\n" +
0x65, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, "\x04name\x18\x02 \x01(\tH\x00R\x04name\x88\x01\x01\x12\x1d\n" +
0x04, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, "\aaddress\x18\x03 \x01(\tH\x01R\aaddress\x88\x01\x01\x12\x17\n" +
0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x63, 0x69, 0x74, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, "\x04city\x18\x04 \x01(\tH\x02R\x04city\x88\x01\x01\x12\x15\n" +
0x09, 0x48, 0x02, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x88, 0x01, 0x01, 0x12, 0x15, 0x0a, 0x03, "\x03zip\x18\x05 \x01(\tH\x03R\x03zip\x88\x01\x01\x12\x1d\n" +
0x7a, 0x69, 0x70, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x03, 0x52, 0x03, 0x7a, 0x69, 0x70, "\acountry\x18\x06 \x01(\tH\x04R\acountry\x88\x01\x01B\a\n" +
0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x07, "\x05_nameB\n" +
0x20, 0x01, 0x28, 0x09, 0x48, 0x04, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x88, "\n" +
0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x0a, 0x0a, 0x08, 0x5f, "\b_addressB\a\n" +
0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x63, 0x69, 0x74, 0x79, "\x05_cityB\x06\n" +
0x42, 0x06, 0x0a, 0x04, 0x5f, 0x7a, 0x69, 0x70, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x63, 0x6f, 0x75, "\x04_zipB\n" +
0x6e, 0x74, 0x72, 0x79, 0x22, 0xd6, 0x01, 0x0a, 0x0b, 0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, "\n" +
0x6f, 0x69, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, "\b_country\" \n" +
0x52, 0x02, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, "\x0eRemoveDelivery\x12\x0e\n" +
0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, "\x02id\x18\x01 \x01(\rR\x02id\"\xb9\x01\n" +
0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, "\x13CreateCheckoutOrder\x12\x14\n" +
0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, "\x05terms\x18\x01 \x01(\tR\x05terms\x12\x1a\n" +
0x63, 0x69, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x48, 0x02, 0x52, 0x04, 0x63, 0x69, "\bcheckout\x18\x02 \x01(\tR\bcheckout\x12\"\n" +
0x74, 0x79, 0x88, 0x01, 0x01, 0x12, 0x15, 0x0a, 0x03, 0x7a, 0x69, 0x70, 0x18, 0x05, 0x20, 0x01, "\fconfirmation\x18\x03 \x01(\tR\fconfirmation\x12\x12\n" +
0x28, 0x09, 0x48, 0x03, 0x52, 0x03, 0x7a, 0x69, 0x70, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, "\x04push\x18\x04 \x01(\tR\x04push\x12\x1e\n" +
0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x04, 0x52, "\n" +
0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, "validation\x18\x05 \x01(\tR\n" +
0x6e, 0x61, 0x6d, 0x65, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, "validation\x12\x18\n" +
0x42, 0x07, 0x0a, 0x05, 0x5f, 0x63, 0x69, 0x74, 0x79, 0x42, 0x06, 0x0a, 0x04, 0x5f, 0x7a, 0x69, "\acountry\x18\x06 \x01(\tR\acountry\"@\n" +
0x70, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x22, 0x20, 0x0a, "\fOrderCreated\x12\x18\n" +
0x0e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x44, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x12, "\aorderId\x18\x01 \x01(\tR\aorderId\x12\x16\n" +
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x22, "\x06status\x18\x02 \x01(\tR\x06status\"\x06\n" +
0xb9, 0x01, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x6f, "\x04Noop\"t\n" +
0x75, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x65, 0x72, 0x6d, 0x73, "\x12InitializeCheckout\x12\x18\n" +
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x12, 0x1a, 0x0a, "\aorderId\x18\x01 \x01(\tR\aorderId\x12\x16\n" +
0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, "\x06status\x18\x02 \x01(\tR\x06status\x12,\n" +
0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, "\x11paymentInProgress\x18\x03 \x01(\bR\x11paymentInProgress\"|\n" +
0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, "\n" +
0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, "AddVoucher\x12\x12\n" +
0x04, 0x70, 0x75, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x75, 0x73, "\x04code\x18\x01 \x01(\tR\x04code\x12\x14\n" +
0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, "\x05value\x18\x02 \x01(\x03R\x05value\x12\"\n" +
0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, "\fvoucherRules\x18\x03 \x03(\tR\fvoucherRules\x12 \n" +
0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x06, 0x20, 0x01, "\vdescription\x18\x04 \x01(\tR\vdescription\"\x1f\n" +
0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x22, 0x40, 0x0a, 0x0c, 0x4f, "\rRemoveVoucher\x12\x0e\n" +
0x72, 0x64, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6f, "\x02id\x18\x01 \x01(\rR\x02id\"\xa7\x01\n" +
0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, "\x19UpsertSubscriptionDetails\x12\x13\n" +
0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, "\x02id\x18\x01 \x01(\tH\x00R\x02id\x88\x01\x01\x12\"\n" +
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x06, 0x0a, "\fofferingCode\x18\x02 \x01(\tR\fofferingCode\x12 \n" +
0x04, 0x4e, 0x6f, 0x6f, 0x70, 0x22, 0x74, 0x0a, 0x12, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, "\vsigningType\x18\x03 \x01(\tR\vsigningType\x12(\n" +
0x69, 0x7a, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, "\x04data\x18\x04 \x01(\v2\x14.google.protobuf.AnyR\x04dataB\x05\n" +
0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, "\x03_id\"t\n" +
0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, "\x12PreConditionFailed\x12\x1c\n" +
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2c, 0x0a, "\toperation\x18\x01 \x01(\tR\toperation\x12\x14\n" +
0x11, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, "\x05error\x18\x02 \x01(\tR\x05error\x12*\n" +
0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, "\x05input\x18\x03 \x01(\v2\x14.google.protobuf.AnyR\x05inputB.Z,git.tornberg.me/go-cart-actor/proto;messagesb\x06proto3"
0x74, 0x49, 0x6e, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x22, 0x79, 0x0a, 0x0b, 0x56,
0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79,
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x20,
0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20,
0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16,
0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x71, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x56, 0x6f, 0x75,
0x63, 0x68, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x39,
0x0a, 0x0c, 0x76, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x73, 0x18, 0x03,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e,
0x56, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x52, 0x0c, 0x76, 0x6f, 0x75,
0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x73, 0x22, 0x1f, 0x0a, 0x0d, 0x52, 0x65, 0x6d,
0x6f, 0x76, 0x65, 0x56, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x22, 0xa7, 0x01, 0x0a, 0x19, 0x55,
0x70, 0x73, 0x65, 0x72, 0x74, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f,
0x6e, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x22, 0x0a,
0x0c, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0c, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x64,
0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x54, 0x79, 0x70, 0x65,
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x54,
0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x05, 0x0a,
0x03, 0x5f, 0x69, 0x64, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x2e, 0x74, 0x6f, 0x72, 0x6e,
0x62, 0x65, 0x72, 0x67, 0x2e, 0x6d, 0x65, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x61, 0x72, 0x74, 0x2d,
0x61, 0x63, 0x74, 0x6f, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x6d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var ( var (
file_messages_proto_rawDescOnce sync.Once file_messages_proto_rawDescOnce sync.Once
@@ -1354,16 +1321,16 @@ var file_messages_proto_goTypes = []any{
(*OrderCreated)(nil), // 9: messages.OrderCreated (*OrderCreated)(nil), // 9: messages.OrderCreated
(*Noop)(nil), // 10: messages.Noop (*Noop)(nil), // 10: messages.Noop
(*InitializeCheckout)(nil), // 11: messages.InitializeCheckout (*InitializeCheckout)(nil), // 11: messages.InitializeCheckout
(*VoucherRule)(nil), // 12: messages.VoucherRule (*AddVoucher)(nil), // 12: messages.AddVoucher
(*AddVoucher)(nil), // 13: messages.AddVoucher (*RemoveVoucher)(nil), // 13: messages.RemoveVoucher
(*RemoveVoucher)(nil), // 14: messages.RemoveVoucher (*UpsertSubscriptionDetails)(nil), // 14: messages.UpsertSubscriptionDetails
(*UpsertSubscriptionDetails)(nil), // 15: messages.UpsertSubscriptionDetails (*PreConditionFailed)(nil), // 15: messages.PreConditionFailed
(*anypb.Any)(nil), // 16: google.protobuf.Any (*anypb.Any)(nil), // 16: google.protobuf.Any
} }
var file_messages_proto_depIdxs = []int32{ var file_messages_proto_depIdxs = []int32{
6, // 0: messages.SetDelivery.pickupPoint:type_name -> messages.PickupPoint 6, // 0: messages.SetDelivery.pickupPoint:type_name -> messages.PickupPoint
12, // 1: messages.AddVoucher.voucherRules:type_name -> messages.VoucherRule 16, // 1: messages.UpsertSubscriptionDetails.data:type_name -> google.protobuf.Any
16, // 2: messages.UpsertSubscriptionDetails.data:type_name -> google.protobuf.Any 16, // 2: messages.PreConditionFailed.input:type_name -> google.protobuf.Any
3, // [3:3] is the sub-list for method output_type 3, // [3:3] is the sub-list for method output_type
3, // [3:3] is the sub-list for method input_type 3, // [3:3] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name 3, // [3:3] is the sub-list for extension type_name
@@ -1380,7 +1347,7 @@ func file_messages_proto_init() {
file_messages_proto_msgTypes[4].OneofWrappers = []any{} file_messages_proto_msgTypes[4].OneofWrappers = []any{}
file_messages_proto_msgTypes[5].OneofWrappers = []any{} file_messages_proto_msgTypes[5].OneofWrappers = []any{}
file_messages_proto_msgTypes[6].OneofWrappers = []any{} file_messages_proto_msgTypes[6].OneofWrappers = []any{}
file_messages_proto_msgTypes[15].OneofWrappers = []any{} file_messages_proto_msgTypes[14].OneofWrappers = []any{}
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{ File: protoimpl.DescBuilder{

443
pkg/promotions/type_test.go Normal file
View File

@@ -0,0 +1,443 @@
package promotions
import (
"encoding/json"
"testing"
)
// sampleJSON mirrors the user's full example data (all three rules)
var sampleJSON = []byte(`[
{
"id": "1",
"name": "Summer Sale 2024",
"description": "20% off on all summer items",
"status": "active",
"priority": 1,
"startDate": "2024-06-01",
"endDate": "2024-08-31",
"conditions": [
{
"id": "group1",
"type": "group",
"operator": "AND",
"conditions": [
{
"id": "c1",
"type": "product_category",
"operator": "in",
"value": ["summer", "beachwear"],
"label": "Product category is Summer or Beachwear"
},
{
"id": "c2",
"type": "cart_total",
"operator": "greater_or_equal",
"value": 50,
"label": "Cart total is at least $50"
}
]
}
],
"actions": [
{
"id": "a1",
"type": "percentage_discount",
"value": 20,
"label": "20% discount"
}
],
"usageLimit": 1000,
"usageCount": 342,
"createdAt": "2024-05-15T10:00:00Z",
"updatedAt": "2024-05-20T14:30:00Z",
"createdBy": "admin@example.com",
"tags": ["seasonal", "summer"]
},
{
"id": "2",
"name": "VIP Customer Exclusive",
"description": "Free shipping for VIP customers",
"status": "active",
"priority": 2,
"startDate": "2024-01-01",
"endDate": null,
"conditions": [
{
"id": "c3",
"type": "customer_segment",
"operator": "equals",
"value": "vip",
"label": "Customer segment is VIP"
}
],
"actions": [
{
"id": "a2",
"type": "free_shipping",
"value": 0,
"label": "Free shipping"
}
],
"usageCount": 1523,
"createdAt": "2023-12-15T09:00:00Z",
"updatedAt": "2024-01-05T11:20:00Z",
"createdBy": "marketing@example.com",
"tags": ["vip", "loyalty"]
},
{
"id": "3",
"name": "Buy 2 Get 1 Free",
"description": "Buy 2 items, get the cheapest one free",
"status": "scheduled",
"priority": 3,
"startDate": "2024-12-01",
"endDate": "2024-12-25",
"conditions": [
{
"id": "c4",
"type": "item_quantity",
"operator": "greater_or_equal",
"value": 3,
"label": "Cart has at least 3 items"
}
],
"actions": [
{
"id": "a3",
"type": "buy_x_get_y",
"value": 0,
"config": { "buy": 2, "get": 1, "discount": 100 },
"label": "Buy 2 Get 1 Free"
}
],
"usageCount": 0,
"createdAt": "2024-11-01T08:00:00Z",
"updatedAt": "2024-11-01T08:00:00Z",
"createdBy": "admin@example.com",
"tags": ["holiday", "christmas"]
}
]`)
func TestDecodePromotionRulesBasic(t *testing.T) {
rules, err := DecodePromotionRules(sampleJSON)
if err != nil {
t.Fatalf("DecodePromotionRules failed: %v", err)
}
if len(rules) != 3 {
t.Fatalf("expected 3 rules, got %d", len(rules))
}
// Rule 1 checks
r1 := rules[0]
if r1.ID != "1" {
t.Errorf("rule[0].ID = %s, want 1", r1.ID)
}
if r1.Status != StatusActive {
t.Errorf("rule[0].Status = %s, want %s", r1.Status, StatusActive)
}
if r1.EndDate == nil || *r1.EndDate != "2024-08-31" {
t.Errorf("rule[0].EndDate = %v, want 2024-08-31", r1.EndDate)
}
if r1.UsageLimit == nil || *r1.UsageLimit != 1000 {
t.Errorf("rule[0].UsageLimit = %v, want 1000", r1.UsageLimit)
}
// Rule 2 checks
r2 := rules[1]
if r2.ID != "2" {
t.Errorf("rule[1].ID = %s, want 2", r2.ID)
}
if r2.EndDate != nil {
t.Errorf("rule[1].EndDate should be nil (from null), got %v", *r2.EndDate)
}
if r2.UsageLimit != nil {
t.Errorf("rule[1].UsageLimit should be nil (missing), got %v", *r2.UsageLimit)
}
}
func TestConditionDecoding(t *testing.T) {
rules, err := DecodePromotionRules(sampleJSON)
if err != nil {
t.Fatalf("DecodePromotionRules failed: %v", err)
}
r1 := rules[0]
if len(r1.Conditions) != 1 {
t.Fatalf("expected 1 top-level condition group, got %d", len(r1.Conditions))
}
grp, ok := r1.Conditions[0].(ConditionGroup)
if !ok {
t.Fatalf("top-level condition is not a group, type=%T", r1.Conditions[0])
}
if grp.Operator != LogicAND {
t.Errorf("group operator = %s, want AND", grp.Operator)
}
if len(grp.Conditions) != 2 {
t.Fatalf("expected 2 child conditions, got %d", len(grp.Conditions))
}
// First child: product_category condition with slice value
c0, ok := grp.Conditions[0].(BaseCondition)
if !ok {
t.Fatalf("first child not BaseCondition, got %T", grp.Conditions[0])
}
if c0.Type != CondProductCategory {
t.Errorf("first child type = %s, want %s", c0.Type, CondProductCategory)
}
if c0.Operator != OpIn {
t.Errorf("first child operator = %s, want %s", c0.Operator, OpIn)
}
if arr, ok := c0.Value.AsStringSlice(); !ok || len(arr) != 2 || arr[0] != "summer" {
t.Errorf("expected string slice value [summer,...], got %v", arr)
}
// Second child: cart_total numeric
c1, ok := grp.Conditions[1].(BaseCondition)
if !ok {
t.Fatalf("second child not BaseCondition, got %T", grp.Conditions[1])
}
if c1.Type != CondCartTotal {
t.Errorf("second child type = %s, want %s", c1.Type, CondCartTotal)
}
if val, ok := c1.Value.AsFloat64(); !ok || val != 50 {
t.Errorf("expected numeric value 50, got %v (ok=%v)", val, ok)
}
}
func TestConditionValueHelpers(t *testing.T) {
tests := []struct {
name string
jsonVal string
wantStr string
wantNum *float64
wantSS []string
wantFS []float64
}{
{
name: "string value",
jsonVal: `"vip"`,
wantStr: "vip",
},
{
name: "number value",
jsonVal: `42`,
wantNum: floatPtr(42),
},
{
name: "string slice",
jsonVal: `["a","b"]`,
wantSS: []string{"a", "b"},
},
{
name: "number slice int",
jsonVal: `[1,2,3]`,
wantFS: []float64{1, 2, 3},
},
{
name: "number slice float",
jsonVal: `[1.5,2.25]`,
wantFS: []float64{1.5, 2.25},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var cv ConditionValue
if err := json.Unmarshal([]byte(tc.jsonVal), &cv); err != nil {
t.Fatalf("unmarshal value failed: %v", err)
}
if tc.wantStr != "" {
if got, ok := cv.AsString(); !ok || got != tc.wantStr {
t.Errorf("AsString got=%q ok=%v want=%q", got, ok, tc.wantStr)
}
}
if tc.wantNum != nil {
if got, ok := cv.AsFloat64(); !ok || got != *tc.wantNum {
t.Errorf("AsFloat64 got=%v ok=%v want=%v", got, ok, *tc.wantNum)
}
}
if tc.wantSS != nil {
if got, ok := cv.AsStringSlice(); !ok || len(got) != len(tc.wantSS) || got[0] != tc.wantSS[0] {
t.Errorf("AsStringSlice got=%v ok=%v want=%v", got, ok, tc.wantSS)
}
}
if tc.wantFS != nil {
if got, ok := cv.AsFloat64Slice(); !ok || len(got) != len(tc.wantFS) {
t.Errorf("AsFloat64Slice got=%v ok=%v want=%v", got, ok, tc.wantFS)
} else {
for i := range got {
if got[i] != tc.wantFS[i] {
t.Errorf("AsFloat64Slice[%d]=%v want=%v", i, got[i], tc.wantFS[i])
}
}
}
}
})
}
}
func TestWalkConditionsTraversal(t *testing.T) {
rules, err := DecodePromotionRules(sampleJSON)
if err != nil {
t.Fatalf("DecodePromotionRules failed: %v", err)
}
visited := 0
WalkConditions(rules[0].Conditions, func(c Condition) bool {
visited++
return true
})
// group + 2 children
if visited != 3 {
t.Errorf("expected 3 visited conditions, got %d", visited)
}
}
func TestActionBundleConfigParsing(t *testing.T) {
jsonData := []byte(`[
{
"id": "bundle-1",
"name": "Bundle Deal",
"description": "Fixed price bundle",
"status": "active",
"priority": 1,
"startDate": "2024-01-01",
"endDate": null,
"conditions": [],
"actions": [
{
"id": "act-bundle",
"type": "bundle_discount",
"value": 0,
"bundleConfig": {
"containers": [
{
"id": "cont1",
"name": "Shoes",
"quantity": 2,
"selectionType": "any",
"qualifyingRules": {
"type": "category",
"value": "shoes"
}
},
{
"id": "cont2",
"name": "Socks",
"quantity": 3,
"selectionType": "specific",
"qualifyingRules": {
"type": "product_ids",
"value": ["sock-1", "sock-2"]
},
"allowedProducts": ["sock-1","sock-2"]
}
],
"pricing": {
"type": "fixed_price",
"value": 49.99
},
"requireAllContainers": true
},
"config": { "note": "Bundle applies to footwear + socks" }
}
],
"usageCount": 0,
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z",
"createdBy": "bundle@example.com",
"tags": ["bundle","footwear"]
}
]`)
rules, err := DecodePromotionRules(jsonData)
if err != nil {
t.Fatalf("decode failed: %v", err)
}
if len(rules) != 1 {
t.Fatalf("expected 1 rule, got %d", len(rules))
}
if len(rules[0].Actions) != 1 {
t.Fatalf("expected 1 action, got %d", len(rules[0].Actions))
}
act := rules[0].Actions[0]
if act.Type != ActionBundleDiscount {
t.Fatalf("action type = %s, want %s", act.Type, ActionBundleDiscount)
}
if act.BundleConfig == nil {
t.Fatalf("bundleConfig nil")
}
if act.BundleConfig.Pricing.Type != "fixed_price" {
t.Errorf("pricing.type = %s, want fixed_price", act.BundleConfig.Pricing.Type)
}
if act.BundleConfig.Pricing.Value != 49.99 {
t.Errorf("pricing.value = %v, want 49.99", act.BundleConfig.Pricing.Value)
}
if !act.BundleConfig.RequireAllContainers {
t.Errorf("RequireAllContainers expected true")
}
if len(act.BundleConfig.Containers) != 2 {
t.Fatalf("expected 2 containers, got %d", len(act.BundleConfig.Containers))
}
if act.Config == nil || act.Config["note"] != "Bundle applies to footwear + socks" {
t.Errorf("config.note mismatch: %v", act.Config)
}
}
func TestConditionValueInvalidTypes(t *testing.T) {
cases := []struct {
name string
raw string
}{
{"object", `{}`},
{"booleanTrue", `true`},
{"booleanFalse", `false`},
{"null", `null`},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var cv ConditionValue
if err := json.Unmarshal([]byte(tc.raw), &cv); err != nil {
t.Fatalf("unmarshal failed: %v", err)
}
if s, ok := cv.AsString(); ok {
t.Errorf("AsString unexpectedly succeeded (%q) for %s", s, tc.name)
}
if n, ok := cv.AsFloat64(); ok {
t.Errorf("AsFloat64 unexpectedly succeeded (%v) for %s", n, tc.name)
}
if ss, ok := cv.AsStringSlice(); ok {
t.Errorf("AsStringSlice unexpectedly succeeded (%v) for %s", ss, tc.name)
}
if fs, ok := cv.AsFloat64Slice(); ok {
t.Errorf("AsFloat64Slice unexpectedly succeeded (%v) for %s", fs, tc.name)
}
})
}
}
func TestPromotionRuleRoundTrip(t *testing.T) {
orig, err := DecodePromotionRules(sampleJSON)
if err != nil {
t.Fatalf("initial decode failed: %v", err)
}
data, err := json.Marshal(orig)
if err != nil {
t.Fatalf("marshal failed: %v", err)
}
round, err := DecodePromotionRules(data)
if err != nil {
t.Fatalf("round-trip decode failed: %v", err)
}
if len(orig) != len(round) {
t.Fatalf("rule count mismatch: orig=%d round=%d", len(orig), len(round))
}
// spot-check first rule
if orig[0].Name != round[0].Name {
t.Errorf("first rule name mismatch: %s vs %s", orig[0].Name, round[0].Name)
}
if len(orig[0].Conditions) != len(round[0].Conditions) {
t.Errorf("first rule condition count mismatch: %d vs %d", len(orig[0].Conditions), len(round[0].Conditions))
}
}
func floatPtr(f float64) *float64 { return &f }

405
pkg/promotions/types.go Normal file
View File

@@ -0,0 +1,405 @@
package promotions
import (
"encoding/json"
"errors"
"fmt"
"os"
"strconv"
)
// -----------------------------
// Enum-like string types
// -----------------------------
type ConditionOperator string
const (
OpEquals ConditionOperator = "equals"
OpNotEquals ConditionOperator = "not_equals"
OpGreaterThan ConditionOperator = "greater_than"
OpLessThan ConditionOperator = "less_than"
OpGreaterOrEqual ConditionOperator = "greater_or_equal"
OpLessOrEqual ConditionOperator = "less_or_equal"
OpContains ConditionOperator = "contains"
OpNotContains ConditionOperator = "not_contains"
OpIn ConditionOperator = "in"
OpNotIn ConditionOperator = "not_in"
)
type ConditionType string
const (
CondCartTotal ConditionType = "cart_total"
CondItemQuantity ConditionType = "item_quantity"
CondCustomerSegment ConditionType = "customer_segment"
CondProductCategory ConditionType = "product_category"
CondProductID ConditionType = "product_id"
CondCustomerLifetime ConditionType = "customer_lifetime_value"
CondOrderCount ConditionType = "order_count"
CondDateRange ConditionType = "date_range"
CondDayOfWeek ConditionType = "day_of_week"
CondTimeOfDay ConditionType = "time_of_day"
CondGroup ConditionType = "group" // synthetic value for groups
)
type ActionType string
const (
ActionPercentageDiscount ActionType = "percentage_discount"
ActionFixedDiscount ActionType = "fixed_discount"
ActionFreeShipping ActionType = "free_shipping"
ActionBuyXGetY ActionType = "buy_x_get_y"
ActionTieredDiscount ActionType = "tiered_discount"
ActionBundleDiscount ActionType = "bundle_discount"
)
type LogicOperator string
const (
LogicAND LogicOperator = "AND"
LogicOR LogicOperator = "OR"
)
type PromotionStatus string
const (
StatusActive PromotionStatus = "active"
StatusInactive PromotionStatus = "inactive"
StatusScheduled PromotionStatus = "scheduled"
StatusExpired PromotionStatus = "expired"
)
// -----------------------------
// Condition Value (union)
// -----------------------------
//
// Represents: string | number | []string | []number
// We store raw JSON and lazily interpret.
type ConditionValue struct {
Raw json.RawMessage
}
func (cv *ConditionValue) UnmarshalJSON(b []byte) error {
if len(b) == 0 {
return errors.New("empty ConditionValue")
}
// Just store raw; interpretation happens via helpers.
cv.Raw = append(cv.Raw[0:0], b...)
return nil
}
// Helpers to interpret value:
func (cv ConditionValue) AsString() (string, bool) {
// Treat explicit JSON null as invalid
if string(cv.Raw) == "null" {
return "", false
}
var s string
if err := json.Unmarshal(cv.Raw, &s); err == nil {
return s, true
}
return "", false
}
func (cv ConditionValue) AsFloat64() (float64, bool) {
if string(cv.Raw) == "null" {
return 0, false
}
var f float64
if err := json.Unmarshal(cv.Raw, &f); err == nil {
return f, true
}
// Attempt integer decode into float64
var i int64
if err := json.Unmarshal(cv.Raw, &i); err == nil {
return float64(i), true
}
return 0, false
}
func (cv ConditionValue) AsStringSlice() ([]string, bool) {
if string(cv.Raw) == "null" {
return nil, false
}
var arr []string
if err := json.Unmarshal(cv.Raw, &arr); err == nil {
return arr, true
}
return nil, false
}
func (cv ConditionValue) AsFloat64Slice() ([]float64, bool) {
if string(cv.Raw) == "null" {
return nil, false
}
var arrNum []float64
if err := json.Unmarshal(cv.Raw, &arrNum); err == nil {
return arrNum, true
}
// Try []int -> []float64
var arrInt []int64
if err := json.Unmarshal(cv.Raw, &arrInt); err == nil {
out := make([]float64, len(arrInt))
for i, v := range arrInt {
out[i] = float64(v)
}
return out, true
}
return nil, false
}
func (cv ConditionValue) String() string {
if s, ok := cv.AsString(); ok {
return s
}
if f, ok := cv.AsFloat64(); ok {
return strconv.FormatFloat(f, 'f', -1, 64)
}
if ss, ok := cv.AsStringSlice(); ok {
return fmt.Sprintf("%v", ss)
}
if fs, ok := cv.AsFloat64Slice(); ok {
return fmt.Sprintf("%v", fs)
}
return string(cv.Raw)
}
// -----------------------------
// BaseCondition
// -----------------------------
type BaseCondition struct {
ID string `json:"id"`
Type ConditionType `json:"type"`
Operator ConditionOperator `json:"operator"`
Value ConditionValue `json:"value"`
Label *string `json:"label,omitempty"`
}
func (b BaseCondition) IsGroup() bool { return false }
// -----------------------------
// ConditionGroup
// -----------------------------
type ConditionGroup struct {
ID string `json:"id"`
Type string `json:"type"` // always "group"
Operator LogicOperator `json:"operator"`
Conditions Conditions `json:"conditions"`
}
// Custom unmarshaller ensures nested polymorphic conditions are decoded
// using the Conditions type (which applies the raw element discriminator).
func (g *ConditionGroup) UnmarshalJSON(b []byte) error {
type alias struct {
ID string `json:"id"`
Type string `json:"type"`
Operator LogicOperator `json:"operator"`
Conditions json.RawMessage `json:"conditions"`
}
var a alias
if err := json.Unmarshal(b, &a); err != nil {
return err
}
// Basic validation
if a.Type != "group" {
return fmt.Errorf("ConditionGroup expected type 'group', got %q", a.Type)
}
var conds Conditions
if len(a.Conditions) > 0 {
if err := json.Unmarshal(a.Conditions, &conds); err != nil {
return err
}
}
g.ID = a.ID
g.Type = a.Type
g.Operator = a.Operator
g.Conditions = conds
return nil
}
func (g ConditionGroup) IsGroup() bool { return true }
// -----------------------------
// Condition interface + slice
// -----------------------------
type Condition interface {
IsGroup() bool
}
// Internal wrapper to help decode each element.
type rawCond struct {
Type string `json:"type"`
}
// Custom unmarshaler for a Condition slice
type Conditions []Condition
func (cs *Conditions) UnmarshalJSON(b []byte) error {
var rawList []json.RawMessage
if err := json.Unmarshal(b, &rawList); err != nil {
return err
}
out := make([]Condition, 0, len(rawList))
for _, elem := range rawList {
var hdr rawCond
if err := json.Unmarshal(elem, &hdr); err != nil {
return err
}
if hdr.Type == "group" {
var grp ConditionGroup
if err := json.Unmarshal(elem, &grp); err != nil {
return err
}
// Recursively decode grp.Conditions (already handled because field type is []Condition)
out = append(out, grp)
} else {
var bc BaseCondition
if err := json.Unmarshal(elem, &bc); err != nil {
return err
}
out = append(out, bc)
}
}
*cs = out
return nil
}
// -----------------------------
// Bundle Structures
// -----------------------------
type BundleQualifyingRules struct {
Type string `json:"type"` // "category" | "product_ids" | "tag" | "all"
Value interface{} `json:"value"` // string or []string
}
type BundleContainer struct {
ID string `json:"id"`
Name string `json:"name"`
Quantity int `json:"quantity"`
SelectionType string `json:"selectionType"` // "any" | "specific"
QualifyingRules BundleQualifyingRules `json:"qualifyingRules"`
AllowedProducts []string `json:"allowedProducts,omitempty"`
}
type BundlePricing struct {
Type string `json:"type"` // "fixed_price" | "percentage_discount" | "fixed_discount"
Value float64 `json:"value"`
}
type BundleConfig struct {
Containers []BundleContainer `json:"containers"`
Pricing BundlePricing `json:"pricing"`
RequireAllContainers bool `json:"requireAllContainers"`
}
// -----------------------------
// Action
// -----------------------------
type Action struct {
ID string `json:"id"`
Type ActionType `json:"type"`
Value interface{} `json:"value"` // number or string
Config map[string]interface{} `json:"config,omitempty"`
BundleConfig *BundleConfig `json:"bundleConfig,omitempty"`
Label *string `json:"label,omitempty"`
}
// -----------------------------
// Promotion Rule
// -----------------------------
type PromotionRule struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Status PromotionStatus `json:"status"`
Priority int `json:"priority"`
StartDate string `json:"startDate"`
EndDate *string `json:"endDate"` // null -> nil
Conditions Conditions `json:"conditions"`
Actions []Action `json:"actions"`
UsageLimit *int `json:"usageLimit,omitempty"`
UsageCount int `json:"usageCount"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
CreatedBy string `json:"createdBy"`
Tags []string `json:"tags"`
}
// -----------------------------
// Promotion Stats
// -----------------------------
type PromotionStats struct {
TotalPromotions int `json:"totalPromotions"`
ActivePromotions int `json:"activePromotions"`
TotalRevenue float64 `json:"totalRevenue"`
TotalOrders int `json:"totalOrders"`
AverageDiscount float64 `json:"averageDiscount"`
}
// -----------------------------
// Utility: Decode array of rules
// -----------------------------
func DecodePromotionRules(data []byte) ([]PromotionRule, error) {
var rules []PromotionRule
if err := json.Unmarshal(data, &rules); err != nil {
return nil, err
}
return rules, nil
}
// Example helper to inspect conditions programmatically.
func WalkConditions(conds []Condition, fn func(c Condition) bool) {
for _, c := range conds {
if !fn(c) {
return
}
if grp, ok := c.(ConditionGroup); ok {
WalkConditions(grp.Conditions, fn)
}
}
}
type PromotionState struct {
Vouchers []PromotionRule `json:"promotions"`
}
type StateFile struct {
State PromotionState `json:"state"`
Version int `json:"version"`
}
func (sf *StateFile) GetPromotion(id string) (*PromotionRule, bool) {
for _, v := range sf.State.Vouchers {
if v.ID == id {
return &v, true
}
}
return nil, false
}
func LoadStateFile(fileName string) (*PromotionState, error) {
f, err := os.Open(fileName)
if err != nil {
return nil, err
}
defer f.Close()
dec := json.NewDecoder(f)
sf := &PromotionState{}
err = dec.Decode(sf)
if err != nil {
return nil, err
}
return sf, nil
}

View File

@@ -28,6 +28,32 @@ func TestParseRules_SimpleSku(t *testing.T) {
} }
} }
func TestRuleCartTotal(t *testing.T) {
rs, err := ParseRules("min_total>=500000")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(rs.Conditions) != 1 {
t.Fatalf("expected 1 condition got %d", len(rs.Conditions))
}
c := rs.Conditions[0]
if c.Kind != RuleMinTotal {
t.Fatalf("expected kind cart total got %s", c.Kind)
}
ctx := EvalContext{
Items: []Item{
Item{
Sku: "123",
},
},
CartTotalInc: 400000,
}
applied := rs.Applies(ctx)
if applied {
t.Fatalf("expected")
}
}
func TestParseRules_CategoryAndSkuMixedSeparators(t *testing.T) { func TestParseRules_CategoryAndSkuMixedSeparators(t *testing.T) {
rs, err := ParseRules(" category=Shoes|Bags ; sku= A | B , min_total>=1000\nmin_item_price>=500") rs, err := ParseRules(" category=Shoes|Bags ; sku= A | B , min_total>=1000\nmin_item_price>=500")
if err != nil { if err != nil {

View File

@@ -1,7 +1,10 @@
package voucher package voucher
import ( import (
"encoding/json"
"errors" "errors"
"fmt"
"os"
"git.tornberg.me/go-cart-actor/pkg/messages" "git.tornberg.me/go-cart-actor/pkg/messages"
) )
@@ -13,10 +16,9 @@ type Rule struct {
type Voucher struct { type Voucher struct {
Code string `json:"code"` Code string `json:"code"`
Value int64 `json:"discount"` Value int64 `json:"value"`
TaxValue int64 `json:"taxValue"` Rules string `json:"rules"`
TaxRate int `json:"taxRate"` Description string `json:"description,omitempty"`
rules []Rule `json:"rules"`
} }
type Service struct { type Service struct {
@@ -29,10 +31,54 @@ func (s *Service) GetVoucher(code string) (*messages.AddVoucher, error) {
if code == "" { if code == "" {
return nil, ErrInvalidCode return nil, ErrInvalidCode
} }
value := int64(250_00) sf, err := LoadStateFile("data/vouchers.json")
if err != nil {
return nil, err
}
v, ok := sf.GetVoucher(code)
if !ok {
return nil, fmt.Errorf("no voucher found for code: %s", code)
}
return &messages.AddVoucher{ return &messages.AddVoucher{
Code: code, Code: code,
Value: value, Value: v.Value,
VoucherRules: make([]*messages.VoucherRule, 0), Description: v.Description,
VoucherRules: []string{
v.Rules,
},
}, nil }, nil
} }
type State struct {
Vouchers []Voucher `json:"vouchers"`
}
type StateFile struct {
State State `json:"state"`
Version int `json:"version"`
}
func (sf *StateFile) GetVoucher(code string) (*Voucher, bool) {
for _, v := range sf.State.Vouchers {
if v.Code == code {
return &v, true
}
}
return nil, false
}
func LoadStateFile(fileName string) (*StateFile, error) {
f, err := os.Open(fileName)
if err != nil {
return nil, err
}
defer f.Close()
dec := json.NewDecoder(f)
sf := &StateFile{}
err = dec.Decode(sf)
if err != nil {
return nil, err
}
return sf, nil
}

View File

@@ -4,9 +4,7 @@ option go_package = "git.tornberg.me/go-cart-actor/proto;messages";
import "google/protobuf/any.proto"; import "google/protobuf/any.proto";
message ClearCartRequest { message ClearCartRequest {}
}
message AddItem { message AddItem {
uint32 item_id = 1; uint32 item_id = 1;
@@ -35,9 +33,7 @@ message AddItem {
optional uint32 parentId = 23; optional uint32 parentId = 23;
} }
message RemoveItem { message RemoveItem { uint32 Id = 1; }
uint32 Id = 1;
}
message ChangeQuantity { message ChangeQuantity {
uint32 Id = 1; uint32 Id = 1;
@@ -73,9 +69,7 @@ message PickupPoint {
optional string country = 6; optional string country = 6;
} }
message RemoveDelivery { message RemoveDelivery { uint32 id = 1; }
uint32 id = 1;
}
message CreateCheckoutOrder { message CreateCheckoutOrder {
string terms = 1; string terms = 1;
@@ -101,28 +95,24 @@ message InitializeCheckout {
bool paymentInProgress = 3; bool paymentInProgress = 3;
} }
message VoucherRule {
string type = 2;
string description = 3;
string condition = 4;
string action = 5;
}
message AddVoucher { message AddVoucher {
string code = 1; string code = 1;
int64 value = 2; int64 value = 2;
repeated VoucherRule voucherRules = 3; repeated string voucherRules = 3;
string description = 4;
} }
message RemoveVoucher { message RemoveVoucher { uint32 id = 1; }
uint32 id = 1;
}
message UpsertSubscriptionDetails { message UpsertSubscriptionDetails {
optional string id = 1; optional string id = 1;
string offeringCode = 2; string offeringCode = 2;
string signingType = 3; string signingType = 3;
google.protobuf.Any data = 4; google.protobuf.Any data = 4;
}
message PreConditionFailed {
string operation = 1;
string error = 2;
google.protobuf.Any input = 3;
} }