payment-history: /{id} lists the order's payments, logs move to /{id}/logs
GET /payment-history/{id} now returns one row per payment of the order
(paid, card, time, period, amounts), newest first - the per-order payment
table the frontend already calls. The step-by-step logs it used to return
are kept at GET /payment-history/{id}/logs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,31 @@ func (r *repository) Get(ctx context.Context, paymentID int64) (paymenthistory.P
|
||||
return detail, nil
|
||||
}
|
||||
|
||||
func (r *repository) OrderPayments(ctx context.Context, orderID int64) ([]paymenthistory.PaymentHistoryItemDTO, error) {
|
||||
whereClause, args := buildListQuery(paymenthistory.ListFilter{OrderId: &orderID})
|
||||
query := `SELECT ` + historySelectColumns + historyFromClause + whereClause + ` ORDER BY p.id DESC`
|
||||
|
||||
rows, err := r.client.Query(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
items := []paymenthistory.PaymentHistoryItemDTO{}
|
||||
for rows.Next() {
|
||||
item, err := r.scanHistoryItem(rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// OwnerInfo returns orderID's owning user/branch, so the handler can run
|
||||
// rbac.GuardOrder before returning its logs to a branch/own-scoped caller.
|
||||
func (r *repository) OwnerInfo(ctx context.Context, orderID int64) (*int64, int64, error) {
|
||||
|
||||
@@ -112,7 +112,7 @@ type PaymentLogDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
OrderId int64 `json:"orderId"`
|
||||
Step string `json:"step"`
|
||||
Detail json.RawMessage `json:"detail,omitempty"`
|
||||
Detail json.RawMessage `json:"detail,omitempty" swaggertype:"object"`
|
||||
CreatedById *int64 `json:"createdById,omitempty"`
|
||||
CreatedByName string `json:"createdByName,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
|
||||
@@ -31,7 +31,8 @@ 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)
|
||||
group.GET("/:id", h.orderPayments)
|
||||
group.GET("/:id/logs", h.logs)
|
||||
}
|
||||
|
||||
// list godoc
|
||||
@@ -108,19 +109,53 @@ func (h *handler) get(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
|
||||
// orderPayments godoc
|
||||
// @Summary List an order's payments
|
||||
// @Description Returns every visa/master/sber payout attempt of one order, newest first - one row per payment with whether it was paid (paid/gatewayStatus), the card it was paid from (cardholderName/maskedPan, once GBÜS reports them), its time (createdAt) and period (paymentPeriod). The raw GBÜS response of a row is at /payment-history/payments/{id}; the step-by-step logs are at /payment-history/{id}/logs.
|
||||
// @Tags payment-history
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param id path int true "Order ID"
|
||||
// @Success 200 {object} appresult.AppSuccess
|
||||
// @Success 200 {array} PaymentHistoryItemDTO
|
||||
// @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) orderPayments(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.OrderPayments(c.Request.Context(), orderID)
|
||||
if err != nil {
|
||||
h.logger.Errorf("list order payments failed (order %d): %v", orderID, err)
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
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, newest first - evidence of what actually happened, independent of the summary rows returned by /payment-history/{id}
|
||||
// @Tags payment-history
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param id path int true "Order ID"
|
||||
// @Success 200 {array} PaymentLogDTO
|
||||
// @Failure 400 {object} appresult.AppError
|
||||
// @Failure 403 {object} appresult.AppError
|
||||
// @Failure 404 {object} appresult.AppError
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /payment-history/{id}/logs [get]
|
||||
func (h *handler) logs(c *gin.Context) {
|
||||
orderID, ok := shared.ParseID(c.Param("id"))
|
||||
if !ok {
|
||||
|
||||
@@ -6,6 +6,9 @@ type Repository interface {
|
||||
List(ctx context.Context, filter ListFilter) (ListPaymentHistoryDTO, error)
|
||||
// Get returns a single payout attempt by its visa_master_order_payments id.
|
||||
Get(ctx context.Context, paymentID int64) (PaymentHistoryDetailDTO, error)
|
||||
// OrderPayments returns every payout attempt of a single order, newest
|
||||
// first - the per-order payment table, without paging.
|
||||
OrderPayments(ctx context.Context, orderID int64) ([]PaymentHistoryItemDTO, error)
|
||||
// Logs returns the full visa_master_payment_logs audit trail for a
|
||||
// single order, newest first.
|
||||
Logs(ctx context.Context, orderID int64) ([]PaymentLogDTO, error)
|
||||
|
||||
Reference in New Issue
Block a user