Author SHA1 Message Date
guwandykandClaude Opus 5.5 ef3a1baee2 payment-history: apiClientName, formUrl/successUrl after finalizing, callbackStatus
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
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>
2026-10-24 19:49:24 +05:00
guwandykandClaude Opus 5.5 ae6bf0b7e3 payment-history: GET /payments/{id}/gateway - one payment with its HALKBANK JSON
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
Returns a payment the way the per-order payment table shows it (paid,
cardholder name, masked card, time, payment year/month, USD/TMT amounts,
reference) plus the last stored GBÜS response, for the storage icon.
Card fields and gatewayResponse are null until GBÜS reports them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 19:10:32 +05:00
9 changed files with 611 additions and 52 deletions

No files matched your search

@@ -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);
+126 -4
View File
@@ -5430,6 +5430,64 @@ const docTemplate = `{
} }
} }
}, },
"/payment-history/payments/{id}/gateway": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "Returns one payment the way the per-order payment table shows it - paid or not, the card it was paid from (cardholderName/maskedPan, null until GBÜS reports them), its time (createdAt), payment year/month, amounts and reference (orderNumber) - together with the last GBÜS (HALKBANK) response stored for it (gatewayResponse, null if GBÜS never answered). Backs the table's storage icon.",
"produces": [
"application/json"
],
"tags": [
"payment-history"
],
"summary": "Get a payment with its HALKBANK response",
"parameters": [
{
"type": "integer",
"description": "Payment ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
}
}
}
},
"/payment-history/{id}": { "/payment-history/{id}": {
"get": { "get": {
"security": [ "security": [
@@ -9928,6 +9986,50 @@ const docTemplate = `{
} }
} }
}, },
"paymenthistory.PaymentGatewayDTO": {
"type": "object",
"properties": {
"amountTmt": {
"type": "number"
},
"amountUsd": {
"type": "number"
},
"cardholderName": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"gatewayResponse": {
"type": "object"
},
"gatewayStatus": {
"type": "string"
},
"id": {
"type": "integer"
},
"maskedPan": {
"type": "string"
},
"orderId": {
"type": "integer"
},
"orderNumber": {
"type": "string"
},
"paid": {
"type": "boolean"
},
"paymentMonth": {
"type": "integer"
},
"paymentYear": {
"type": "integer"
}
}
},
"paymenthistory.PaymentHistoryDetailDTO": { "paymenthistory.PaymentHistoryDetailDTO": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -9943,7 +10045,10 @@ const docTemplate = `{
"type": "number" "type": "number"
}, },
"apiClient": { "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" "type": "string"
}, },
"bankFeeTmt": { "bankFeeTmt": {
@@ -9955,6 +10060,13 @@ const docTemplate = `{
"branchName": { "branchName": {
"$ref": "#/definitions/shared.LocalizedText" "$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": { "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).", "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" "type": "string"
@@ -9978,7 +10090,7 @@ const docTemplate = `{
"type": "number" "type": "number"
}, },
"formUrl": { "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" "type": "string"
}, },
"gatewayReference": { "gatewayReference": {
@@ -10058,7 +10170,10 @@ const docTemplate = `{
"type": "number" "type": "number"
}, },
"apiClient": { "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" "type": "string"
}, },
"bankFeeTmt": { "bankFeeTmt": {
@@ -10070,6 +10185,13 @@ const docTemplate = `{
"branchName": { "branchName": {
"$ref": "#/definitions/shared.LocalizedText" "$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": { "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).", "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" "type": "string"
@@ -10093,7 +10215,7 @@ const docTemplate = `{
"type": "number" "type": "number"
}, },
"formUrl": { "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" "type": "string"
}, },
"gatewayReference": { "gatewayReference": {
+126 -4
View File
@@ -5424,6 +5424,64 @@
} }
} }
}, },
"/payment-history/payments/{id}/gateway": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "Returns one payment the way the per-order payment table shows it - paid or not, the card it was paid from (cardholderName/maskedPan, null until GBÜS reports them), its time (createdAt), payment year/month, amounts and reference (orderNumber) - together with the last GBÜS (HALKBANK) response stored for it (gatewayResponse, null if GBÜS never answered). Backs the table's storage icon.",
"produces": [
"application/json"
],
"tags": [
"payment-history"
],
"summary": "Get a payment with its HALKBANK response",
"parameters": [
{
"type": "integer",
"description": "Payment ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/paymenthistory.PaymentGatewayDTO"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
}
}
}
},
"/payment-history/{id}": { "/payment-history/{id}": {
"get": { "get": {
"security": [ "security": [
@@ -9922,6 +9980,50 @@
} }
} }
}, },
"paymenthistory.PaymentGatewayDTO": {
"type": "object",
"properties": {
"amountTmt": {
"type": "number"
},
"amountUsd": {
"type": "number"
},
"cardholderName": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"gatewayResponse": {
"type": "object"
},
"gatewayStatus": {
"type": "string"
},
"id": {
"type": "integer"
},
"maskedPan": {
"type": "string"
},
"orderId": {
"type": "integer"
},
"orderNumber": {
"type": "string"
},
"paid": {
"type": "boolean"
},
"paymentMonth": {
"type": "integer"
},
"paymentYear": {
"type": "integer"
}
}
},
"paymenthistory.PaymentHistoryDetailDTO": { "paymenthistory.PaymentHistoryDetailDTO": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -9937,7 +10039,10 @@
"type": "number" "type": "number"
}, },
"apiClient": { "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" "type": "string"
}, },
"bankFeeTmt": { "bankFeeTmt": {
@@ -9949,6 +10054,13 @@
"branchName": { "branchName": {
"$ref": "#/definitions/shared.LocalizedText" "$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": { "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).", "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" "type": "string"
@@ -9972,7 +10084,7 @@
"type": "number" "type": "number"
}, },
"formUrl": { "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" "type": "string"
}, },
"gatewayReference": { "gatewayReference": {
@@ -10052,7 +10164,10 @@
"type": "number" "type": "number"
}, },
"apiClient": { "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" "type": "string"
}, },
"bankFeeTmt": { "bankFeeTmt": {
@@ -10064,6 +10179,13 @@
"branchName": { "branchName": {
"$ref": "#/definitions/shared.LocalizedText" "$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": { "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).", "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" "type": "string"
@@ -10087,7 +10209,7 @@
"type": "number" "type": "number"
}, },
"formUrl": { "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" "type": "string"
}, },
"gatewayReference": { "gatewayReference": {
+105 -12
View File
@@ -1304,6 +1304,35 @@ definitions:
$ref: '#/definitions/paymenthistory.PaymentHistoryItemDTO' $ref: '#/definitions/paymenthistory.PaymentHistoryItemDTO'
type: array type: array
type: object type: object
paymenthistory.PaymentGatewayDTO:
properties:
amountTmt:
type: number
amountUsd:
type: number
cardholderName:
type: string
createdAt:
type: string
gatewayResponse:
type: object
gatewayStatus:
type: string
id:
type: integer
maskedPan:
type: string
orderId:
type: integer
orderNumber:
type: string
paid:
type: boolean
paymentMonth:
type: integer
paymentYear:
type: integer
type: object
paymenthistory.PaymentHistoryDetailDTO: paymenthistory.PaymentHistoryDetailDTO:
properties: properties:
amountMinor: amountMinor:
@@ -1319,8 +1348,12 @@ definitions:
apiClient: apiClient:
description: |- description: |-
ApiClient is the branch's GBÜS merchant username for this order type 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 - (visa/master or sber), ApiClientName the branch setting it comes from
both as visamasterpay's Pay picks them. (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 type: string
bankFeeTmt: bankFeeTmt:
type: number type: number
@@ -1328,6 +1361,14 @@ definitions:
type: integer type: integer
branchName: branchName:
$ref: '#/definitions/shared.LocalizedText' $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: cardholderName:
description: |- description: |-
CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended
@@ -1349,10 +1390,9 @@ definitions:
type: number type: number
formUrl: formUrl:
description: |- description: |-
FormUrl/SuccessUrl are only set while the attempt is still pending FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it
(awaiting the customer to finish paying on GBÜS's hosted page) - once was registered with - set for every attempt register.do accepted,
an attempt is finalized (success/failed), gateway_response no longer finalized ones included (unset if registration failed).
holds a formUrl, so there's nothing left to resume.
type: string type: string
gatewayReference: gatewayReference:
type: string type: string
@@ -1410,8 +1450,12 @@ definitions:
apiClient: apiClient:
description: |- description: |-
ApiClient is the branch's GBÜS merchant username for this order type 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 - (visa/master or sber), ApiClientName the branch setting it comes from
both as visamasterpay's Pay picks them. (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 type: string
bankFeeTmt: bankFeeTmt:
type: number type: number
@@ -1419,6 +1463,14 @@ definitions:
type: integer type: integer
branchName: branchName:
$ref: '#/definitions/shared.LocalizedText' $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: cardholderName:
description: |- description: |-
CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended
@@ -1440,10 +1492,9 @@ definitions:
type: number type: number
formUrl: formUrl:
description: |- description: |-
FormUrl/SuccessUrl are only set while the attempt is still pending FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it
(awaiting the customer to finish paying on GBÜS's hosted page) - once was registered with - set for every attempt register.do accepted,
an attempt is finalized (success/failed), gateway_response no longer finalized ones included (unset if registration failed).
holds a formUrl, so there's nothing left to resume.
type: string type: string
gatewayReference: gatewayReference:
type: string type: string
@@ -5701,6 +5752,48 @@ paths:
summary: Get a single payment attempt summary: Get a single payment attempt
tags: tags:
- payment-history - payment-history
/payment-history/payments/{id}/gateway:
get:
description: Returns one payment the way the per-order payment table shows it
- paid or not, the card it was paid from (cardholderName/maskedPan, null until
GBÜS reports them), its time (createdAt), payment year/month, amounts and
reference (orderNumber) - together with the last GBÜS (HALKBANK) response
stored for it (gatewayResponse, null if GBÜS never answered). Backs the table's
storage icon.
parameters:
- description: Payment ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/paymenthistory.PaymentGatewayDTO'
"400":
description: Bad Request
schema:
$ref: '#/definitions/appresult.AppError'
"403":
description: Forbidden
schema:
$ref: '#/definitions/appresult.AppError'
"404":
description: Not Found
schema:
$ref: '#/definitions/appresult.AppError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/appresult.AppError'
security:
- BearerAuth: []
summary: Get a payment with its HALKBANK response
tags:
- payment-history
/payment-settings: /payment-settings:
get: get:
description: Returns the admin-configurable bank and GBÜS commission fees used description: Returns the admin-configurable bank and GBÜS commission fees used
@@ -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. // isSberSQL mirrors visamasterpay's isSber for the order joined as o.
const isSberSQL = `LOWER(TRIM(COALESCE(o.type, ''))) = 'sber'` 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 // historySelectColumns pulls only the handful of gateway_response fields a
// row needs (formUrl, cardAuthInfo) out in SQL rather than shipping every // 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, ''), 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, 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,
@@ -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.exchange_rate_usd, p.exchange_rate_rub, p.payment_period,
p.gateway_status, p.gateway_reference, 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 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, CASE WHEN ` + isSberSQL + ` THEN 'Sber tölegi' ELSE 'Visa/Master tölegi' END,
NULLIF(p.gateway_response->'cardAuthInfo'->>'cardholderName', ''), NULLIF(p.gateway_response->'cardAuthInfo'->>'cardholderName', ''),
NULLIF(COALESCE(p.gateway_response->'cardAuthInfo'->>'maskedPan', p.gateway_response->'cardAuthInfo'->>'pan'), ''), 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_by, ` + shared.UserDisplaySQL + `,
p.created_at, p.updated_at` 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) { func (r *repository) scanHistoryItem(row pgx.Row, extra ...interface{}) (paymenthistory.PaymentHistoryItemDTO, error) {
var item paymenthistory.PaymentHistoryItemDTO var item paymenthistory.PaymentHistoryItemDTO
var branchNameJSON []byte var branchNameJSON []byte
var formURL *string
dest := []interface{}{ dest := []interface{}{
&item.Id, &item.OrderId, &item.OrderNumber, &item.OrderUniqueId, &item.Type, &item.Id, &item.OrderId, &item.OrderNumber, &item.OrderUniqueId, &item.Type,
&item.BranchId, &branchNameJSON, &item.PassportName, &item.PassportSurname, &item.UserId, &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.AmountMinor, &item.AmountUsd,
&item.ExchangeRateUsd, &item.ExchangeRateRub, &item.PaymentPeriod, &item.ExchangeRateUsd, &item.ExchangeRateRub, &item.PaymentPeriod,
&item.GatewayStatus, &item.GatewayReference, &item.GatewayStatus, &item.GatewayReference,
&item.ApiClient, &item.Description, &item.ApiClient, &item.ApiClientName, &item.Description,
&item.CardholderName, &item.MaskedPan, &formURL, &item.CardholderName, &item.MaskedPan, &item.FormUrl, &item.SuccessUrl, &item.CallbackAt,
&item.CreatedById, &item.CreatedByName, &item.CreatedById, &item.CreatedByName,
&item.CreatedAt, &item.UpdatedAt, &item.CreatedAt, &item.UpdatedAt,
} }
@@ -248,13 +259,17 @@ func (r *repository) scanHistoryItem(row pgx.Row, extra ...interface{}) (payment
} }
item.Paid = item.GatewayStatus == "success" item.Paid = item.GatewayStatus == "success"
// formUrl only survives in gateway_response while the attempt is still if item.CallbackAt != nil {
// pending - once finalized, gateway_response is overwritten with the received := paymenthistory.CallbackReceived
// status-check response, which has no formUrl, so there's nothing to item.CallbackStatus = &received
// resume for a paid/failed row. SuccessUrl must match the ReturnURL }
// visamasterpay registered with GBÜS (see its Pay).
if formURL != nil { // A returnUrl only matters for an attempt GBÜS registered (has a
item.FormUrl = formURL // 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" successURL := r.publicBaseURL + "/online/visa-master"
item.SuccessUrl = &successURL item.SuccessUrl = &successURL
} }
+69 -14
View File
@@ -45,28 +45,39 @@ type PaymentHistoryItemDTO struct {
GatewayStatus string `json:"gatewayStatus"` GatewayStatus string `json:"gatewayStatus"`
GatewayReference *string `json:"gatewayReference,omitempty"` GatewayReference *string `json:"gatewayReference,omitempty"`
// ApiClient is the branch's GBÜS merchant username for this order type // 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 - // (visa/master or sber), ApiClientName the branch setting it comes from
// both as visamasterpay's Pay picks them. // (billing_visa_master_username or billing_sber_username), and
ApiClient string `json:"apiClient"` // Description the text sent with register.do - all as visamasterpay's
Description string `json:"description"` // Pay picks them.
ApiClient string `json:"apiClient"`
ApiClientName string `json:"apiClientName"`
Description string `json:"description"`
// CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended // CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended
// cardAuthInfo, so they're only known once an attempt has been // cardAuthInfo, so they're only known once an attempt has been
// finalized by the callback/status check (unset while pending, and for // finalized by the callback/status check (unset while pending, and for
// attempts that never reached the card form). // attempts that never reached the card form).
CardholderName *string `json:"cardholderName,omitempty"` CardholderName *string `json:"cardholderName,omitempty"`
MaskedPan *string `json:"maskedPan,omitempty"` MaskedPan *string `json:"maskedPan,omitempty"`
// FormUrl/SuccessUrl are only set while the attempt is still pending // FormUrl is GBÜS's hosted payment page and SuccessUrl the returnUrl it
// (awaiting the customer to finish paying on GBÜS's hosted page) - once // was registered with - set for every attempt register.do accepted,
// an attempt is finalized (success/failed), gateway_response no longer // finalized ones included (unset if registration failed).
// holds a formUrl, so there's nothing left to resume. FormUrl *string `json:"formUrl,omitempty"`
FormUrl *string `json:"formUrl,omitempty"` SuccessUrl *string `json:"successUrl,omitempty"`
SuccessUrl *string `json:"successUrl,omitempty"` // CallbackStatus is CallbackReceived once GBÜS's redirect reached the
CreatedById *int64 `json:"createdById,omitempty"` // callback for this attempt, at CallbackAt (its first time); both are
CreatedByName string `json:"createdByName,omitempty"` // unset if it never did (e.g. finalized by a /status check instead).
CreatedAt time.Time `json:"createdAt"` CallbackStatus *string `json:"callbackStatus,omitempty"`
UpdatedAt time.Time `json:"updatedAt"` 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 // PaymentHistoryDetailDTO is a single payout attempt with the raw GBÜS
// response kept alongside it - the list deliberately leaves the jsonb out // response kept alongside it - the list deliberately leaves the jsonb out
// so pages stay small. // so pages stay small.
@@ -75,6 +86,50 @@ type PaymentHistoryDetailDTO struct {
GatewayResponse json.RawMessage `json:"gatewayResponse,omitempty" swaggertype:"object"` GatewayResponse json.RawMessage `json:"gatewayResponse,omitempty" swaggertype:"object"`
} }
// PaymentGatewayDTO is one payment the way the per-order payment table
// shows it (paid or not, from which card, when, for which month) together
// with the last GBÜS (HALKBANK) response stored for it. Card fields are
// null until GBÜS reports cardAuthInfo; gatewayResponse is null if GBÜS
// never answered.
type PaymentGatewayDTO struct {
Id int64 `json:"id"`
OrderId int64 `json:"orderId"`
CardholderName *string `json:"cardholderName"`
MaskedPan *string `json:"maskedPan"`
PaymentYear int `json:"paymentYear"`
PaymentMonth int `json:"paymentMonth"`
CreatedAt time.Time `json:"createdAt"`
AmountUsd float64 `json:"amountUsd"`
AmountTmt float64 `json:"amountTmt"`
OrderNumber string `json:"orderNumber"`
Paid bool `json:"paid"`
GatewayStatus string `json:"gatewayStatus"`
GatewayResponse json.RawMessage `json:"gatewayResponse" swaggertype:"object"`
}
// NewPaymentGatewayDTO trims a payment detail down to PaymentGatewayDTO.
func NewPaymentGatewayDTO(detail PaymentHistoryDetailDTO) PaymentGatewayDTO {
gatewayResponse := detail.GatewayResponse
if len(gatewayResponse) == 0 {
gatewayResponse = json.RawMessage("null")
}
return PaymentGatewayDTO{
Id: detail.Id,
OrderId: detail.OrderId,
CardholderName: detail.CardholderName,
MaskedPan: detail.MaskedPan,
PaymentYear: detail.PaymentPeriod.Year(),
PaymentMonth: int(detail.PaymentPeriod.Month()),
CreatedAt: detail.CreatedAt,
AmountUsd: detail.AmountUsd,
AmountTmt: detail.AmountTmt,
OrderNumber: detail.OrderNumber,
Paid: detail.Paid,
GatewayStatus: detail.GatewayStatus,
GatewayResponse: gatewayResponse,
}
}
// ListFilter narrows the history list. BranchIds is populated by // ListFilter narrows the history list. BranchIds is populated by
// rbac.BindBranchIDs and takes priority over BranchId when set (see // rbac.BindBranchIDs and takes priority over BranchId when set (see
// rbac.AppendBranchIDs), the same way visamaster.ListFilter works. // rbac.AppendBranchIDs), the same way visamaster.ListFilter works.
+37 -6
View File
@@ -31,6 +31,7 @@ func (h *handler) Register(router *gin.RouterGroup) {
group := rbac.Group(router, baseURL, rbac.RequireStaff(perm.Cards)) group := rbac.Group(router, baseURL, rbac.RequireStaff(perm.Cards))
group.GET("", h.list) group.GET("", h.list)
group.GET("/payments/:id", h.get) group.GET("/payments/:id", h.get)
group.GET("/payments/:id/gateway", h.gateway)
group.GET("/:id", h.orderPayments) group.GET("/:id", h.orderPayments)
group.GET("/:id/logs", h.logs) group.GET("/:id/logs", h.logs)
} }
@@ -85,28 +86,58 @@ func (h *handler) list(c *gin.Context) {
// @Failure 500 {object} appresult.AppError // @Failure 500 {object} appresult.AppError
// @Router /payment-history/payments/{id} [get] // @Router /payment-history/payments/{id} [get]
func (h *handler) get(c *gin.Context) { func (h *handler) get(c *gin.Context) {
result, ok := h.loadPayment(c)
if !ok {
return
}
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
}
// gateway godoc
// @Summary Get a payment with its HALKBANK response
// @Description Returns one payment the way the per-order payment table shows it - paid or not, the card it was paid from (cardholderName/maskedPan, null until GBÜS reports them), its time (createdAt), payment year/month, amounts and reference (orderNumber) - together with the last GBÜS (HALKBANK) response stored for it (gatewayResponse, null if GBÜS never answered). Backs the table's storage icon.
// @Tags payment-history
// @Produce json
// @Security BearerAuth
// @Param id path int true "Payment ID"
// @Success 200 {object} PaymentGatewayDTO
// @Failure 400 {object} appresult.AppError
// @Failure 403 {object} appresult.AppError
// @Failure 404 {object} appresult.AppError
// @Failure 500 {object} appresult.AppError
// @Router /payment-history/payments/{id}/gateway [get]
func (h *handler) gateway(c *gin.Context) {
result, ok := h.loadPayment(c)
if !ok {
return
}
c.JSON(http.StatusOK, appresult.SuccessWithData(NewPaymentGatewayDTO(result)))
}
// loadPayment loads the :id payment and runs the order guard on it,
// answering the request itself when that fails.
func (h *handler) loadPayment(c *gin.Context) (PaymentHistoryDetailDTO, bool) {
paymentID, ok := shared.ParseID(c.Param("id")) paymentID, ok := shared.ParseID(c.Param("id"))
if !ok { if !ok {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam) c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return return PaymentHistoryDetailDTO{}, false
} }
result, err := h.repository.Get(c.Request.Context(), paymentID) result, err := h.repository.Get(c.Request.Context(), paymentID)
if errors.Is(err, pgx.ErrNoRows) { if errors.Is(err, pgx.ErrNoRows) {
c.JSON(http.StatusNotFound, appresult.ErrNotFound) c.JSON(http.StatusNotFound, appresult.ErrNotFound)
return return PaymentHistoryDetailDTO{}, false
} }
if err != nil { if err != nil {
h.logger.Errorf("get payment history failed (payment %d): %v", paymentID, err) h.logger.Errorf("get payment history failed (payment %d): %v", paymentID, err)
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return return PaymentHistoryDetailDTO{}, false
} }
if !h.guardOrder(c, result.OrderId) { if !h.guardOrder(c, result.OrderId) {
return return PaymentHistoryDetailDTO{}, false
} }
return result, true
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
} }
// orderPayments godoc // orderPayments godoc
@@ -0,0 +1,115 @@
package paymenthistory
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
"online-back/internal/identity/rbac"
"online-back/pkg/logging"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v4"
)
type fakeRepository struct {
Repository
payments map[int64]PaymentHistoryDetailDTO
}
func (f fakeRepository) Get(_ context.Context, paymentID int64) (PaymentHistoryDetailDTO, error) {
p, ok := f.payments[paymentID]
if !ok {
return PaymentHistoryDetailDTO{}, pgx.ErrNoRows
}
return p, nil
}
func strPtr(s string) *string { return &s }
func gatewayRequest(t *testing.T, repo Repository, path string) *httptest.ResponseRecorder {
t.Helper()
gin.SetMode(gin.TestMode)
// Register's rbac.Group also demands a signed JWT; mount the handler
// directly behind an all-scope principal instead.
h := &handler{logger: logging.GetLogger(), repository: repo}
router := gin.New()
router.Use(func(c *gin.Context) {
c.Set("rbacPrincipal", &rbac.Principal{UserID: 1, Scope: rbac.ScopeAll})
})
router.GET("/payment-history/payments/:id/gateway", h.gateway)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/payment-history/payments/"+path, nil))
return rec
}
func TestGatewayReturnsTableRowWithHalkbankJSON(t *testing.T) {
created := time.Date(2026, 10, 22, 8, 19, 57, 0, time.UTC)
paid := PaymentHistoryDetailDTO{
PaymentHistoryItemDTO: PaymentHistoryItemDTO{
Id: 2922, OrderId: 9437, OrderNumber: "221026131957",
CardholderName: strPtr("Amanowa guljemal"), MaskedPan: strPtr("993404**2453"),
PaymentPeriod: time.Date(2026, 10, 31, 0, 0, 0, 0, time.UTC), CreatedAt: created,
AmountUsd: 250, AmountTmt: 1063.44, Paid: true, GatewayStatus: "success",
Description: "Visa/Master tölegi",
},
GatewayResponse: json.RawMessage(`{"orderStatus":2,"actionCode":0}`),
}
repo := fakeRepository{payments: map[int64]PaymentHistoryDetailDTO{2922: paid}}
rec := gatewayRequest(t, repo, "2922/gateway")
if rec.Code != http.StatusOK {
t.Fatalf("got %d %s", rec.Code, rec.Body.String())
}
var body struct {
Data map[string]json.RawMessage `json:"data"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatal(err)
}
want := map[string]string{
"id": `2922`, "orderId": `9437`, "cardholderName": `"Amanowa guljemal"`, "maskedPan": `"993404**2453"`,
"paymentYear": `2026`, "paymentMonth": `10`, "createdAt": `"2026-10-22T08:19:57Z"`,
"amountUsd": `250`, "amountTmt": `1063.44`, "orderNumber": `"221026131957"`,
"paid": `true`, "gatewayStatus": `"success"`, "gatewayResponse": `{"orderStatus":2,"actionCode":0}`,
}
if len(body.Data) != len(want) {
t.Errorf("got fields %v, want exactly %d", body.Data, len(want))
}
for key, value := range want {
if got := string(body.Data[key]); got != value {
t.Errorf("%s: got %s, want %s", key, got, value)
}
}
}
func TestGatewayNullsWhenHalkbankNeverAnswered(t *testing.T) {
repo := fakeRepository{payments: map[int64]PaymentHistoryDetailDTO{
7: {PaymentHistoryItemDTO: PaymentHistoryItemDTO{Id: 7, GatewayStatus: "failed"}},
}}
rec := gatewayRequest(t, repo, "7/gateway")
var body struct {
Data map[string]json.RawMessage `json:"data"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatal(err)
}
for _, key := range []string{"cardholderName", "maskedPan", "gatewayResponse"} {
if got := string(body.Data[key]); got != "null" {
t.Errorf("%s: got %q, want null", key, got)
}
}
}
func TestGatewayErrors(t *testing.T) {
repo := fakeRepository{payments: map[int64]PaymentHistoryDetailDTO{}}
for path, want := range map[string]int{"abc/gateway": http.StatusBadRequest, "999/gateway": http.StatusNotFound} {
if rec := gatewayRequest(t, repo, path); rec.Code != want {
t.Errorf("%s: got %d, want %d", path, rec.Code, want)
}
}
}