ch some
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

This commit is contained in:
2026-09-21 19:12:07 +05:00
parent febd190d6e
commit 235ef5ec9e
8 changed files with 96 additions and 19 deletions

View File

@@ -9416,6 +9416,10 @@ const docTemplate = `{
"exchangeRateUsd": {
"type": "number"
},
"formUrl": {
"description": "FormUrl/SuccessUrl are only set while the attempt is still pending\n(awaiting the customer to finish paying on GBÜS's hosted page) - once\nan attempt is finalized (success/failed), gateway_response no longer\nholds a formUrl, so there's nothing left to resume.",
"type": "string"
},
"gatewayReference": {
"type": "string"
},
@@ -9446,6 +9450,9 @@ const docTemplate = `{
"paymentPeriod": {
"type": "string"
},
"successUrl": {
"type": "string"
},
"totalAmountTmt": {
"type": "number"
},
@@ -10060,8 +10067,14 @@ const docTemplate = `{
"formUrl": {
"type": "string"
},
"orderId": {
"type": "integer"
},
"paymentId": {
"type": "integer"
},
"successUrl": {
"type": "string"
}
}
},

View File

@@ -9410,6 +9410,10 @@
"exchangeRateUsd": {
"type": "number"
},
"formUrl": {
"description": "FormUrl/SuccessUrl are only set while the attempt is still pending\n(awaiting the customer to finish paying on GBÜS's hosted page) - once\nan attempt is finalized (success/failed), gateway_response no longer\nholds a formUrl, so there's nothing left to resume.",
"type": "string"
},
"gatewayReference": {
"type": "string"
},
@@ -9440,6 +9444,9 @@
"paymentPeriod": {
"type": "string"
},
"successUrl": {
"type": "string"
},
"totalAmountTmt": {
"type": "number"
},
@@ -10054,8 +10061,14 @@
"formUrl": {
"type": "string"
},
"orderId": {
"type": "integer"
},
"paymentId": {
"type": "integer"
},
"successUrl": {
"type": "string"
}
}
},

View File

@@ -1324,6 +1324,13 @@ definitions:
type: number
exchangeRateUsd:
type: number
formUrl:
description: |-
FormUrl/SuccessUrl are only set while the attempt is still pending
(awaiting the customer to finish paying on GBÜS's hosted page) - once
an attempt is finalized (success/failed), gateway_response no longer
holds a formUrl, so there's nothing left to resume.
type: string
gatewayReference:
type: string
gatewayStatus:
@@ -1344,6 +1351,8 @@ definitions:
type: string
paymentPeriod:
type: string
successUrl:
type: string
totalAmountTmt:
type: number
tvebFeeTmt:
@@ -1764,8 +1773,12 @@ definitions:
properties:
formUrl:
type: string
orderId:
type: integer
paymentId:
type: integer
successUrl:
type: string
type: object
visamasterpay.PaymentQuoteDTO:
properties:

View File

@@ -2,6 +2,7 @@ package db
import (
"context"
"encoding/json"
"fmt"
"strings"
@@ -15,12 +16,13 @@ import (
)
type repository struct {
client postgresql.Client
logger *logging.Logger
client postgresql.Client
logger *logging.Logger
publicBaseURL string
}
func NewRepository(client postgresql.Client, logger *logging.Logger) paymenthistory.Repository {
return &repository{client: client, logger: logger}
func NewRepository(client postgresql.Client, logger *logging.Logger, publicBaseURL string) paymenthistory.Repository {
return &repository{client: client, logger: logger, publicBaseURL: strings.TrimRight(publicBaseURL, "/")}
}
const historyFromClause = ` FROM visa_master_order_payments p
@@ -32,7 +34,7 @@ const historySelectColumns = `p.id, p.order_id, COALESCE(o.unique_id, ''), COALE
o.branch_id, b.name, COALESCE(o.passport_name, ''), COALESCE(o.passport_surname, ''), p.user_id,
p.amount_tmt, p.bank_fee_tmt, p.gbus_fee_tmt, p.tveb_fee_usd, p.tveb_fee_tmt, p.total_amount_tmt,
p.exchange_rate_usd, p.exchange_rate_rub, p.payment_period,
p.gateway_status, p.gateway_reference, p.created_by, ` + shared.UserDisplaySQL + `,
p.gateway_status, p.gateway_reference, p.gateway_response, p.created_by, ` + shared.UserDisplaySQL + `,
p.created_at, p.updated_at`
func (r *repository) List(ctx context.Context, filter paymenthistory.ListFilter) (paymenthistory.ListPaymentHistoryDTO, error) {
@@ -60,7 +62,7 @@ func (r *repository) List(ctx context.Context, filter paymenthistory.ListFilter)
var items []paymenthistory.PaymentHistoryItemDTO
for rows.Next() {
item, err := scanHistoryItem(rows)
item, err := r.scanHistoryItem(rows)
if err != nil {
return paymenthistory.ListPaymentHistoryDTO{}, err
}
@@ -109,16 +111,17 @@ func buildListQuery(filter paymenthistory.ListFilter) (whereClause string, args
return " WHERE " + strings.Join(conditions, " AND "), args
}
func scanHistoryItem(row pgx.Row) (paymenthistory.PaymentHistoryItemDTO, error) {
func (r *repository) scanHistoryItem(row pgx.Row) (paymenthistory.PaymentHistoryItemDTO, error) {
var item paymenthistory.PaymentHistoryItemDTO
var gatewayStatus string
var branchNameJSON []byte
var gatewayResponse []byte
if err := row.Scan(
&item.Id, &item.OrderId, &item.OrderUniqueId, &item.Type,
&item.BranchId, &branchNameJSON, &item.PassportName, &item.PassportSurname, &item.UserId,
&item.AmountTmt, &item.BankFeeTmt, &item.GbusFeeTmt, &item.TvebFeeUsd, &item.TvebFeeTmt, &item.TotalAmountTmt,
&item.ExchangeRateUsd, &item.ExchangeRateRub, &item.PaymentPeriod,
&gatewayStatus, &item.GatewayReference, &item.CreatedById, &item.CreatedByName,
&gatewayStatus, &item.GatewayReference, &gatewayResponse, &item.CreatedById, &item.CreatedByName,
&item.CreatedAt, &item.UpdatedAt,
); err != nil {
return paymenthistory.PaymentHistoryItemDTO{}, err
@@ -128,5 +131,29 @@ func scanHistoryItem(row pgx.Row) (paymenthistory.PaymentHistoryItemDTO, error)
}
item.GatewayStatus = gatewayStatus
item.Paid = gatewayStatus == "success"
// formUrl only survives in gateway_response while the attempt is still
// pending - once finalized, gateway_response is overwritten with the
// status-check response, which has no formUrl, so there's nothing to
// resume for a paid/failed row.
if formURL := extractFormURL(gatewayResponse); formURL != "" {
item.FormUrl = &formURL
successURL := fmt.Sprintf("%s/api/admin/visa-master-payment-orders/callback?paymentId=%d", r.publicBaseURL, item.Id)
item.SuccessUrl = &successURL
}
return item, nil
}
func extractFormURL(gatewayResponse []byte) string {
if len(gatewayResponse) == 0 {
return ""
}
var parsed struct {
FormUrl string `json:"formUrl"`
}
if err := json.Unmarshal(gatewayResponse, &parsed); err != nil {
return ""
}
return parsed.FormUrl
}

View File

@@ -37,10 +37,16 @@ type PaymentHistoryItemDTO struct {
PaymentPeriod time.Time `json:"paymentPeriod"`
GatewayStatus string `json:"gatewayStatus"`
GatewayReference *string `json:"gatewayReference,omitempty"`
CreatedById *int64 `json:"createdById,omitempty"`
CreatedByName string `json:"createdByName,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// FormUrl/SuccessUrl are only set while the attempt is still pending
// (awaiting the customer to finish paying on GBÜS's hosted page) - once
// an attempt is finalized (success/failed), gateway_response no longer
// holds a formUrl, so there's nothing left to resume.
FormUrl *string `json:"formUrl,omitempty"`
SuccessUrl *string `json:"successUrl,omitempty"`
CreatedById *int64 `json:"createdById,omitempty"`
CreatedByName string `json:"createdByName,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// ListFilter narrows the history list. BranchIds is populated by

View File

@@ -32,6 +32,6 @@ func Handlers(client postgresql.Client, logger *logging.Logger, currencyRepo cur
return []handlers.Handler{
paymentsettings.NewHandler(logger, settingsRepo),
visamasterpay.NewHandler(logger, visamasterpaydb.NewRepository(client, logger, currencyRepo, settingsRepo, gateway, publicBaseURL)),
paymenthistory.NewHandler(logger, paymenthistorydb.NewRepository(client, logger)),
paymenthistory.NewHandler(logger, paymenthistorydb.NewRepository(client, logger, publicBaseURL)),
}
}

View File

@@ -294,8 +294,8 @@ func (r *repository) Pay(ctx context.Context, orderID int64, dto visamasterpay.P
return visamasterpay.PaymentInitResultDTO{}, err
}
println("[pay] step 13 done: paymentId=", paymentID, "formUrl=", result.FormUrl)
return visamasterpay.PaymentInitResultDTO{PaymentId: paymentID, FormUrl: result.FormUrl}, nil
println("[pay] step 13 done: paymentId=", paymentID, "formUrl=", result.FormUrl, "successUrl=", returnURL)
return visamasterpay.PaymentInitResultDTO{PaymentId: paymentID, OrderId: orderID, FormUrl: result.FormUrl, SuccessUrl: returnURL}, nil
}
// HandleCallback is hit (unauthenticated - see rbac.isPublicAdminPath) when
@@ -409,9 +409,9 @@ func (r *repository) HandleCallback(ctx context.Context, paymentID int64) (visam
}
println("[callback] step 7b ok: lockedPaid=", lockedPaid)
if !lockedPaid {
println("[callback] step 7c: marking order paid")
println("[callback] step 7c: marking order paid and completed")
if _, err := tx.Exec(ctx,
`UPDATE visa_master_payment_orders SET paid = true, updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') WHERE id = $1`,
`UPDATE visa_master_payment_orders SET paid = true, status = 'completed', updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') WHERE id = $1`,
orderID,
); err != nil {
println("[callback] step 7c FAILED: mark order paid:", err.Error())

View File

@@ -45,9 +45,14 @@ type PayOrderDTO struct {
// - the customer (or the operator, in-branch) must complete payment there.
// The definitive outcome only becomes known once GBÜS redirects back to
// our callback, which verifies and finalizes it - see PaymentResultDTO.
// SuccessUrl is that same callback URL (embedded in the GBÜS register
// request as ReturnURL) - the frontend can watch for navigation to it
// inside the hosted-payment-page webview to know the flow has ended.
type PaymentInitResultDTO struct {
PaymentId int64 `json:"paymentId"`
FormUrl string `json:"formUrl"`
PaymentId int64 `json:"paymentId"`
OrderId int64 `json:"orderId"`
FormUrl string `json:"formUrl"`
SuccessUrl string `json:"successUrl"`
}
// PaymentResultDTO is one payout attempt's final, verified state, recorded