payment-history: GET /payments/{id}/gateway - one payment with its HALKBANK JSON
Returns a payment the way the per-order payment table shows it (paid, cardholder name, masked card, time, payment year/month, USD/TMT amounts, reference) plus the last stored GBÜS response, for the storage icon. Card fields and gatewayResponse are null until GBÜS reports them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,7 @@ 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("/payments/:id/gateway", h.gateway)
|
||||
group.GET("/:id", h.orderPayments)
|
||||
group.GET("/:id/logs", h.logs)
|
||||
}
|
||||
@@ -85,28 +86,58 @@ func (h *handler) list(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /payment-history/payments/{id} [get]
|
||||
func (h *handler) get(c *gin.Context) {
|
||||
result, ok := h.loadPayment(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||
}
|
||||
|
||||
// gateway 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). Backs the table's storage icon.
|
||||
// @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) gateway(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"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
return PaymentHistoryDetailDTO{}, false
|
||||
}
|
||||
|
||||
result, err := h.repository.Get(c.Request.Context(), paymentID)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
|
||||
return
|
||||
return PaymentHistoryDetailDTO{}, false
|
||||
}
|
||||
if err != nil {
|
||||
h.logger.Errorf("get payment history failed (payment %d): %v", paymentID, err)
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
return PaymentHistoryDetailDTO{}, false
|
||||
}
|
||||
|
||||
if !h.guardOrder(c, result.OrderId) {
|
||||
return
|
||||
return PaymentHistoryDetailDTO{}, false
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||
return result, true
|
||||
}
|
||||
|
||||
// orderPayments godoc
|
||||
|
||||
Reference in New Issue
Block a user