diff --git a/docs/docs.go b/docs/docs.go index 1fcb9a7..afd58c1 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -9929,7 +9929,7 @@ const docTemplate = `{ "BearerAuth": [] } ], - "description": "For when the frontend can't rely on GBÜS's redirect having reached the callback (e.g. the user closed the hosted payment page first) - re-verifies the latest attempt with GBÜS server-to-server, the same way the callback does, and finalizes it if needed. Safe to call repeatedly.", + "description": "For when the frontend can't rely on GBÜS's redirect having reached the callback (e.g. the user closed the hosted payment page first) - re-verifies the latest attempt with GBÜS server-to-server, the same way the callback does, and finalizes it if needed. gatewayResponse is GBÜS's last stored response for the attempt (null if GBÜS never answered). Safe to call repeatedly.", "produces": [ "application/json" ], @@ -13033,6 +13033,9 @@ const docTemplate = `{ "gatewayReference": { "type": "string" }, + "gatewayResponse": { + "type": "object" + }, "gatewayStatus": { "type": "string" }, diff --git a/docs/swagger.json b/docs/swagger.json index 26f95a2..53b1cab 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -9926,7 +9926,7 @@ "BearerAuth": [] } ], - "description": "For when the frontend can't rely on GBÜS's redirect having reached the callback (e.g. the user closed the hosted payment page first) - re-verifies the latest attempt with GBÜS server-to-server, the same way the callback does, and finalizes it if needed. Safe to call repeatedly.", + "description": "For when the frontend can't rely on GBÜS's redirect having reached the callback (e.g. the user closed the hosted payment page first) - re-verifies the latest attempt with GBÜS server-to-server, the same way the callback does, and finalizes it if needed. gatewayResponse is GBÜS's last stored response for the attempt (null if GBÜS never answered). Safe to call repeatedly.", "produces": [ "application/json" ], @@ -13030,6 +13030,9 @@ "gatewayReference": { "type": "string" }, + "gatewayResponse": { + "type": "object" + }, "gatewayStatus": { "type": "string" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 672aa95..6a66f9e 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2131,6 +2131,8 @@ definitions: type: number gatewayReference: type: string + gatewayResponse: + type: object gatewayStatus: type: string gbusFeeTmt: @@ -8872,7 +8874,8 @@ paths: description: For when the frontend can't rely on GBÜS's redirect having reached the callback (e.g. the user closed the hosted payment page first) - re-verifies the latest attempt with GBÜS server-to-server, the same way the callback does, - and finalizes it if needed. Safe to call repeatedly. + and finalizes it if needed. gatewayResponse is GBÜS's last stored response + for the attempt (null if GBÜS never answered). Safe to call repeatedly. parameters: - description: Visa/master payment order ID in: path diff --git a/internal/payment/visamasterpay/db/postgresql.go b/internal/payment/visamasterpay/db/postgresql.go index 09b47e7..f4ea81c 100644 --- a/internal/payment/visamasterpay/db/postgresql.go +++ b/internal/payment/visamasterpay/db/postgresql.go @@ -30,7 +30,7 @@ const orderTypeSber = "sber" const paymentReturningColumns = `id, order_id, order_number, payment_period, exchange_rate_usd, exchange_rate_rub, amount_tmt, bank_fee_tmt, gbus_fee_tmt, tveb_fee_usd, tveb_fee_tmt, total_amount_tmt, - gateway_status, gateway_reference, created_at, updated_at` + gateway_status, gateway_reference, gateway_response, created_at, updated_at` type repository struct { client postgresql.Client @@ -685,10 +685,13 @@ func scanPayment(row pgx.Row) (visamasterpay.PaymentResultDTO, error) { if err := row.Scan( &item.Id, &item.OrderId, &item.OrderNumber, &item.PaymentPeriod, &item.ExchangeRateUsd, &item.ExchangeRateRub, &item.AmountTmt, &item.BankFeeTmt, &item.GbusFeeTmt, &item.TvebFeeUsd, &item.TvebFeeTmt, &item.TotalAmountTmt, - &item.GatewayStatus, &item.GatewayReference, &item.CreatedAt, &item.UpdatedAt, + &item.GatewayStatus, &item.GatewayReference, &item.GatewayResponse, &item.CreatedAt, &item.UpdatedAt, ); err != nil { return visamasterpay.PaymentResultDTO{}, err } + if len(item.GatewayResponse) == 0 { + item.GatewayResponse = json.RawMessage("null") + } return item, nil } diff --git a/internal/payment/visamasterpay/dto.go b/internal/payment/visamasterpay/dto.go index 71a5e03..32f4014 100644 --- a/internal/payment/visamasterpay/dto.go +++ b/internal/payment/visamasterpay/dto.go @@ -1,6 +1,7 @@ package visamasterpay import ( + "encoding/json" "time" "online-back/internal/shared" @@ -69,25 +70,28 @@ type CallbackResultDTO struct { // as its own row in visa_master_order_payments (a full audit trail - // failed attempts are kept, not overwritten by a retry) - deliberately not // the full order+branch+user DTO owned by cards/visamaster (fetch that -// separately via GET /visa-master-payment-orders/:id). +// separately via GET /visa-master-payment-orders/:id). GatewayResponse is +// the last GBÜS response stored for the attempt (null if GBÜS never +// answered). type PaymentResultDTO struct { - Id int64 `json:"id"` - OrderId int64 `json:"orderId"` - OrderNumber string `json:"orderNumber"` - Type string `json:"type"` - Paid bool `json:"paid"` - AmountUsd float64 `json:"amountUsd"` - ExchangeRateUsd float64 `json:"exchangeRateUsd"` - ExchangeRateRub *float64 `json:"exchangeRateRub,omitempty"` - AmountTmt float64 `json:"amountTmt"` - BankFeeTmt float64 `json:"bankFeeTmt"` - GbusFeeTmt *float64 `json:"gbusFeeTmt,omitempty"` - TvebFeeUsd *float64 `json:"tvebFeeUsd,omitempty"` - TvebFeeTmt *float64 `json:"tvebFeeTmt,omitempty"` - TotalAmountTmt float64 `json:"totalAmountTmt"` - PaymentPeriod time.Time `json:"paymentPeriod"` - GatewayStatus string `json:"gatewayStatus"` - GatewayReference *string `json:"gatewayReference,omitempty"` - CreatedAt time.Time `json:"createdAt"` - UpdatedAt time.Time `json:"updatedAt"` + Id int64 `json:"id"` + OrderId int64 `json:"orderId"` + OrderNumber string `json:"orderNumber"` + Type string `json:"type"` + Paid bool `json:"paid"` + AmountUsd float64 `json:"amountUsd"` + ExchangeRateUsd float64 `json:"exchangeRateUsd"` + ExchangeRateRub *float64 `json:"exchangeRateRub,omitempty"` + AmountTmt float64 `json:"amountTmt"` + BankFeeTmt float64 `json:"bankFeeTmt"` + GbusFeeTmt *float64 `json:"gbusFeeTmt,omitempty"` + TvebFeeUsd *float64 `json:"tvebFeeUsd,omitempty"` + TvebFeeTmt *float64 `json:"tvebFeeTmt,omitempty"` + TotalAmountTmt float64 `json:"totalAmountTmt"` + PaymentPeriod time.Time `json:"paymentPeriod"` + GatewayStatus string `json:"gatewayStatus"` + GatewayReference *string `json:"gatewayReference,omitempty"` + GatewayResponse json.RawMessage `json:"gatewayResponse" swaggertype:"object"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` } diff --git a/internal/payment/visamasterpay/handler.go b/internal/payment/visamasterpay/handler.go index 07111de..f4f4bd5 100644 --- a/internal/payment/visamasterpay/handler.go +++ b/internal/payment/visamasterpay/handler.go @@ -114,7 +114,7 @@ func (h *handler) pay(c *gin.Context) { // status godoc // @Summary Re-check a visa/master/sber order's latest payment attempt -// @Description For when the frontend can't rely on GBÜS's redirect having reached the callback (e.g. the user closed the hosted payment page first) - re-verifies the latest attempt with GBÜS server-to-server, the same way the callback does, and finalizes it if needed. Safe to call repeatedly. +// @Description For when the frontend can't rely on GBÜS's redirect having reached the callback (e.g. the user closed the hosted payment page first) - re-verifies the latest attempt with GBÜS server-to-server, the same way the callback does, and finalizes it if needed. gatewayResponse is GBÜS's last stored response for the attempt (null if GBÜS never answered). Safe to call repeatedly. // @Tags visa-master-payment // @Produce json // @Security BearerAuth