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:
@@ -0,0 +1 @@
|
||||
DROP INDEX IF EXISTS visa_master_payment_logs_order_step_idx;
|
||||
@@ -0,0 +1,5 @@
|
||||
-- payment-history reads each attempt's register/callback log rows
|
||||
-- (formUrl, returnUrl, first callback) by order and step; without this
|
||||
-- every row of a page scans all of its order's logs.
|
||||
CREATE INDEX IF NOT EXISTS visa_master_payment_logs_order_step_idx
|
||||
ON visa_master_payment_logs (order_id, step);
|
||||
28
docs/docs.go
28
docs/docs.go
@@ -10045,7 +10045,10 @@ const docTemplate = `{
|
||||
"type": "number"
|
||||
},
|
||||
"apiClient": {
|
||||
"description": "ApiClient is the branch's GBÜS merchant username for this order type\n(visa/master or sber) and Description the text sent with register.do -\nboth as visamasterpay's Pay picks them.",
|
||||
"description": "ApiClient is the branch's GBÜS merchant username for this order type\n(visa/master or sber), ApiClientName the branch setting it comes from\n(billing_visa_master_username or billing_sber_username), and\nDescription the text sent with register.do - all as visamasterpay's\nPay picks them.",
|
||||
"type": "string"
|
||||
},
|
||||
"apiClientName": {
|
||||
"type": "string"
|
||||
},
|
||||
"bankFeeTmt": {
|
||||
@@ -10057,6 +10060,13 @@ const docTemplate = `{
|
||||
"branchName": {
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"callbackAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"callbackStatus": {
|
||||
"description": "CallbackStatus is CallbackReceived once GBÜS's redirect reached the\ncallback for this attempt, at CallbackAt (its first time); both are\nunset if it never did (e.g. finalized by a /status check instead).",
|
||||
"type": "string"
|
||||
},
|
||||
"cardholderName": {
|
||||
"description": "CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended\ncardAuthInfo, so they're only known once an attempt has been\nfinalized by the callback/status check (unset while pending, and for\nattempts that never reached the card form).",
|
||||
"type": "string"
|
||||
@@ -10080,7 +10090,7 @@ const docTemplate = `{
|
||||
"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.",
|
||||
"description": "FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it\nwas registered with - set for every attempt register.do accepted,\nfinalized ones included (unset if registration failed).",
|
||||
"type": "string"
|
||||
},
|
||||
"gatewayReference": {
|
||||
@@ -10160,7 +10170,10 @@ const docTemplate = `{
|
||||
"type": "number"
|
||||
},
|
||||
"apiClient": {
|
||||
"description": "ApiClient is the branch's GBÜS merchant username for this order type\n(visa/master or sber) and Description the text sent with register.do -\nboth as visamasterpay's Pay picks them.",
|
||||
"description": "ApiClient is the branch's GBÜS merchant username for this order type\n(visa/master or sber), ApiClientName the branch setting it comes from\n(billing_visa_master_username or billing_sber_username), and\nDescription the text sent with register.do - all as visamasterpay's\nPay picks them.",
|
||||
"type": "string"
|
||||
},
|
||||
"apiClientName": {
|
||||
"type": "string"
|
||||
},
|
||||
"bankFeeTmt": {
|
||||
@@ -10172,6 +10185,13 @@ const docTemplate = `{
|
||||
"branchName": {
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"callbackAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"callbackStatus": {
|
||||
"description": "CallbackStatus is CallbackReceived once GBÜS's redirect reached the\ncallback for this attempt, at CallbackAt (its first time); both are\nunset if it never did (e.g. finalized by a /status check instead).",
|
||||
"type": "string"
|
||||
},
|
||||
"cardholderName": {
|
||||
"description": "CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended\ncardAuthInfo, so they're only known once an attempt has been\nfinalized by the callback/status check (unset while pending, and for\nattempts that never reached the card form).",
|
||||
"type": "string"
|
||||
@@ -10195,7 +10215,7 @@ const docTemplate = `{
|
||||
"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.",
|
||||
"description": "FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it\nwas registered with - set for every attempt register.do accepted,\nfinalized ones included (unset if registration failed).",
|
||||
"type": "string"
|
||||
},
|
||||
"gatewayReference": {
|
||||
|
||||
@@ -10039,7 +10039,10 @@
|
||||
"type": "number"
|
||||
},
|
||||
"apiClient": {
|
||||
"description": "ApiClient is the branch's GBÜS merchant username for this order type\n(visa/master or sber) and Description the text sent with register.do -\nboth as visamasterpay's Pay picks them.",
|
||||
"description": "ApiClient is the branch's GBÜS merchant username for this order type\n(visa/master or sber), ApiClientName the branch setting it comes from\n(billing_visa_master_username or billing_sber_username), and\nDescription the text sent with register.do - all as visamasterpay's\nPay picks them.",
|
||||
"type": "string"
|
||||
},
|
||||
"apiClientName": {
|
||||
"type": "string"
|
||||
},
|
||||
"bankFeeTmt": {
|
||||
@@ -10051,6 +10054,13 @@
|
||||
"branchName": {
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"callbackAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"callbackStatus": {
|
||||
"description": "CallbackStatus is CallbackReceived once GBÜS's redirect reached the\ncallback for this attempt, at CallbackAt (its first time); both are\nunset if it never did (e.g. finalized by a /status check instead).",
|
||||
"type": "string"
|
||||
},
|
||||
"cardholderName": {
|
||||
"description": "CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended\ncardAuthInfo, so they're only known once an attempt has been\nfinalized by the callback/status check (unset while pending, and for\nattempts that never reached the card form).",
|
||||
"type": "string"
|
||||
@@ -10074,7 +10084,7 @@
|
||||
"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.",
|
||||
"description": "FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it\nwas registered with - set for every attempt register.do accepted,\nfinalized ones included (unset if registration failed).",
|
||||
"type": "string"
|
||||
},
|
||||
"gatewayReference": {
|
||||
@@ -10154,7 +10164,10 @@
|
||||
"type": "number"
|
||||
},
|
||||
"apiClient": {
|
||||
"description": "ApiClient is the branch's GBÜS merchant username for this order type\n(visa/master or sber) and Description the text sent with register.do -\nboth as visamasterpay's Pay picks them.",
|
||||
"description": "ApiClient is the branch's GBÜS merchant username for this order type\n(visa/master or sber), ApiClientName the branch setting it comes from\n(billing_visa_master_username or billing_sber_username), and\nDescription the text sent with register.do - all as visamasterpay's\nPay picks them.",
|
||||
"type": "string"
|
||||
},
|
||||
"apiClientName": {
|
||||
"type": "string"
|
||||
},
|
||||
"bankFeeTmt": {
|
||||
@@ -10166,6 +10179,13 @@
|
||||
"branchName": {
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"callbackAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"callbackStatus": {
|
||||
"description": "CallbackStatus is CallbackReceived once GBÜS's redirect reached the\ncallback for this attempt, at CallbackAt (its first time); both are\nunset if it never did (e.g. finalized by a /status check instead).",
|
||||
"type": "string"
|
||||
},
|
||||
"cardholderName": {
|
||||
"description": "CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended\ncardAuthInfo, so they're only known once an attempt has been\nfinalized by the callback/status check (unset while pending, and for\nattempts that never reached the card form).",
|
||||
"type": "string"
|
||||
@@ -10189,7 +10209,7 @@
|
||||
"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.",
|
||||
"description": "FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it\nwas registered with - set for every attempt register.do accepted,\nfinalized ones included (unset if registration failed).",
|
||||
"type": "string"
|
||||
},
|
||||
"gatewayReference": {
|
||||
|
||||
@@ -1348,8 +1348,12 @@ definitions:
|
||||
apiClient:
|
||||
description: |-
|
||||
ApiClient is the branch's GBÜS merchant username for this order type
|
||||
(visa/master or sber) and Description the text sent with register.do -
|
||||
both as visamasterpay's Pay picks them.
|
||||
(visa/master or sber), ApiClientName the branch setting it comes from
|
||||
(billing_visa_master_username or billing_sber_username), and
|
||||
Description the text sent with register.do - all as visamasterpay's
|
||||
Pay picks them.
|
||||
type: string
|
||||
apiClientName:
|
||||
type: string
|
||||
bankFeeTmt:
|
||||
type: number
|
||||
@@ -1357,6 +1361,14 @@ definitions:
|
||||
type: integer
|
||||
branchName:
|
||||
$ref: '#/definitions/shared.LocalizedText'
|
||||
callbackAt:
|
||||
type: string
|
||||
callbackStatus:
|
||||
description: |-
|
||||
CallbackStatus is CallbackReceived once GBÜS's redirect reached the
|
||||
callback for this attempt, at CallbackAt (its first time); both are
|
||||
unset if it never did (e.g. finalized by a /status check instead).
|
||||
type: string
|
||||
cardholderName:
|
||||
description: |-
|
||||
CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended
|
||||
@@ -1378,10 +1390,9 @@ definitions:
|
||||
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.
|
||||
FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it
|
||||
was registered with - set for every attempt register.do accepted,
|
||||
finalized ones included (unset if registration failed).
|
||||
type: string
|
||||
gatewayReference:
|
||||
type: string
|
||||
@@ -1439,8 +1450,12 @@ definitions:
|
||||
apiClient:
|
||||
description: |-
|
||||
ApiClient is the branch's GBÜS merchant username for this order type
|
||||
(visa/master or sber) and Description the text sent with register.do -
|
||||
both as visamasterpay's Pay picks them.
|
||||
(visa/master or sber), ApiClientName the branch setting it comes from
|
||||
(billing_visa_master_username or billing_sber_username), and
|
||||
Description the text sent with register.do - all as visamasterpay's
|
||||
Pay picks them.
|
||||
type: string
|
||||
apiClientName:
|
||||
type: string
|
||||
bankFeeTmt:
|
||||
type: number
|
||||
@@ -1448,6 +1463,14 @@ definitions:
|
||||
type: integer
|
||||
branchName:
|
||||
$ref: '#/definitions/shared.LocalizedText'
|
||||
callbackAt:
|
||||
type: string
|
||||
callbackStatus:
|
||||
description: |-
|
||||
CallbackStatus is CallbackReceived once GBÜS's redirect reached the
|
||||
callback for this attempt, at CallbackAt (its first time); both are
|
||||
unset if it never did (e.g. finalized by a /status check instead).
|
||||
type: string
|
||||
cardholderName:
|
||||
description: |-
|
||||
CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended
|
||||
@@ -1469,10 +1492,9 @@ definitions:
|
||||
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.
|
||||
FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it
|
||||
was registered with - set for every attempt register.do accepted,
|
||||
finalized ones included (unset if registration failed).
|
||||
type: string
|
||||
gatewayReference:
|
||||
type: string
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -45,28 +45,39 @@ type PaymentHistoryItemDTO struct {
|
||||
GatewayStatus string `json:"gatewayStatus"`
|
||||
GatewayReference *string `json:"gatewayReference,omitempty"`
|
||||
// ApiClient is the branch's GBÜS merchant username for this order type
|
||||
// (visa/master or sber) and Description the text sent with register.do -
|
||||
// both as visamasterpay's Pay picks them.
|
||||
ApiClient string `json:"apiClient"`
|
||||
Description string `json:"description"`
|
||||
// (visa/master or sber), ApiClientName the branch setting it comes from
|
||||
// (billing_visa_master_username or billing_sber_username), and
|
||||
// Description the text sent with register.do - all as visamasterpay's
|
||||
// Pay picks them.
|
||||
ApiClient string `json:"apiClient"`
|
||||
ApiClientName string `json:"apiClientName"`
|
||||
Description string `json:"description"`
|
||||
// CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended
|
||||
// cardAuthInfo, so they're only known once an attempt has been
|
||||
// finalized by the callback/status check (unset while pending, and for
|
||||
// attempts that never reached the card form).
|
||||
CardholderName *string `json:"cardholderName,omitempty"`
|
||||
MaskedPan *string `json:"maskedPan,omitempty"`
|
||||
// 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"`
|
||||
// FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it
|
||||
// was registered with - set for every attempt register.do accepted,
|
||||
// finalized ones included (unset if registration failed).
|
||||
FormUrl *string `json:"formUrl,omitempty"`
|
||||
SuccessUrl *string `json:"successUrl,omitempty"`
|
||||
// CallbackStatus is CallbackReceived once GBÜS's redirect reached the
|
||||
// callback for this attempt, at CallbackAt (its first time); both are
|
||||
// unset if it never did (e.g. finalized by a /status check instead).
|
||||
CallbackStatus *string `json:"callbackStatus,omitempty"`
|
||||
CallbackAt *time.Time `json:"callbackAt,omitempty"`
|
||||
CreatedById *int64 `json:"createdById,omitempty"`
|
||||
CreatedByName string `json:"createdByName,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// CallbackReceived is PaymentHistoryItemDTO.CallbackStatus once the GBÜS
|
||||
// callback reached an attempt.
|
||||
const CallbackReceived = "received"
|
||||
|
||||
// PaymentHistoryDetailDTO is a single payout attempt with the raw GBÜS
|
||||
// response kept alongside it - the list deliberately leaves the jsonb out
|
||||
// so pages stay small.
|
||||
|
||||
Reference in New Issue
Block a user