diff --git a/docs/docs.go b/docs/docs.go index ad28bce..856ff79 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -5437,7 +5437,68 @@ const docTemplate = `{ "BearerAuth": [] } ], - "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", + "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.", + "produces": [ + "application/json" + ], + "tags": [ + "payment-history" + ], + "summary": "List an order's payments", + "parameters": [ + { + "type": "integer", + "description": "Order ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/paymenthistory.PaymentHistoryItemDTO" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/payment-history/{id}/logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "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}", "produces": [ "application/json" ], @@ -5458,7 +5519,10 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/appresult.AppSuccess" + "type": "array", + "items": { + "$ref": "#/definitions/paymenthistory.PaymentLogDTO" + } } }, "400": { @@ -10091,6 +10155,32 @@ const docTemplate = `{ } } }, + "paymenthistory.PaymentLogDTO": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "createdById": { + "type": "integer" + }, + "createdByName": { + "type": "string" + }, + "detail": { + "type": "object" + }, + "id": { + "type": "integer" + }, + "orderId": { + "type": "integer" + }, + "step": { + "type": "string" + } + } + }, "paymentsettings.PaymentSettingsDTO": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index dee1877..3bbafc3 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -5431,7 +5431,68 @@ "BearerAuth": [] } ], - "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", + "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.", + "produces": [ + "application/json" + ], + "tags": [ + "payment-history" + ], + "summary": "List an order's payments", + "parameters": [ + { + "type": "integer", + "description": "Order ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/paymenthistory.PaymentHistoryItemDTO" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/appresult.AppError" + } + } + } + } + }, + "/payment-history/{id}/logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "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}", "produces": [ "application/json" ], @@ -5452,7 +5513,10 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/appresult.AppSuccess" + "type": "array", + "items": { + "$ref": "#/definitions/paymenthistory.PaymentLogDTO" + } } }, "400": { @@ -10085,6 +10149,32 @@ } } }, + "paymenthistory.PaymentLogDTO": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "createdById": { + "type": "integer" + }, + "createdByName": { + "type": "string" + }, + "detail": { + "type": "object" + }, + "id": { + "type": "integer" + }, + "orderId": { + "type": "integer" + }, + "step": { + "type": "string" + } + } + }, "paymentsettings.PaymentSettingsDTO": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index cf47e48..f37b492 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1484,6 +1484,23 @@ definitions: userId: type: integer type: object + paymenthistory.PaymentLogDTO: + properties: + createdAt: + type: string + createdById: + type: integer + createdByName: + type: string + detail: + type: object + id: + type: integer + orderId: + type: integer + step: + type: string + type: object paymentsettings.PaymentSettingsDTO: properties: bankFeeTmt: @@ -5563,9 +5580,11 @@ paths: - payment-history /payment-history/{id}: get: - 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 + 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. parameters: - description: Order ID in: path @@ -5578,7 +5597,50 @@ paths: "200": description: OK schema: - $ref: '#/definitions/appresult.AppSuccess' + items: + $ref: '#/definitions/paymenthistory.PaymentHistoryItemDTO' + type: array + "400": + description: Bad Request + schema: + $ref: '#/definitions/appresult.AppError' + "403": + description: Forbidden + schema: + $ref: '#/definitions/appresult.AppError' + "404": + description: Not Found + schema: + $ref: '#/definitions/appresult.AppError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/appresult.AppError' + security: + - BearerAuth: [] + summary: List an order's payments + tags: + - payment-history + /payment-history/{id}/logs: + get: + 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} + parameters: + - description: Order ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/paymenthistory.PaymentLogDTO' + type: array "400": description: Bad Request schema: diff --git a/internal/payment/paymenthistory/db/postgresql.go b/internal/payment/paymenthistory/db/postgresql.go index b355116..5fe9f9b 100644 --- a/internal/payment/paymenthistory/db/postgresql.go +++ b/internal/payment/paymenthistory/db/postgresql.go @@ -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) { diff --git a/internal/payment/paymenthistory/dto.go b/internal/payment/paymenthistory/dto.go index da5a067..b59acdd 100644 --- a/internal/payment/paymenthistory/dto.go +++ b/internal/payment/paymenthistory/dto.go @@ -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"` diff --git a/internal/payment/paymenthistory/handler.go b/internal/payment/paymenthistory/handler.go index d8e9ac0..22b64e7 100644 --- a/internal/payment/paymenthistory/handler.go +++ b/internal/payment/paymenthistory/handler.go @@ -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 { diff --git a/internal/payment/paymenthistory/storage.go b/internal/payment/paymenthistory/storage.go index b0c662a..4a6c6c2 100644 --- a/internal/payment/paymenthistory/storage.go +++ b/internal/payment/paymenthistory/storage.go @@ -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)