Compare commits
3 Commits
payment-hi
...
payment-hi
| Author | SHA1 | Date | |
|---|---|---|---|
| f067872cd7 | |||
| 6dd6110914 | |||
| a3cbb52f4b |
74
docs/docs.go
74
docs/docs.go
@@ -5437,18 +5437,18 @@ const docTemplate = `{
|
||||
"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). Backs the table's storage icon.",
|
||||
"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": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"payment-history"
|
||||
],
|
||||
"summary": "Get a payment with its HALKBANK response",
|
||||
"summary": "List an order's payments with their HALKBANK responses",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Payment ID",
|
||||
"description": "Order ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
@@ -5458,7 +5458,10 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
@@ -5495,7 +5498,7 @@ const docTemplate = `{
|
||||
"BearerAuth": []
|
||||
}
|
||||
],
|
||||
"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.",
|
||||
"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}, of every row at once at /payment-history/{id}/gateway; the step-by-step logs are at /payment-history/{id}/logs.",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
@@ -5549,6 +5552,67 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/payment-history/{id}/gateway": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"BearerAuth": []
|
||||
}
|
||||
],
|
||||
"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": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"payment-history"
|
||||
],
|
||||
"summary": "List an order's payments with their HALKBANK responses",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Order ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
|
||||
}
|
||||
}
|
||||
},
|
||||
"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": [
|
||||
|
||||
@@ -5431,18 +5431,18 @@
|
||||
"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). Backs the table's storage icon.",
|
||||
"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": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"payment-history"
|
||||
],
|
||||
"summary": "Get a payment with its HALKBANK response",
|
||||
"summary": "List an order's payments with their HALKBANK responses",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Payment ID",
|
||||
"description": "Order ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
@@ -5452,7 +5452,10 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
@@ -5489,7 +5492,7 @@
|
||||
"BearerAuth": []
|
||||
}
|
||||
],
|
||||
"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.",
|
||||
"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}, of every row at once at /payment-history/{id}/gateway; the step-by-step logs are at /payment-history/{id}/logs.",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
@@ -5543,6 +5546,67 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/payment-history/{id}/gateway": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"BearerAuth": []
|
||||
}
|
||||
],
|
||||
"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": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"payment-history"
|
||||
],
|
||||
"summary": "List an order's payments with their HALKBANK responses",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Order ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
|
||||
}
|
||||
}
|
||||
},
|
||||
"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": [
|
||||
|
||||
@@ -5635,7 +5635,8 @@ paths:
|
||||
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.
|
||||
a row is at /payment-history/payments/{id}, of every row at once at /payment-history/{id}/gateway;
|
||||
the step-by-step logs are at /payment-history/{id}/logs.
|
||||
parameters:
|
||||
- description: Order ID
|
||||
in: path
|
||||
@@ -5672,6 +5673,50 @@ paths:
|
||||
summary: List an order's payments
|
||||
tags:
|
||||
- payment-history
|
||||
/payment-history/{id}/gateway:
|
||||
get:
|
||||
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.
|
||||
parameters:
|
||||
- description: Order ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/paymenthistory.PaymentGatewayDTO'
|
||||
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 with their HALKBANK responses
|
||||
tags:
|
||||
- payment-history
|
||||
/payment-history/{id}/logs:
|
||||
get:
|
||||
description: Returns the full step-by-step audit trail (visa_master_payment_logs)
|
||||
@@ -5754,14 +5799,14 @@ paths:
|
||||
- payment-history
|
||||
/payment-history/payments/{id}/gateway:
|
||||
get:
|
||||
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.
|
||||
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.
|
||||
parameters:
|
||||
- description: Payment ID
|
||||
- description: Order ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
@@ -5772,7 +5817,9 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/paymenthistory.PaymentGatewayDTO'
|
||||
items:
|
||||
$ref: '#/definitions/paymenthistory.PaymentGatewayDTO'
|
||||
type: array
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
@@ -5791,7 +5838,7 @@ paths:
|
||||
$ref: '#/definitions/appresult.AppError'
|
||||
security:
|
||||
- BearerAuth: []
|
||||
summary: Get a payment with its HALKBANK response
|
||||
summary: List an order's payments with their HALKBANK responses
|
||||
tags:
|
||||
- payment-history
|
||||
/payment-settings:
|
||||
|
||||
@@ -142,6 +142,33 @@ func (r *repository) OrderPayments(ctx context.Context, orderID int64) ([]paymen
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (r *repository) OrderPaymentDetails(ctx context.Context, orderID int64) ([]paymenthistory.PaymentHistoryDetailDTO, error) {
|
||||
whereClause, args := buildListQuery(paymenthistory.ListFilter{OrderId: &orderID})
|
||||
query := `SELECT ` + historySelectColumns + `, p.gateway_response` + historyFromClause + whereClause + ` ORDER BY p.id DESC`
|
||||
|
||||
rows, err := r.client.Query(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
details := []paymenthistory.PaymentHistoryDetailDTO{}
|
||||
for rows.Next() {
|
||||
var detail paymenthistory.PaymentHistoryDetailDTO
|
||||
item, err := r.scanHistoryItem(rows, &detail.GatewayResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
detail.PaymentHistoryItemDTO = item
|
||||
details = append(details, detail)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return details, 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) {
|
||||
|
||||
@@ -32,6 +32,7 @@ func (h *handler) Register(router *gin.RouterGroup) {
|
||||
group.GET("", h.list)
|
||||
group.GET("/payments/:id", h.get)
|
||||
group.GET("/payments/:id/gateway", h.gateway)
|
||||
group.GET("/:id/gateway", h.gateway)
|
||||
group.GET("/:id", h.orderPayments)
|
||||
group.GET("/:id/logs", h.logs)
|
||||
}
|
||||
@@ -86,63 +87,71 @@ 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)
|
||||
paymentID, ok := shared.ParseID(c.Param("id"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.Get(c.Request.Context(), paymentID)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
h.logger.Errorf("get payment history failed (payment %d): %v", paymentID, err)
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
|
||||
if !h.guardOrder(c, result.OrderId) {
|
||||
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.
|
||||
// @Summary List an order's payments with their HALKBANK responses
|
||||
// @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.
|
||||
// @Tags payment-history
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param id path int true "Payment ID"
|
||||
// @Success 200 {object} PaymentGatewayDTO
|
||||
// @Param id path int true "Order ID"
|
||||
// @Success 200 {array} 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]
|
||||
// @Router /payment-history/{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"))
|
||||
orderID, ok := shared.ParseID(c.Param("id"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return PaymentHistoryDetailDTO{}, false
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.Get(c.Request.Context(), paymentID)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
|
||||
return PaymentHistoryDetailDTO{}, false
|
||||
if !h.guardOrder(c, orderID) {
|
||||
return
|
||||
}
|
||||
|
||||
details, err := h.repository.OrderPaymentDetails(c.Request.Context(), orderID)
|
||||
if err != nil {
|
||||
h.logger.Errorf("get payment history failed (payment %d): %v", paymentID, err)
|
||||
h.logger.Errorf("list order payment gateway responses failed (order %d): %v", orderID, err)
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return PaymentHistoryDetailDTO{}, false
|
||||
return
|
||||
}
|
||||
|
||||
if !h.guardOrder(c, result.OrderId) {
|
||||
return PaymentHistoryDetailDTO{}, false
|
||||
result := make([]PaymentGatewayDTO, 0, len(details))
|
||||
for _, detail := range details {
|
||||
result = append(result, NewPaymentGatewayDTO(detail))
|
||||
}
|
||||
return result, true
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||
}
|
||||
|
||||
// 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.
|
||||
// @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}, of every row at once at /payment-history/{id}/gateway; the step-by-step logs are at /payment-history/{id}/logs.
|
||||
// @Tags payment-history
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
|
||||
@@ -12,20 +12,15 @@ import (
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v4"
|
||||
)
|
||||
|
||||
type fakeRepository struct {
|
||||
Repository
|
||||
payments map[int64]PaymentHistoryDetailDTO
|
||||
orders 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) {
|
||||
return append([]PaymentHistoryDetailDTO{}, f.orders[orderID]...), nil
|
||||
}
|
||||
|
||||
func strPtr(s string) *string { return &s }
|
||||
@@ -47,7 +42,7 @@ func gatewayRequest(t *testing.T, repo Repository, path string) *httptest.Respon
|
||||
return rec
|
||||
}
|
||||
|
||||
func TestGatewayReturnsTableRowWithHalkbankJSON(t *testing.T) {
|
||||
func TestGatewayReturnsOrderPaymentsWithHalkbankJSON(t *testing.T) {
|
||||
created := time.Date(2026, 10, 22, 8, 19, 57, 0, time.UTC)
|
||||
paid := PaymentHistoryDetailDTO{
|
||||
PaymentHistoryItemDTO: PaymentHistoryItemDTO{
|
||||
@@ -59,57 +54,80 @@ func TestGatewayReturnsTableRowWithHalkbankJSON(t *testing.T) {
|
||||
},
|
||||
GatewayResponse: json.RawMessage(`{"orderStatus":2,"actionCode":0}`),
|
||||
}
|
||||
repo := fakeRepository{payments: map[int64]PaymentHistoryDetailDTO{2922: paid}}
|
||||
failed := PaymentHistoryDetailDTO{PaymentHistoryItemDTO: PaymentHistoryItemDTO{Id: 2921, OrderId: 9437, GatewayStatus: "failed"}}
|
||||
repo := fakeRepository{orders: map[int64][]PaymentHistoryDetailDTO{9437: {paid, failed}}}
|
||||
|
||||
rec := gatewayRequest(t, repo, "2922/gateway")
|
||||
rec := gatewayRequest(t, repo, "9437/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"`
|
||||
Data []map[string]json.RawMessage `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(body.Data) != 2 {
|
||||
t.Fatalf("got %d payments, want 2", len(body.Data))
|
||||
}
|
||||
if got := string(body.Data[1]["id"]); got != "2921" {
|
||||
t.Errorf("second payment id: got %s, want 2921", got)
|
||||
}
|
||||
want := map[string]string{
|
||||
"id": `2922`, "orderId": `9437`, "cardholderName": `"Amanowa guljemal"`, "maskedPan": `"993404**2453"`,
|
||||
"paymentYear": `2026`, "paymentMonth": `10`, "createdAt": `"2026-10-22T08:19:57Z"`,
|
||||
"amountUsd": `250`, "amountTmt": `1063.44`, "orderNumber": `"221026131957"`,
|
||||
"paid": `true`, "gatewayStatus": `"success"`, "gatewayResponse": `{"orderStatus":2,"actionCode":0}`,
|
||||
}
|
||||
if len(body.Data) != len(want) {
|
||||
t.Errorf("got fields %v, want exactly %d", body.Data, len(want))
|
||||
if len(body.Data[0]) != len(want) {
|
||||
t.Errorf("got fields %v, want exactly %d", body.Data[0], len(want))
|
||||
}
|
||||
for key, value := range want {
|
||||
if got := string(body.Data[key]); got != value {
|
||||
if got := string(body.Data[0][key]); got != value {
|
||||
t.Errorf("%s: got %s, want %s", key, got, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatewayNullsWhenHalkbankNeverAnswered(t *testing.T) {
|
||||
repo := fakeRepository{payments: map[int64]PaymentHistoryDetailDTO{
|
||||
7: {PaymentHistoryItemDTO: PaymentHistoryItemDTO{Id: 7, GatewayStatus: "failed"}},
|
||||
repo := fakeRepository{orders: map[int64][]PaymentHistoryDetailDTO{
|
||||
3: {{PaymentHistoryItemDTO: PaymentHistoryItemDTO{Id: 7, OrderId: 3, GatewayStatus: "failed"}}},
|
||||
}}
|
||||
rec := gatewayRequest(t, repo, "7/gateway")
|
||||
rec := gatewayRequest(t, repo, "3/gateway")
|
||||
var body struct {
|
||||
Data map[string]json.RawMessage `json:"data"`
|
||||
Data []map[string]json.RawMessage `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(body.Data) != 1 {
|
||||
t.Fatalf("got %d payments, want 1", len(body.Data))
|
||||
}
|
||||
for _, key := range []string{"cardholderName", "maskedPan", "gatewayResponse"} {
|
||||
if got := string(body.Data[key]); got != "null" {
|
||||
if got := string(body.Data[0][key]); got != "null" {
|
||||
t.Errorf("%s: got %q, want null", key, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatewayErrors(t *testing.T) {
|
||||
repo := fakeRepository{payments: map[int64]PaymentHistoryDetailDTO{}}
|
||||
for path, want := range map[string]int{"abc/gateway": http.StatusBadRequest, "999/gateway": http.StatusNotFound} {
|
||||
if rec := gatewayRequest(t, repo, path); rec.Code != want {
|
||||
t.Errorf("%s: got %d, want %d", path, rec.Code, want)
|
||||
}
|
||||
func TestGatewayEmptyOrderAndBadID(t *testing.T) {
|
||||
repo := fakeRepository{orders: map[int64][]PaymentHistoryDetailDTO{}}
|
||||
|
||||
rec := gatewayRequest(t, repo, "999/gateway")
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("got %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var body struct {
|
||||
Data json.RawMessage `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := string(body.Data); got != "[]" {
|
||||
t.Errorf("data: got %s, want []", got)
|
||||
}
|
||||
|
||||
if rec := gatewayRequest(t, repo, "abc/gateway"); rec.Code != http.StatusBadRequest {
|
||||
t.Errorf("abc/gateway: got %d, want %d", rec.Code, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ type Repository interface {
|
||||
// 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)
|
||||
// OrderPaymentDetails is OrderPayments with each attempt's raw GBÜS
|
||||
// response kept alongside it.
|
||||
OrderPaymentDetails(ctx context.Context, orderID int64) ([]PaymentHistoryDetailDTO, 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