ch some
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:
guwandyk committed 2026-09-21 19:12:07 +05:00
1 parent febd190d6e
commit 235ef5ec9e
8 files changed
+96 -19

No files matched your search

+13
View File
@@ -9416,6 +9416,10 @@ const docTemplate = `{
"exchangeRateUsd": { "exchangeRateUsd": {
"type": "number" "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": { "gatewayReference": {
"type": "string" "type": "string"
}, },
@@ -9446,6 +9450,9 @@ const docTemplate = `{
"paymentPeriod": { "paymentPeriod": {
"type": "string" "type": "string"
}, },
"successUrl": {
"type": "string"
},
"totalAmountTmt": { "totalAmountTmt": {
"type": "number" "type": "number"
}, },
@@ -10060,8 +10067,14 @@ const docTemplate = `{
"formUrl": { "formUrl": {
"type": "string" "type": "string"
}, },
"orderId": {
"type": "integer"
},
"paymentId": { "paymentId": {
"type": "integer" "type": "integer"
},
"successUrl": {
"type": "string"
} }
} }
}, },
+13
View File
@@ -9410,6 +9410,10 @@
"exchangeRateUsd": { "exchangeRateUsd": {
"type": "number" "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": { "gatewayReference": {
"type": "string" "type": "string"
}, },
@@ -9440,6 +9444,9 @@
"paymentPeriod": { "paymentPeriod": {
"type": "string" "type": "string"
}, },
"successUrl": {
"type": "string"
},
"totalAmountTmt": { "totalAmountTmt": {
"type": "number" "type": "number"
}, },
@@ -10054,8 +10061,14 @@
"formUrl": { "formUrl": {
"type": "string" "type": "string"
}, },
"orderId": {
"type": "integer"
},
"paymentId": { "paymentId": {
"type": "integer" "type": "integer"
},
"successUrl": {
"type": "string"
} }
} }
}, },
+13
View File
@@ -1324,6 +1324,13 @@ definitions:
type: number type: number
exchangeRateUsd: exchangeRateUsd:
type: number 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: gatewayReference:
type: string type: string
gatewayStatus: gatewayStatus:
@@ -1344,6 +1351,8 @@ definitions:
type: string type: string
paymentPeriod: paymentPeriod:
type: string type: string
successUrl:
type: string
totalAmountTmt: totalAmountTmt:
type: number type: number
tvebFeeTmt: tvebFeeTmt:
@@ -1764,8 +1773,12 @@ definitions:
properties: properties:
formUrl: formUrl:
type: string type: string
orderId:
type: integer
paymentId: paymentId:
type: integer type: integer
successUrl:
type: string
type: object type: object
visamasterpay.PaymentQuoteDTO: visamasterpay.PaymentQuoteDTO:
properties: properties:
@@ -2,6 +2,7 @@ package db
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"strings" "strings"
@@ -15,12 +16,13 @@ import (
) )
type repository struct { type repository struct {
client postgresql.Client client postgresql.Client
logger *logging.Logger logger *logging.Logger
publicBaseURL string
} }
func NewRepository(client postgresql.Client, logger *logging.Logger) paymenthistory.Repository { func NewRepository(client postgresql.Client, logger *logging.Logger, publicBaseURL string) paymenthistory.Repository {
return &repository{client: client, logger: logger} return &repository{client: client, logger: logger, publicBaseURL: strings.TrimRight(publicBaseURL, "/")}
} }
const historyFromClause = ` FROM visa_master_order_payments p 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, 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.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.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` p.created_at, p.updated_at`
func (r *repository) List(ctx context.Context, filter paymenthistory.ListFilter) (paymenthistory.ListPaymentHistoryDTO, error) { 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 var items []paymenthistory.PaymentHistoryItemDTO
for rows.Next() { for rows.Next() {
item, err := scanHistoryItem(rows) item, err := r.scanHistoryItem(rows)
if err != nil { if err != nil {
return paymenthistory.ListPaymentHistoryDTO{}, err return paymenthistory.ListPaymentHistoryDTO{}, err
} }
@@ -109,16 +111,17 @@ func buildListQuery(filter paymenthistory.ListFilter) (whereClause string, args
return " WHERE " + strings.Join(conditions, " AND "), 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 item paymenthistory.PaymentHistoryItemDTO
var gatewayStatus string var gatewayStatus string
var branchNameJSON []byte var branchNameJSON []byte
var gatewayResponse []byte
if err := row.Scan( if err := row.Scan(
&item.Id, &item.OrderId, &item.OrderUniqueId, &item.Type, &item.Id, &item.OrderId, &item.OrderUniqueId, &item.Type,
&item.BranchId, &branchNameJSON, &item.PassportName, &item.PassportSurname, &item.UserId, &item.BranchId, &branchNameJSON, &item.PassportName, &item.PassportSurname, &item.UserId,
&item.AmountTmt, &item.BankFeeTmt, &item.GbusFeeTmt, &item.TvebFeeUsd, &item.TvebFeeTmt, &item.TotalAmountTmt, &item.AmountTmt, &item.BankFeeTmt, &item.GbusFeeTmt, &item.TvebFeeUsd, &item.TvebFeeTmt, &item.TotalAmountTmt,
&item.ExchangeRateUsd, &item.ExchangeRateRub, &item.PaymentPeriod, &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, &item.CreatedAt, &item.UpdatedAt,
); err != nil { ); err != nil {
return paymenthistory.PaymentHistoryItemDTO{}, err return paymenthistory.PaymentHistoryItemDTO{}, err
@@ -128,5 +131,29 @@ func scanHistoryItem(row pgx.Row) (paymenthistory.PaymentHistoryItemDTO, error)
} }
item.GatewayStatus = gatewayStatus item.GatewayStatus = gatewayStatus
item.Paid = gatewayStatus == "success" 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 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
}
+10 -4
View File
@@ -37,10 +37,16 @@ type PaymentHistoryItemDTO struct {
PaymentPeriod time.Time `json:"paymentPeriod"` PaymentPeriod time.Time `json:"paymentPeriod"`
GatewayStatus string `json:"gatewayStatus"` GatewayStatus string `json:"gatewayStatus"`
GatewayReference *string `json:"gatewayReference,omitempty"` GatewayReference *string `json:"gatewayReference,omitempty"`
CreatedById *int64 `json:"createdById,omitempty"` // FormUrl/SuccessUrl are only set while the attempt is still pending
CreatedByName string `json:"createdByName,omitempty"` // (awaiting the customer to finish paying on GBÜS's hosted page) - once
CreatedAt time.Time `json:"createdAt"` // an attempt is finalized (success/failed), gateway_response no longer
UpdatedAt time.Time `json:"updatedAt"` // 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 // ListFilter narrows the history list. BranchIds is populated by
+1 -1
View File
@@ -32,6 +32,6 @@ func Handlers(client postgresql.Client, logger *logging.Logger, currencyRepo cur
return []handlers.Handler{ return []handlers.Handler{
paymentsettings.NewHandler(logger, settingsRepo), paymentsettings.NewHandler(logger, settingsRepo),
visamasterpay.NewHandler(logger, visamasterpaydb.NewRepository(client, logger, currencyRepo, settingsRepo, gateway, publicBaseURL)), 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)),
} }
} }
@@ -294,8 +294,8 @@ func (r *repository) Pay(ctx context.Context, orderID int64, dto visamasterpay.P
return visamasterpay.PaymentInitResultDTO{}, err return visamasterpay.PaymentInitResultDTO{}, err
} }
println("[pay] step 13 done: paymentId=", paymentID, "formUrl=", result.FormUrl) println("[pay] step 13 done: paymentId=", paymentID, "formUrl=", result.FormUrl, "successUrl=", returnURL)
return visamasterpay.PaymentInitResultDTO{PaymentId: paymentID, FormUrl: result.FormUrl}, nil return visamasterpay.PaymentInitResultDTO{PaymentId: paymentID, OrderId: orderID, FormUrl: result.FormUrl, SuccessUrl: returnURL}, nil
} }
// HandleCallback is hit (unauthenticated - see rbac.isPublicAdminPath) when // 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) println("[callback] step 7b ok: lockedPaid=", lockedPaid)
if !lockedPaid { if !lockedPaid {
println("[callback] step 7c: marking order paid") println("[callback] step 7c: marking order paid and completed")
if _, err := tx.Exec(ctx, 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, orderID,
); err != nil { ); err != nil {
println("[callback] step 7c FAILED: mark order paid:", err.Error()) println("[callback] step 7c FAILED: mark order paid:", err.Error())
+7 -2
View File
@@ -45,9 +45,14 @@ type PayOrderDTO struct {
// - the customer (or the operator, in-branch) must complete payment there. // - the customer (or the operator, in-branch) must complete payment there.
// The definitive outcome only becomes known once GBÜS redirects back to // The definitive outcome only becomes known once GBÜS redirects back to
// our callback, which verifies and finalizes it - see PaymentResultDTO. // 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 { type PaymentInitResultDTO struct {
PaymentId int64 `json:"paymentId"` PaymentId int64 `json:"paymentId"`
FormUrl string `json:"formUrl"` OrderId int64 `json:"orderId"`
FormUrl string `json:"formUrl"`
SuccessUrl string `json:"successUrl"`
} }
// PaymentResultDTO is one payout attempt's final, verified state, recorded // PaymentResultDTO is one payout attempt's final, verified state, recorded