Add void print
This commit is contained in:
@@ -38,9 +38,9 @@ func (s *orderSvc) ExecuteOrderInquiry(ctx mycontext.Context,
|
||||
}
|
||||
|
||||
func (s *orderSvc) RefundRequest(ctx mycontext.Context, partnerID, orderID int64, reason string) error {
|
||||
order, err := s.repo.FindByIDAndPartnerID(ctx, partnerID, orderID)
|
||||
order, err := s.repo.FindByIDAndPartnerID(ctx, orderID, partnerID)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("failed to create order", zap.Error(err))
|
||||
logger.ContextLogger(ctx).Error("failed to find order for refund", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -48,7 +48,31 @@ func (s *orderSvc) RefundRequest(ctx mycontext.Context, partnerID, orderID int64
|
||||
return errors.New("only paid order can be refund")
|
||||
}
|
||||
|
||||
return s.repo.UpdateOrder(ctx, order.ID, "REFUNDED", reason)
|
||||
err = s.repo.UpdateOrder(ctx, order.ID, "REFUNDED", reason)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("failed to update order status", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
refundTransaction, err := s.createRefundTransaction(ctx, order, reason)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("failed to create refund transaction", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if order.CustomerID != nil && *order.CustomerID > 0 {
|
||||
err = s.reverseCustomerVouchers(ctx, *order.CustomerID, int64(order.Total), order.ID)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Warn("failed to reverse customer vouchers", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
logger.ContextLogger(ctx).Info("refund processed successfully",
|
||||
zap.Int64("orderID", orderID),
|
||||
zap.String("reason", reason),
|
||||
zap.String("refundTransactionID", refundTransaction.ID))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *orderSvc) processPostOrderActions(
|
||||
@@ -262,3 +286,36 @@ func formatPaymentMethod(method string) string {
|
||||
}
|
||||
return method
|
||||
}
|
||||
|
||||
func (s *orderSvc) createRefundTransaction(ctx mycontext.Context, order *entity.Order, reason string) (*entity.Transaction, error) {
|
||||
transaction := &entity.Transaction{
|
||||
OrderID: order.ID,
|
||||
Amount: -order.Total,
|
||||
PaymentMethod: order.PaymentType,
|
||||
Status: "REFUND",
|
||||
CreatedAt: constants.TimeNow(),
|
||||
PartnerID: order.PartnerID,
|
||||
TransactionType: "REFUND",
|
||||
CreatedBy: ctx.RequestedBy(),
|
||||
UpdatedBy: ctx.RequestedBy(),
|
||||
}
|
||||
|
||||
_, err := s.transaction.Create(ctx, transaction)
|
||||
return transaction, err
|
||||
}
|
||||
|
||||
func (s *orderSvc) reverseCustomerVouchers(ctx mycontext.Context, customerID int64, total int64, orderID int64) error {
|
||||
// Find vouchers associated with this order and reverse them
|
||||
// This is a simplified implementation - in production you might want to track voucher-order relationships
|
||||
logger.ContextLogger(ctx).Info("reversing customer vouchers",
|
||||
zap.Int64("customerID", customerID),
|
||||
zap.Int64("orderID", orderID))
|
||||
|
||||
// TODO: Implement voucher reversal logic
|
||||
// This would involve:
|
||||
// 1. Finding vouchers created for this order
|
||||
// 2. Marking them as reversed/cancelled
|
||||
// 3. Optionally adjusting customer points
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user