payment-history: /payments/{id}/gateway takes an order ID and lists its payments
Some checks failed
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

The frontend calls /payments/{id}/gateway with an order ID, so that URL
now returns every payment of the order (newest first, each with its
HALKBANK JSON) instead of one payment by payment ID. /{id}/gateway stays
as an alias of the same handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 20:18:05 +05:00
parent 6dd6110914
commit f067872cd7
5 changed files with 35 additions and 99 deletions

View File

@@ -5437,18 +5437,18 @@ const docTemplate = `{
"BearerAuth": [] "BearerAuth": []
} }
], ],
"description": "Returns one payment the way the per-order payment table shows it - paid or not, the card it was paid from (cardholderName/maskedPan, null until GBÜS reports them), its time (createdAt), payment year/month, amounts and reference (orderNumber) - together with the last GBÜS (HALKBANK) response stored for it (gatewayResponse, null if GBÜS never answered). Every payment of an order at once is at /payment-history/{id}/gateway.", "description": "Returns every payment of one order, newest first, the way the per-order payment table shows them - paid or not, the card it was paid from (cardholderName/maskedPan, null until GBÜS reports them), its time (createdAt), payment year/month, amounts and reference (orderNumber) - each together with the last GBÜS (HALKBANK) response stored for it (gatewayResponse, null if GBÜS never answered). Backs the table's storage icon.",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"payment-history" "payment-history"
], ],
"summary": "Get a payment with its HALKBANK response", "summary": "List an order's payments with their HALKBANK responses",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Payment ID", "description": "Order ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
@@ -5458,7 +5458,10 @@ const docTemplate = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO" "type": "array",
"items": {
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
}
} }
}, },
"400": { "400": {

View File

@@ -5431,18 +5431,18 @@
"BearerAuth": [] "BearerAuth": []
} }
], ],
"description": "Returns one payment the way the per-order payment table shows it - paid or not, the card it was paid from (cardholderName/maskedPan, null until GBÜS reports them), its time (createdAt), payment year/month, amounts and reference (orderNumber) - together with the last GBÜS (HALKBANK) response stored for it (gatewayResponse, null if GBÜS never answered). Every payment of an order at once is at /payment-history/{id}/gateway.", "description": "Returns every payment of one order, newest first, the way the per-order payment table shows them - paid or not, the card it was paid from (cardholderName/maskedPan, null until GBÜS reports them), its time (createdAt), payment year/month, amounts and reference (orderNumber) - each together with the last GBÜS (HALKBANK) response stored for it (gatewayResponse, null if GBÜS never answered). Backs the table's storage icon.",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"payment-history" "payment-history"
], ],
"summary": "Get a payment with its HALKBANK response", "summary": "List an order's payments with their HALKBANK responses",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Payment ID", "description": "Order ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
@@ -5452,7 +5452,10 @@
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO" "type": "array",
"items": {
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
}
} }
}, },
"400": { "400": {

View File

@@ -5799,14 +5799,14 @@ paths:
- payment-history - payment-history
/payment-history/payments/{id}/gateway: /payment-history/payments/{id}/gateway:
get: get:
description: Returns one payment the way the per-order payment table shows it description: Returns every payment of one order, newest first, the way the per-order
- paid or not, the card it was paid from (cardholderName/maskedPan, null until payment table shows them - paid or not, the card it was paid from (cardholderName/maskedPan,
GBÜS reports them), its time (createdAt), payment year/month, amounts and null until GBÜS reports them), its time (createdAt), payment year/month, amounts
reference (orderNumber) - together with the last GBÜS (HALKBANK) response and reference (orderNumber) - each together with the last GBÜS (HALKBANK)
stored for it (gatewayResponse, null if GBÜS never answered). Every payment response stored for it (gatewayResponse, null if GBÜS never answered). Backs
of an order at once is at /payment-history/{id}/gateway. the table's storage icon.
parameters: parameters:
- description: Payment ID - description: Order ID
in: path in: path
name: id name: id
required: true required: true
@@ -5817,7 +5817,9 @@ paths:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/paymenthistory.PaymentGatewayDTO' items:
$ref: '#/definitions/paymenthistory.PaymentGatewayDTO'
type: array
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
@@ -5836,7 +5838,7 @@ paths:
$ref: '#/definitions/appresult.AppError' $ref: '#/definitions/appresult.AppError'
security: security:
- BearerAuth: [] - BearerAuth: []
summary: Get a payment with its HALKBANK response summary: List an order's payments with their HALKBANK responses
tags: tags:
- payment-history - payment-history
/payment-settings: /payment-settings:

View File

@@ -31,7 +31,7 @@ func (h *handler) Register(router *gin.RouterGroup) {
group := rbac.Group(router, baseURL, rbac.RequireStaff(perm.Cards)) group := rbac.Group(router, baseURL, rbac.RequireStaff(perm.Cards))
group.GET("", h.list) group.GET("", h.list)
group.GET("/payments/:id", h.get) group.GET("/payments/:id", h.get)
group.GET("/payments/:id/gateway", h.paymentGateway) group.GET("/payments/:id/gateway", h.gateway)
group.GET("/:id/gateway", h.gateway) group.GET("/:id/gateway", h.gateway)
group.GET("/:id", h.orderPayments) group.GET("/:id", h.orderPayments)
group.GET("/:id/logs", h.logs) group.GET("/:id/logs", h.logs)
@@ -87,58 +87,27 @@ func (h *handler) list(c *gin.Context) {
// @Failure 500 {object} appresult.AppError // @Failure 500 {object} appresult.AppError
// @Router /payment-history/payments/{id} [get] // @Router /payment-history/payments/{id} [get]
func (h *handler) get(c *gin.Context) { func (h *handler) get(c *gin.Context) {
result, ok := h.loadPayment(c)
if !ok {
return
}
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
}
// paymentGateway godoc
// @Summary Get a payment with its HALKBANK response
// @Description Returns one payment the way the per-order payment table shows it - paid or not, the card it was paid from (cardholderName/maskedPan, null until GBÜS reports them), its time (createdAt), payment year/month, amounts and reference (orderNumber) - together with the last GBÜS (HALKBANK) response stored for it (gatewayResponse, null if GBÜS never answered). Every payment of an order at once is at /payment-history/{id}/gateway.
// @Tags payment-history
// @Produce json
// @Security BearerAuth
// @Param id path int true "Payment ID"
// @Success 200 {object} PaymentGatewayDTO
// @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}/gateway [get]
func (h *handler) paymentGateway(c *gin.Context) {
result, ok := h.loadPayment(c)
if !ok {
return
}
c.JSON(http.StatusOK, appresult.SuccessWithData(NewPaymentGatewayDTO(result)))
}
// loadPayment loads the :id payment and runs the order guard on it,
// answering the request itself when that fails.
func (h *handler) loadPayment(c *gin.Context) (PaymentHistoryDetailDTO, bool) {
paymentID, ok := shared.ParseID(c.Param("id")) paymentID, ok := shared.ParseID(c.Param("id"))
if !ok { if !ok {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return PaymentHistoryDetailDTO{}, false return
} }
result, err := h.repository.Get(c.Request.Context(), paymentID) result, err := h.repository.Get(c.Request.Context(), paymentID)
if errors.Is(err, pgx.ErrNoRows) { if errors.Is(err, pgx.ErrNoRows) {
c.JSON(http.StatusNotFound, appresult.ErrNotFound) c.JSON(http.StatusNotFound, appresult.ErrNotFound)
return PaymentHistoryDetailDTO{}, false return
} }
if err != nil { if err != nil {
h.logger.Errorf("get payment history failed (payment %d): %v", paymentID, err) h.logger.Errorf("get payment history failed (payment %d): %v", paymentID, err)
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return PaymentHistoryDetailDTO{}, false return
} }
if !h.guardOrder(c, result.OrderId) { if !h.guardOrder(c, result.OrderId) {
return PaymentHistoryDetailDTO{}, false return
} }
return result, true c.JSON(http.StatusOK, appresult.SuccessWithData(result))
} }
// gateway godoc // gateway godoc
@@ -153,6 +122,7 @@ func (h *handler) loadPayment(c *gin.Context) (PaymentHistoryDetailDTO, bool) {
// @Failure 403 {object} appresult.AppError // @Failure 403 {object} appresult.AppError
// @Failure 404 {object} appresult.AppError // @Failure 404 {object} appresult.AppError
// @Failure 500 {object} appresult.AppError // @Failure 500 {object} appresult.AppError
// @Router /payment-history/payments/{id}/gateway [get]
// @Router /payment-history/{id}/gateway [get] // @Router /payment-history/{id}/gateway [get]
func (h *handler) gateway(c *gin.Context) { func (h *handler) gateway(c *gin.Context) {
orderID, ok := shared.ParseID(c.Param("id")) orderID, ok := shared.ParseID(c.Param("id"))

View File

@@ -12,21 +12,11 @@ import (
"online-back/pkg/logging" "online-back/pkg/logging"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/jackc/pgx/v4"
) )
type fakeRepository struct { type fakeRepository struct {
Repository Repository
orders map[int64][]PaymentHistoryDetailDTO orders map[int64][]PaymentHistoryDetailDTO
payments map[int64]PaymentHistoryDetailDTO
}
func (f fakeRepository) Get(_ context.Context, paymentID int64) (PaymentHistoryDetailDTO, error) {
p, ok := f.payments[paymentID]
if !ok {
return PaymentHistoryDetailDTO{}, pgx.ErrNoRows
}
return p, nil
} }
func (f fakeRepository) OrderPaymentDetails(_ context.Context, orderID int64) ([]PaymentHistoryDetailDTO, error) { func (f fakeRepository) OrderPaymentDetails(_ context.Context, orderID int64) ([]PaymentHistoryDetailDTO, error) {
@@ -45,11 +35,10 @@ func gatewayRequest(t *testing.T, repo Repository, path string) *httptest.Respon
router.Use(func(c *gin.Context) { router.Use(func(c *gin.Context) {
c.Set("rbacPrincipal", &rbac.Principal{UserID: 1, Scope: rbac.ScopeAll}) c.Set("rbacPrincipal", &rbac.Principal{UserID: 1, Scope: rbac.ScopeAll})
}) })
router.GET("/payment-history/payments/:id/gateway", h.paymentGateway) router.GET("/payment-history/payments/:id/gateway", h.gateway)
router.GET("/payment-history/:id/gateway", h.gateway)
rec := httptest.NewRecorder() rec := httptest.NewRecorder()
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/payment-history/"+path, nil)) router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/payment-history/payments/"+path, nil))
return rec return rec
} }
@@ -142,34 +131,3 @@ func TestGatewayEmptyOrderAndBadID(t *testing.T) {
t.Errorf("abc/gateway: got %d, want %d", rec.Code, http.StatusBadRequest) t.Errorf("abc/gateway: got %d, want %d", rec.Code, http.StatusBadRequest)
} }
} }
func TestPaymentGatewayReturnsOnePayment(t *testing.T) {
repo := fakeRepository{payments: map[int64]PaymentHistoryDetailDTO{
2922: {
PaymentHistoryItemDTO: PaymentHistoryItemDTO{Id: 2922, OrderId: 9437, Paid: true, GatewayStatus: "success"},
GatewayResponse: json.RawMessage(`{"orderStatus":2}`),
},
}}
rec := gatewayRequest(t, repo, "payments/2922/gateway")
if rec.Code != http.StatusOK {
t.Fatalf("got %d %s", rec.Code, rec.Body.String())
}
var body struct {
Data map[string]json.RawMessage `json:"data"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatal(err)
}
for key, value := range map[string]string{"id": `2922`, "orderId": `9437`, "gatewayResponse": `{"orderStatus":2}`} {
if got := string(body.Data[key]); got != value {
t.Errorf("%s: got %s, want %s", key, got, value)
}
}
for path, want := range map[string]int{"payments/abc/gateway": http.StatusBadRequest, "payments/999/gateway": http.StatusNotFound} {
if rec := gatewayRequest(t, repo, path); rec.Code != want {
t.Errorf("%s: got %d, want %d", path, rec.Code, want)
}
}
}