diff --git a/config/order.go b/config/order.go index 93b2f2d..b2d7491 100644 --- a/config/order.go +++ b/config/order.go @@ -4,6 +4,9 @@ type Order struct { Fee float64 `mapstructure:"fee"` } -func (w *Order) GetOrderFee() float64 { +func (w *Order) GetOrderFee(source string) float64 { + if source == "POS" { + return 0 + } return w.Fee } diff --git a/internal/services/order/order.go b/internal/services/order/order.go index 2e4c944..92b5c69 100644 --- a/internal/services/order/order.go +++ b/internal/services/order/order.go @@ -20,7 +20,7 @@ import ( ) type Config interface { - GetOrderFee() float64 + GetOrderFee(source string) float64 } type OrderService struct { @@ -53,9 +53,15 @@ func NewOrderService( } func (s *OrderService) CreateOrder(ctx mycontext.Context, req *entity.OrderRequest) (*entity.OrderResponse, error) { - productIDs := make([]int64, len(req.OrderItems)) - for i, item := range req.OrderItems { - productIDs[i] = item.ProductID + productIDs := []int64{} + for _, item := range req.OrderItems { + if item.Quantity != 0 { + productIDs = append(productIDs, item.ProductID) + } + } + + if len(productIDs) < 1 { + return nil, errors2.ErrorBadRequest } products, err := s.product.GetProductsByIDs(ctx, productIDs, req.PartnerID) @@ -92,8 +98,8 @@ func (s *OrderService) CreateOrder(ctx mycontext.Context, req *entity.OrderReque RefID: generator.GenerateUUID(), Status: order2.New.String(), Amount: totalAmount, - Total: totalAmount + s.cfg.GetOrderFee(), - Fee: s.cfg.GetOrderFee(), + Total: totalAmount + s.cfg.GetOrderFee(req.Source), + Fee: s.cfg.GetOrderFee(req.Source), PaymentType: req.PaymentMethod, SiteID: &siteID, CreatedBy: req.CreatedBy,