Inquiry Fee

This commit is contained in:
aditya.siregar 2024-08-21 22:48:14 +07:00
parent c4e0c6d2c8
commit 6063713ad2
2 changed files with 16 additions and 7 deletions

View File

@ -4,6 +4,9 @@ type Order struct {
Fee float64 `mapstructure:"fee"` Fee float64 `mapstructure:"fee"`
} }
func (w *Order) GetOrderFee() float64 { func (w *Order) GetOrderFee(source string) float64 {
if source == "POS" {
return 0
}
return w.Fee return w.Fee
} }

View File

@ -20,7 +20,7 @@ import (
) )
type Config interface { type Config interface {
GetOrderFee() float64 GetOrderFee(source string) float64
} }
type OrderService struct { type OrderService struct {
@ -53,9 +53,15 @@ func NewOrderService(
} }
func (s *OrderService) CreateOrder(ctx mycontext.Context, req *entity.OrderRequest) (*entity.OrderResponse, error) { func (s *OrderService) CreateOrder(ctx mycontext.Context, req *entity.OrderRequest) (*entity.OrderResponse, error) {
productIDs := make([]int64, len(req.OrderItems)) productIDs := []int64{}
for i, item := range req.OrderItems { for _, item := range req.OrderItems {
productIDs[i] = item.ProductID 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) 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(), RefID: generator.GenerateUUID(),
Status: order2.New.String(), Status: order2.New.String(),
Amount: totalAmount, Amount: totalAmount,
Total: totalAmount + s.cfg.GetOrderFee(), Total: totalAmount + s.cfg.GetOrderFee(req.Source),
Fee: s.cfg.GetOrderFee(), Fee: s.cfg.GetOrderFee(req.Source),
PaymentType: req.PaymentMethod, PaymentType: req.PaymentMethod,
SiteID: &siteID, SiteID: &siteID,
CreatedBy: req.CreatedBy, CreatedBy: req.CreatedBy,