payment-history: payment detail with GBÜS response, sorting, newest-first logs
- GET /payment-history/payments/{id}: single payment attempt with the raw
gateway_response (last HALKBANK JSON) for the "storage" icon modal
- GET /payment-history: sort (id/created_at/status/amount) and order
(asc/desc, default desc) query params
- GET /payment-history/{id}: order logs now newest first
- index on visa_master_order_payments (gateway_status, id DESC)
- regenerate swagger docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package paymenthistory
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
@@ -29,6 +30,7 @@ func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler
|
||||
func (h *handler) Register(router *gin.RouterGroup) {
|
||||
group := rbac.Group(router, baseURL, rbac.RequireStaff(perm.Cards))
|
||||
group.GET("", h.list)
|
||||
group.GET("/payments/:id", h.get)
|
||||
group.GET("/:id", h.logs)
|
||||
}
|
||||
|
||||
@@ -43,6 +45,8 @@ func (h *handler) Register(router *gin.RouterGroup) {
|
||||
// @Param user_id query int false "Filter by order owner (client) user ID"
|
||||
// @Param status query string false "Filter by gateway status (pending, success, failed)"
|
||||
// @Param search query string false "Filter by passport name/surname or order unique ID"
|
||||
// @Param sort query string false "Sort column" Enums(id, created_at, status, amount) default(id)
|
||||
// @Param order query string false "Sort direction" Enums(asc, desc) default(desc)
|
||||
// @Param page query int false "Page number" default(1)
|
||||
// @Param limit query int false "Items per page" default(10)
|
||||
// @Success 200 {object} ListPaymentHistoryDTO
|
||||
@@ -66,6 +70,44 @@ func (h *handler) list(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||
}
|
||||
|
||||
// get godoc
|
||||
// @Summary Get a single payment attempt
|
||||
// @Description Returns one visa/master/sber payout attempt by its payment ID, with the raw GBÜS response - the detail view behind a payment-history list row
|
||||
// @Tags payment-history
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param id path int true "Payment ID"
|
||||
// @Success 200 {object} PaymentHistoryDetailDTO
|
||||
// @Failure 400 {object} appresult.AppError
|
||||
// @Failure 403 {object} appresult.AppError
|
||||
// @Failure 404 {object} appresult.AppError
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /payment-history/payments/{id} [get]
|
||||
func (h *handler) get(c *gin.Context) {
|
||||
paymentID, ok := shared.ParseID(c.Param("id"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.Get(c.Request.Context(), paymentID)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
h.logger.Errorf("get payment history failed (payment %d): %v", paymentID, err)
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
|
||||
if !h.guardOrder(c, result.OrderId) {
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
@@ -151,6 +193,20 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
|
||||
filter.Search = shared.QueryValue(c, "search", "q")
|
||||
|
||||
if raw := shared.QueryValue(c, "sort", "sort_by", "sortBy"); raw != "" {
|
||||
if _, ok := SortColumns[raw]; !ok {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
filter.Sort = raw
|
||||
}
|
||||
switch strings.ToLower(shared.QueryValue(c, "order", "direction")) {
|
||||
case "", "desc":
|
||||
filter.Desc = true
|
||||
case "asc":
|
||||
default:
|
||||
return ListFilter{}, false
|
||||
}
|
||||
|
||||
rbac.BindBranchIDs(c, &filter.BranchIds)
|
||||
return filter, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user