add /order-id
This commit is contained in:
1 parent
235ef5ec9e
commit
ac94e0dd8a
7 files changed
+274
No files matched your search
@@ -4980,6 +4980,64 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/payment-history/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"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",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-history"
|
||||||
|
],
|
||||||
|
"summary": "Get payment logs for an order",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppSuccess"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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-settings": {
|
"/payment-settings": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|||||||
@@ -4974,6 +4974,64 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/payment-history/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"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",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-history"
|
||||||
|
],
|
||||||
|
"summary": "Get payment logs for an order",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppSuccess"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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-settings": {
|
"/payment-settings": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|||||||
@@ -4999,6 +4999,45 @@ paths:
|
|||||||
summary: List payment history
|
summary: List payment history
|
||||||
tags:
|
tags:
|
||||||
- payment-history
|
- 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
|
||||||
|
parameters:
|
||||||
|
- description: Order ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppSuccess'
|
||||||
|
"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: Get payment logs for an order
|
||||||
|
tags:
|
||||||
|
- payment-history
|
||||||
/payment-settings:
|
/payment-settings:
|
||||||
get:
|
get:
|
||||||
description: Returns the admin-configurable bank and GBÜS commission fees used
|
description: Returns the admin-configurable bank and GBÜS commission fees used
|
||||||
|
|||||||
@@ -75,6 +75,48 @@ func (r *repository) List(ctx context.Context, filter paymenthistory.ListFilter)
|
|||||||
return paymenthistory.ListPaymentHistoryDTO{Count: count, Items: items}, nil
|
return paymenthistory.ListPaymentHistoryDTO{Count: count, Items: 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) {
|
||||||
|
var userID *int64
|
||||||
|
var branchID int64
|
||||||
|
err := r.client.QueryRow(ctx,
|
||||||
|
`SELECT user_id, branch_id FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`, orderID,
|
||||||
|
).Scan(&userID, &branchID)
|
||||||
|
return userID, branchID, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *repository) Logs(ctx context.Context, orderID int64) ([]paymenthistory.PaymentLogDTO, error) {
|
||||||
|
rows, err := r.client.Query(ctx,
|
||||||
|
`SELECT l.id, l.order_id, l.step, l.detail, l.created_by, `+shared.UserDisplaySQL+`, l.created_at
|
||||||
|
FROM visa_master_payment_logs l
|
||||||
|
LEFT JOIN users u ON u.id = l.created_by
|
||||||
|
WHERE l.order_id = $1
|
||||||
|
ORDER BY l.id ASC`,
|
||||||
|
orderID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
items := []paymenthistory.PaymentLogDTO{}
|
||||||
|
for rows.Next() {
|
||||||
|
var item paymenthistory.PaymentLogDTO
|
||||||
|
if err := rows.Scan(
|
||||||
|
&item.Id, &item.OrderId, &item.Step, &item.Detail, &item.CreatedById, &item.CreatedByName, &item.CreatedAt,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, item)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
func buildListQuery(filter paymenthistory.ListFilter) (whereClause string, args []interface{}) {
|
func buildListQuery(filter paymenthistory.ListFilter) (whereClause string, args []interface{}) {
|
||||||
conditions := []string{"p.deleted_at IS NULL", "o.deleted_at IS NULL"}
|
conditions := []string{"p.deleted_at IS NULL", "o.deleted_at IS NULL"}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
package paymenthistory
|
package paymenthistory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"online-back/internal/shared"
|
"online-back/internal/shared"
|
||||||
@@ -67,3 +68,17 @@ type ListPaymentHistoryDTO struct {
|
|||||||
Count int64 `json:"count"`
|
Count int64 `json:"count"`
|
||||||
Items []PaymentHistoryItemDTO `json:"items"`
|
Items []PaymentHistoryItemDTO `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PaymentLogDTO is one step-by-step entry from visa_master_payment_logs -
|
||||||
|
// the granular audit trail recorded while processing an order's payout
|
||||||
|
// (see visamasterpay's logStep), independent of and more detailed than
|
||||||
|
// the summary rows in visa_master_order_payments.
|
||||||
|
type PaymentLogDTO struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
OrderId int64 `json:"orderId"`
|
||||||
|
Step string `json:"step"`
|
||||||
|
Detail json.RawMessage `json:"detail,omitempty"`
|
||||||
|
CreatedById *int64 `json:"createdById,omitempty"`
|
||||||
|
CreatedByName string `json:"createdByName,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package paymenthistory
|
package paymenthistory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"online-back/internal/appresult"
|
"online-back/internal/appresult"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"online-back/pkg/logging"
|
"online-back/pkg/logging"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jackc/pgx/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
const baseURL = "/payment-history"
|
const baseURL = "/payment-history"
|
||||||
@@ -26,6 +28,7 @@ func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler
|
|||||||
func (h *handler) Register(router *gin.RouterGroup) {
|
func (h *handler) Register(router *gin.RouterGroup) {
|
||||||
group := router.Group(baseURL, appresult.JwtTokenCheck())
|
group := router.Group(baseURL, appresult.JwtTokenCheck())
|
||||||
group.GET("", h.list)
|
group.GET("", h.list)
|
||||||
|
group.GET("/:id", h.logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// list godoc
|
// list godoc
|
||||||
@@ -62,6 +65,60 @@ func (h *handler) list(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
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) {
|
func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||||
page, limit, ok := shared.ParsePageLimit(c)
|
page, limit, ok := shared.ParsePageLimit(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -4,4 +4,9 @@ import "context"
|
|||||||
|
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
List(ctx context.Context, filter ListFilter) (ListPaymentHistoryDTO, error)
|
List(ctx context.Context, filter ListFilter) (ListPaymentHistoryDTO, error)
|
||||||
|
// Logs returns the full visa_master_payment_logs audit trail for a
|
||||||
|
// single order, oldest first.
|
||||||
|
Logs(ctx context.Context, orderID int64) ([]PaymentLogDTO, error)
|
||||||
|
// OwnerInfo returns an order's owning user/branch, for rbac.GuardOrder.
|
||||||
|
OwnerInfo(ctx context.Context, orderID int64) (*int64, int64, error)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user