diff --git a/config/configs.go b/config/configs.go index 62f5c21..eff8104 100644 --- a/config/configs.go +++ b/config/configs.go @@ -33,6 +33,7 @@ type Config struct { Email Email `mapstructure:"email"` Withdraw Withdraw `mapstructure:"withdrawal"` Discovery Discovery `mapstructure:"discovery"` + Order Order `mapstructure:"order"` } var ( diff --git a/config/order.go b/config/order.go new file mode 100644 index 0000000..93b2f2d --- /dev/null +++ b/config/order.go @@ -0,0 +1,9 @@ +package config + +type Order struct { + Fee float64 `mapstructure:"fee"` +} + +func (w *Order) GetOrderFee() float64 { + return w.Fee +} diff --git a/infra/furtuna.development.yaml b/infra/furtuna.development.yaml index 499a766..71fc3d5 100644 --- a/infra/furtuna.development.yaml +++ b/infra/furtuna.development.yaml @@ -51,6 +51,9 @@ email: subject: "Reset Password" opening_word: "Terima kasih sudah menjadi bagian dari Furtuna. Anda telah berhasil melakukan reset password, silakan masukan unik password yang dibuat oleh sistem dibawah ini:" closing_word: "Silakan login kembali menggunakan email dan password anda diatas, sistem akan secara otomatis meminta anda untuk membuat password baru setelah berhasil login. Mohon maaf atas kendala yang dialami." + +order: + fee: 5000 withdrawal: platform_fee: 5000 diff --git a/internal/entity/order.go b/internal/entity/order.go index f3e5c04..bbccf01 100644 --- a/internal/entity/order.go +++ b/internal/entity/order.go @@ -10,6 +10,8 @@ type Order struct { PartnerID int64 `gorm:"type:int;column:partner_id"` Status string `gorm:"type:varchar;column:status"` Amount float64 `gorm:"type:numeric;not null;column:amount"` + Total float64 `gorm:"type:numeric;not null;column:total"` + Fee float64 `gorm:"type:numeric;not null;column:fee"` SiteID *int64 `gorm:"type:numeric;not null;column:site_id"` CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"` diff --git a/internal/handlers/http/order/order.go b/internal/handlers/http/order/order.go index 0b163b2..b2d9343 100644 --- a/internal/handlers/http/order/order.go +++ b/internal/handlers/http/order/order.go @@ -125,6 +125,8 @@ func MapOrderToCreateOrderResponse(orderResponse *entity.OrderResponse) response PartnerID: order.PartnerID, Status: order.Status, Amount: order.Amount, + Total: order.Total, + Fee: order.Fee, PaymentType: order.PaymentType, CreatedAt: order.CreatedAt, OrderItems: orderItems, diff --git a/internal/handlers/response/order.go b/internal/handlers/response/order.go index b9a6ac7..5bda2ef 100644 --- a/internal/handlers/response/order.go +++ b/internal/handlers/response/order.go @@ -85,6 +85,8 @@ type CreateOrderResponse struct { PartnerID int64 `json:"partner_id"` Status string `json:"status"` Amount float64 `json:"amount"` + Total float64 `json:"total"` + Fee float64 `json:"fee"` PaymentType string `json:"payment_type"` CreatedAt time.Time `json:"created_at"` OrderItems []CreateOrderItemResponse `json:"order_items"` diff --git a/internal/services/order/order.go b/internal/services/order/order.go index 29ffcaf..4c372c2 100644 --- a/internal/services/order/order.go +++ b/internal/services/order/order.go @@ -18,6 +18,10 @@ import ( "time" ) +type Config interface { + GetOrderFee() float64 +} + type OrderService struct { repo repository.Order crypt repository.Crypto @@ -26,6 +30,7 @@ type OrderService struct { payment repository.Payment txmanager repository.TransactionManager wallet repository.WalletRepository + cfg Config } func NewOrderService( @@ -33,7 +38,7 @@ func NewOrderService( product repository.Product, crypt repository.Crypto, midtrans repository.Midtrans, payment repository.Payment, txmanager repository.TransactionManager, - wallet repository.WalletRepository) *OrderService { + wallet repository.WalletRepository, cfg Config) *OrderService { return &OrderService{ repo: repo, product: product, @@ -42,6 +47,7 @@ func NewOrderService( payment: payment, txmanager: txmanager, wallet: wallet, + cfg: cfg, } } @@ -77,6 +83,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(), PaymentType: req.PaymentMethod, SiteID: ctx.GetSiteID(), CreatedBy: req.CreatedBy, diff --git a/internal/services/service.go b/internal/services/service.go index 6765e57..54af676 100644 --- a/internal/services/service.go +++ b/internal/services/service.go @@ -50,7 +50,7 @@ func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl) BranchSvc: branch.NewBranchService(repo.Branch), StudioSvc: studio.NewStudioService(repo.Studio), ProductSvc: product.NewProductService(repo.Product), - OrderSvc: order.NewOrderService(repo.Order, repo.Product, repo.Crypto, repo.Midtrans, repo.Payment, repo.Trx, repo.Wallet), + OrderSvc: order.NewOrderService(repo.Order, repo.Product, repo.Crypto, repo.Midtrans, repo.Payment, repo.Trx, repo.Wallet, &cfg.Order), OSSSvc: oss.NewOSSService(repo.OSS), PartnerSvc: partner.NewPartnerService( repo.Partner, users.NewUserService(repo.User, repo.Branch), repo.Trx, repo.Wallet),