Add refund order
This commit is contained in:
@@ -12,6 +12,13 @@ import (
|
||||
|
||||
func (s *orderSvc) CreateOrderInquiry(ctx mycontext.Context,
|
||||
req *entity.OrderRequest) (*entity.OrderInquiryResponse, error) {
|
||||
|
||||
cashierSession, err := s.cashierSvc.GetOpenSession(ctx, ctx.RequestedBy())
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("no open session found for cashier", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
productIDs, filteredItems, err := s.ValidateOrderItems(ctx, req.OrderItems)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -60,6 +67,7 @@ func (s *orderSvc) CreateOrderInquiry(ctx mycontext.Context,
|
||||
req.PaymentProvider,
|
||||
req.TableNumber,
|
||||
req.OrderType,
|
||||
cashierSession.ID,
|
||||
)
|
||||
|
||||
for _, item := range req.OrderItems {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"enaklo-pos-be/internal/constants"
|
||||
"enaklo-pos-be/internal/entity"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
@@ -36,6 +37,20 @@ func (s *orderSvc) ExecuteOrderInquiry(ctx mycontext.Context,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *orderSvc) RefundRequest(ctx mycontext.Context, partnerID, orderID int64, reason string) error {
|
||||
order, err := s.repo.FindByIDAndPartnerID(ctx, partnerID, orderID)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("failed to create order", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if order.Status != "PAID" {
|
||||
return errors.New("only paid order can be refund")
|
||||
}
|
||||
|
||||
return s.repo.UpdateOrder(ctx, order.ID, "REFUNDED", reason)
|
||||
}
|
||||
|
||||
func (s *orderSvc) processPostOrderActions(
|
||||
ctx mycontext.Context,
|
||||
order *entity.Order,
|
||||
|
||||
@@ -12,6 +12,7 @@ type Repository interface {
|
||||
CreateInquiry(ctx mycontext.Context, inquiry *entity.OrderInquiry) (*entity.OrderInquiry, error)
|
||||
FindInquiryByID(ctx mycontext.Context, id string) (*entity.OrderInquiry, error)
|
||||
UpdateInquiryStatus(ctx mycontext.Context, id string, status string) error
|
||||
UpdateOrder(ctx mycontext.Context, id int64, status string, description string) error
|
||||
GetOrderHistoryByPartnerID(ctx mycontext.Context, partnerID int64, req entity.SearchRequest) ([]*entity.Order, int64, error)
|
||||
GetOrderPaymentMethodBreakdown(
|
||||
ctx mycontext.Context,
|
||||
@@ -65,6 +66,7 @@ type Service interface {
|
||||
req *entity.OrderRequest) (*entity.OrderInquiryResponse, error)
|
||||
ExecuteOrderInquiry(ctx mycontext.Context,
|
||||
token string, paymentMethod, paymentProvider string, inProgressOrderID int64) (*entity.OrderResponse, error)
|
||||
RefundRequest(ctx mycontext.Context, partnerID, orderID int64, reason string) error
|
||||
GetOrderHistory(ctx mycontext.Context, partnerID int64, request entity.SearchRequest) ([]*entity.Order, int64, error)
|
||||
CalculateOrderTotals(
|
||||
ctx mycontext.Context,
|
||||
@@ -122,6 +124,10 @@ type VoucherUndianRepo interface {
|
||||
CreateUndianVouchers(ctx mycontext.Context, vouchers []*entity.UndianVoucherDB) error
|
||||
}
|
||||
|
||||
type CashierSvc interface {
|
||||
GetOpenSession(ctx mycontext.Context, cashierID int64) (*entity.CashierSession, error)
|
||||
}
|
||||
|
||||
type orderSvc struct {
|
||||
repo Repository
|
||||
product ProductService
|
||||
@@ -133,6 +139,7 @@ type orderSvc struct {
|
||||
partnerSetting PartnerSettings
|
||||
inprogressOrder InProgressOrderRepository
|
||||
voucherUndianRepo VoucherUndianRepo
|
||||
cashierSvc CashierSvc
|
||||
}
|
||||
|
||||
func New(
|
||||
@@ -145,6 +152,7 @@ func New(
|
||||
notification NotificationService,
|
||||
partnerSetting PartnerSettings,
|
||||
voucherUndianRepo VoucherUndianRepo,
|
||||
cashierSvc CashierSvc,
|
||||
) Service {
|
||||
return &orderSvc{
|
||||
repo: repo,
|
||||
@@ -156,5 +164,6 @@ func New(
|
||||
notification: notification,
|
||||
partnerSetting: partnerSetting,
|
||||
voucherUndianRepo: voucherUndianRepo,
|
||||
cashierSvc: cashierSvc,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user