add /order-id
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
guwandyk committed 2026-09-21 19:52:10 +05:00
1 parent 235ef5ec9e
commit ac94e0dd8a
7 files changed
+274

No files matched your search

@@ -1,6 +1,7 @@
package paymenthistory
import (
"errors"
"net/http"
"online-back/internal/appresult"
@@ -10,6 +11,7 @@ import (
"online-back/pkg/logging"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v4"
)
const baseURL = "/payment-history"
@@ -26,6 +28,7 @@ func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler
func (h *handler) Register(router *gin.RouterGroup) {
group := router.Group(baseURL, appresult.JwtTokenCheck())
group.GET("", h.list)
group.GET("/:id", h.logs)
}
// list godoc
@@ -62,6 +65,60 @@ func (h *handler) list(c *gin.Context) {
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
}
// logs godoc
// @Summary Get payment logs for an order
// @Description Returns the full step-by-step audit trail (visa_master_payment_logs) recorded while processing an order's payout - evidence of what actually happened, independent of the summary rows returned by the list endpoint
// @Tags payment-history
// @Produce json
// @Security BearerAuth
// @Param id path int true "Order ID"
// @Success 200 {object} appresult.AppSuccess
// @Failure 400 {object} appresult.AppError
// @Failure 403 {object} appresult.AppError
// @Failure 404 {object} appresult.AppError
// @Failure 500 {object} appresult.AppError
// @Router /payment-history/{id} [get]
func (h *handler) logs(c *gin.Context) {
orderID, ok := shared.ParseID(c.Param("id"))
if !ok {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
}
if !h.guardOrder(c, orderID) {
return
}
result, err := h.repository.Logs(c.Request.Context(), orderID)
if err != nil {
h.logger.Errorf("list payment logs failed (order %d): %v", orderID, err)
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
}
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
}
// guardOrder 404s if orderID doesn't exist, then enforces the same
// branch/own-scope rules as every other order-scoped endpoint (see
// visamasterpay.handler.guardOrder) before its logs are returned.
func (h *handler) guardOrder(c *gin.Context, orderID int64) bool {
if rbac.SkipRecordGuard(c) {
return true
}
userID, branchID, err := h.repository.OwnerInfo(c.Request.Context(), orderID)
if errors.Is(err, pgx.ErrNoRows) {
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
return false
}
if err != nil {
h.logger.Errorf("payment history owner lookup failed (order %d): %v", orderID, err)
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return false
}
return rbac.GuardOrder(c, userID, branchID)
}
func parseListFilter(c *gin.Context) (ListFilter, bool) {
page, limit, ok := shared.ParsePageLimit(c)
if !ok {