payment-history: apiClientName, formUrl/successUrl after finalizing, callbackStatus
To match the old online payment history page:
- apiClientName: billing_visa_master_username / billing_sber_username
- formUrl falls back to the logged register.do response, so finalized
attempts keep it; successUrl is the returnUrl logged with register.do
- callbackStatus ("received") and callbackAt from the attempt's first
callback_received log
- index visa_master_payment_logs (order_id, step) for those lookups
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae6bf0b7e3
commit
ef3a1baee2
7 files changed
+140
-46
No files matched your search
@@ -36,9 +36,16 @@ LEFT JOIN users u ON u.id = p.created_by`
|
||||
// isSberSQL mirrors visamasterpay's isSber for the order joined as o.
|
||||
const isSberSQL = `LOWER(TRIM(COALESCE(o.type, ''))) = 'sber'`
|
||||
|
||||
// paymentLogSQL selects from the order's visa_master_payment_logs rows of
|
||||
// one step (served by visa_master_payment_logs_order_step_idx).
|
||||
const paymentLogSQL = `FROM visa_master_payment_logs l WHERE l.order_id = p.order_id AND l.step = `
|
||||
|
||||
// historySelectColumns pulls only the handful of gateway_response fields a
|
||||
// row needs (formUrl, cardAuthInfo) out in SQL rather than shipping every
|
||||
// row's whole jsonb blob to Go and decoding it there.
|
||||
// row's whole jsonb blob to Go and decoding it there. formUrl falls back to
|
||||
// the register.do response logged for the attempt (gateway_response drops
|
||||
// it once finalized), successUrl is the returnUrl logged with register.do,
|
||||
// and the callback columns come from its first callback_received log.
|
||||
const historySelectColumns = `p.id, p.order_id, COALESCE(p.order_number, ''), COALESCE(o.unique_id, ''), COALESCE(o.type, ''),
|
||||
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,
|
||||
@@ -47,10 +54,15 @@ const historySelectColumns = `p.id, p.order_id, COALESCE(p.order_number, ''), CO
|
||||
p.exchange_rate_usd, p.exchange_rate_rub, p.payment_period,
|
||||
p.gateway_status, p.gateway_reference,
|
||||
CASE WHEN ` + isSberSQL + ` THEN COALESCE(b.billing_sber_username, '') ELSE COALESCE(b.billing_visa_master_username, '') END,
|
||||
CASE WHEN ` + isSberSQL + ` THEN 'billing_sber_username' ELSE 'billing_visa_master_username' END,
|
||||
CASE WHEN ` + isSberSQL + ` THEN 'Sber tölegi' ELSE 'Visa/Master tölegi' END,
|
||||
NULLIF(p.gateway_response->'cardAuthInfo'->>'cardholderName', ''),
|
||||
NULLIF(COALESCE(p.gateway_response->'cardAuthInfo'->>'maskedPan', p.gateway_response->'cardAuthInfo'->>'pan'), ''),
|
||||
NULLIF(p.gateway_response->>'formUrl', ''),
|
||||
COALESCE(NULLIF(p.gateway_response->>'formUrl', ''), (SELECT NULLIF(l.detail->>'formUrl', '') ` + paymentLogSQL + `'register_response'
|
||||
AND l.detail->>'gbusOrderId' = p.gateway_reference ORDER BY l.id DESC LIMIT 1)),
|
||||
(SELECT NULLIF(l.detail->>'returnUrl', '') ` + paymentLogSQL + `'register_request'
|
||||
AND l.detail->>'paymentId' = p.id::text ORDER BY l.id DESC LIMIT 1),
|
||||
(SELECT MIN(l.created_at) ` + paymentLogSQL + `'callback_received' AND l.detail->>'paymentId' = p.id::text),
|
||||
p.created_by, ` + shared.UserDisplaySQL + `,
|
||||
p.created_at, p.updated_at`
|
||||
|
||||
@@ -227,7 +239,6 @@ func buildListQuery(filter paymenthistory.ListFilter) (whereClause string, args
|
||||
func (r *repository) scanHistoryItem(row pgx.Row, extra ...interface{}) (paymenthistory.PaymentHistoryItemDTO, error) {
|
||||
var item paymenthistory.PaymentHistoryItemDTO
|
||||
var branchNameJSON []byte
|
||||
var formURL *string
|
||||
dest := []interface{}{
|
||||
&item.Id, &item.OrderId, &item.OrderNumber, &item.OrderUniqueId, &item.Type,
|
||||
&item.BranchId, &branchNameJSON, &item.PassportName, &item.PassportSurname, &item.UserId,
|
||||
@@ -235,8 +246,8 @@ func (r *repository) scanHistoryItem(row pgx.Row, extra ...interface{}) (payment
|
||||
&item.AmountMinor, &item.AmountUsd,
|
||||
&item.ExchangeRateUsd, &item.ExchangeRateRub, &item.PaymentPeriod,
|
||||
&item.GatewayStatus, &item.GatewayReference,
|
||||
&item.ApiClient, &item.Description,
|
||||
&item.CardholderName, &item.MaskedPan, &formURL,
|
||||
&item.ApiClient, &item.ApiClientName, &item.Description,
|
||||
&item.CardholderName, &item.MaskedPan, &item.FormUrl, &item.SuccessUrl, &item.CallbackAt,
|
||||
&item.CreatedById, &item.CreatedByName,
|
||||
&item.CreatedAt, &item.UpdatedAt,
|
||||
}
|
||||
@@ -248,13 +259,17 @@ func (r *repository) scanHistoryItem(row pgx.Row, extra ...interface{}) (payment
|
||||
}
|
||||
item.Paid = item.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. SuccessUrl must match the ReturnURL
|
||||
// visamasterpay registered with GBÜS (see its Pay).
|
||||
if formURL != nil {
|
||||
item.FormUrl = formURL
|
||||
if item.CallbackAt != nil {
|
||||
received := paymenthistory.CallbackReceived
|
||||
item.CallbackStatus = &received
|
||||
}
|
||||
|
||||
// A returnUrl only matters for an attempt GBÜS registered (has a
|
||||
// formUrl). Ones registered before register_request logged its
|
||||
// returnUrl fall back to the ReturnURL visamasterpay's Pay uses.
|
||||
if item.FormUrl == nil {
|
||||
item.SuccessUrl = nil
|
||||
} else if item.SuccessUrl == nil {
|
||||
successURL := r.publicBaseURL + "/online/visa-master"
|
||||
item.SuccessUrl = &successURL
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user