Compare commits
8 Commits
payment-hi
...
api-lang-l
| Author | SHA1 | Date | |
|---|---|---|---|
| 72a5ac52b0 | |||
| c6540a658b | |||
| f067872cd7 | |||
| 6dd6110914 | |||
| a3cbb52f4b | |||
| ef3a1baee2 | |||
| ae6bf0b7e3 | |||
| c209f338c2 |
4
app.go
4
app.go
@@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
// @title Service APIs
|
// @title Service APIs
|
||||||
// @version 1.0
|
// @version 1.0
|
||||||
// @description Online payment system admin API.
|
// @description Online payment system admin API. Localized fields ({en, ru, tm} objects) come back as a plain string in the language of the `lang` query parameter: tm, ru or en (default tm), falling back to tm, ru, en when that translation is empty. lang=all returns the full {en, ru, tm} objects (for edit forms); any other value is 400.
|
||||||
// @host localhost:5005
|
// @host localhost:5005
|
||||||
// @BasePath /api/admin
|
// @BasePath /api/admin
|
||||||
// @securityDefinitions.apikey BearerAuth
|
// @securityDefinitions.apikey BearerAuth
|
||||||
@@ -62,7 +62,7 @@ func main() {
|
|||||||
|
|
||||||
docs.SwaggerInfo.Title = "Service APIs"
|
docs.SwaggerInfo.Title = "Service APIs"
|
||||||
docs.SwaggerInfo.Version = "1.0"
|
docs.SwaggerInfo.Version = "1.0"
|
||||||
docs.SwaggerInfo.Description = "Online payment system admin API."
|
docs.SwaggerInfo.Description = "Online payment system admin API. Localized fields ({en, ru, tm} objects) come back as a plain string in the language of the `lang` query parameter: tm, ru or en (default tm), falling back to tm, ru, en when that translation is empty. lang=all returns the full {en, ru, tm} objects (for edit forms); any other value is 400."
|
||||||
docs.SwaggerInfo.Host = "localhost:" + cfg.Listen.Port
|
docs.SwaggerInfo.Host = "localhost:" + cfg.Listen.Port
|
||||||
docs.SwaggerInfo.BasePath = "/api/admin"
|
docs.SwaggerInfo.BasePath = "/api/admin"
|
||||||
docs.SwaggerInfo.Schemes = []string{"http"}
|
docs.SwaggerInfo.Schemes = []string{"http"}
|
||||||
|
|||||||
@@ -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);
|
||||||
312
docs/docs.go
312
docs/docs.go
@@ -5430,6 +5430,67 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/payment-history/payments/{id}/gateway": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns every payment of one order, newest first, the way the per-order payment table shows them - 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) - each 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": "List an order's payments with their HALKBANK responses",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$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": [
|
||||||
@@ -5437,7 +5498,129 @@ const docTemplate = `{
|
|||||||
"BearerAuth": []
|
"BearerAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Returns the full step-by-step audit trail (visa_master_payment_logs) recorded while processing an order's payout - evidence of what actually happened, independent of the summary rows returned by the list endpoint",
|
"description": "Returns every visa/master/sber payout attempt of one order, newest first - one row per payment with whether it was paid (paid/gatewayStatus), the card it was paid from (cardholderName/maskedPan, once GBÜS reports them), its time (createdAt) and period (paymentPeriod). The raw GBÜS response of a row is at /payment-history/payments/{id}, of every row at once at /payment-history/{id}/gateway; the step-by-step logs are at /payment-history/{id}/logs.",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-history"
|
||||||
|
],
|
||||||
|
"summary": "List an order's payments",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/paymenthistory.PaymentHistoryItemDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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}/gateway": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns every payment of one order, newest first, the way the per-order payment table shows them - 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) - each 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": "List an order's payments with their HALKBANK responses",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$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}/logs": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns the full step-by-step audit trail (visa_master_payment_logs) recorded while processing an order's payout, newest first - evidence of what actually happened, independent of the summary rows returned by /payment-history/{id}",
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -5458,7 +5641,10 @@ const docTemplate = `{
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/appresult.AppSuccess"
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/paymenthistory.PaymentLogDTO"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
@@ -8154,7 +8340,7 @@ const docTemplate = `{
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"address": {
|
"address": {
|
||||||
"$ref": "#/definitions/branches.LocalizedText"
|
"$ref": "#/definitions/shared.LocalizedText"
|
||||||
},
|
},
|
||||||
"billingPassword": {
|
"billingPassword": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -8181,7 +8367,7 @@ const docTemplate = `{
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"$ref": "#/definitions/branches.LocalizedText"
|
"$ref": "#/definitions/shared.LocalizedText"
|
||||||
},
|
},
|
||||||
"phoneNumbers": {
|
"phoneNumbers": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -8197,20 +8383,6 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"branches.LocalizedText": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"en": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"ru": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"tm": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"branches.UpdateBranchDTO": {
|
"branches.UpdateBranchDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
@@ -8223,7 +8395,7 @@ const docTemplate = `{
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"address": {
|
"address": {
|
||||||
"$ref": "#/definitions/branches.LocalizedText"
|
"$ref": "#/definitions/shared.LocalizedText"
|
||||||
},
|
},
|
||||||
"billingPassword": {
|
"billingPassword": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -8250,7 +8422,7 @@ const docTemplate = `{
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"$ref": "#/definitions/branches.LocalizedText"
|
"$ref": "#/definitions/shared.LocalizedText"
|
||||||
},
|
},
|
||||||
"phoneNumbers": {
|
"phoneNumbers": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -9864,6 +10036,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": {
|
||||||
@@ -9879,7 +10095,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": {
|
||||||
@@ -9891,6 +10110,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"
|
||||||
@@ -9914,7 +10140,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": {
|
||||||
@@ -9994,7 +10220,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": {
|
||||||
@@ -10006,6 +10235,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"
|
||||||
@@ -10029,7 +10265,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": {
|
||||||
@@ -10091,6 +10327,32 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"paymenthistory.PaymentLogDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdById": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"createdByName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"detail": {
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"orderId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"step": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"paymentsettings.PaymentSettingsDTO": {
|
"paymentsettings.PaymentSettingsDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -11005,7 +11267,7 @@ var SwaggerInfo = &swag.Spec{
|
|||||||
BasePath: "/api/admin",
|
BasePath: "/api/admin",
|
||||||
Schemes: []string{},
|
Schemes: []string{},
|
||||||
Title: "Service APIs",
|
Title: "Service APIs",
|
||||||
Description: "Online payment system admin API.",
|
Description: "Online payment system admin API. Localized fields ({en, ru, tm} objects) come back as a plain string in the language of the `lang` query parameter: tm, ru or en (default tm), falling back to tm, ru, en when that translation is empty. lang=all returns the full {en, ru, tm} objects (for edit forms); any other value is 400.",
|
||||||
InfoInstanceName: "swagger",
|
InfoInstanceName: "swagger",
|
||||||
SwaggerTemplate: docTemplate,
|
SwaggerTemplate: docTemplate,
|
||||||
LeftDelim: "{{",
|
LeftDelim: "{{",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"swagger": "2.0",
|
"swagger": "2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"description": "Online payment system admin API.",
|
"description": "Online payment system admin API. Localized fields ({en, ru, tm} objects) come back as a plain string in the language of the `lang` query parameter: tm, ru or en (default tm), falling back to tm, ru, en when that translation is empty. lang=all returns the full {en, ru, tm} objects (for edit forms); any other value is 400.",
|
||||||
"title": "Service APIs",
|
"title": "Service APIs",
|
||||||
"contact": {},
|
"contact": {},
|
||||||
"version": "1.0"
|
"version": "1.0"
|
||||||
@@ -5424,6 +5424,67 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/payment-history/payments/{id}/gateway": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns every payment of one order, newest first, the way the per-order payment table shows them - 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) - each 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": "List an order's payments with their HALKBANK responses",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$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": [
|
||||||
@@ -5431,7 +5492,129 @@
|
|||||||
"BearerAuth": []
|
"BearerAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Returns the full step-by-step audit trail (visa_master_payment_logs) recorded while processing an order's payout - evidence of what actually happened, independent of the summary rows returned by the list endpoint",
|
"description": "Returns every visa/master/sber payout attempt of one order, newest first - one row per payment with whether it was paid (paid/gatewayStatus), the card it was paid from (cardholderName/maskedPan, once GBÜS reports them), its time (createdAt) and period (paymentPeriod). The raw GBÜS response of a row is at /payment-history/payments/{id}, of every row at once at /payment-history/{id}/gateway; the step-by-step logs are at /payment-history/{id}/logs.",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-history"
|
||||||
|
],
|
||||||
|
"summary": "List an order's payments",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/paymenthistory.PaymentHistoryItemDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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}/gateway": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns every payment of one order, newest first, the way the per-order payment table shows them - 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) - each 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": "List an order's payments with their HALKBANK responses",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$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}/logs": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns the full step-by-step audit trail (visa_master_payment_logs) recorded while processing an order's payout, newest first - evidence of what actually happened, independent of the summary rows returned by /payment-history/{id}",
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -5452,7 +5635,10 @@
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/appresult.AppSuccess"
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/paymenthistory.PaymentLogDTO"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
@@ -8148,7 +8334,7 @@
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"address": {
|
"address": {
|
||||||
"$ref": "#/definitions/branches.LocalizedText"
|
"$ref": "#/definitions/shared.LocalizedText"
|
||||||
},
|
},
|
||||||
"billingPassword": {
|
"billingPassword": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -8175,7 +8361,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"$ref": "#/definitions/branches.LocalizedText"
|
"$ref": "#/definitions/shared.LocalizedText"
|
||||||
},
|
},
|
||||||
"phoneNumbers": {
|
"phoneNumbers": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -8191,20 +8377,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"branches.LocalizedText": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"en": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"ru": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"tm": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"branches.UpdateBranchDTO": {
|
"branches.UpdateBranchDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
@@ -8217,7 +8389,7 @@
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"address": {
|
"address": {
|
||||||
"$ref": "#/definitions/branches.LocalizedText"
|
"$ref": "#/definitions/shared.LocalizedText"
|
||||||
},
|
},
|
||||||
"billingPassword": {
|
"billingPassword": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -8244,7 +8416,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"$ref": "#/definitions/branches.LocalizedText"
|
"$ref": "#/definitions/shared.LocalizedText"
|
||||||
},
|
},
|
||||||
"phoneNumbers": {
|
"phoneNumbers": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -9858,6 +10030,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": {
|
||||||
@@ -9873,7 +10089,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": {
|
||||||
@@ -9885,6 +10104,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"
|
||||||
@@ -9908,7 +10134,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": {
|
||||||
@@ -9988,7 +10214,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": {
|
||||||
@@ -10000,6 +10229,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"
|
||||||
@@ -10023,7 +10259,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": {
|
||||||
@@ -10085,6 +10321,32 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"paymenthistory.PaymentLogDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdById": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"createdByName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"detail": {
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"orderId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"step": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"paymentsettings.PaymentSettingsDTO": {
|
"paymentsettings.PaymentSettingsDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ definitions:
|
|||||||
active:
|
active:
|
||||||
type: boolean
|
type: boolean
|
||||||
address:
|
address:
|
||||||
$ref: '#/definitions/branches.LocalizedText'
|
$ref: '#/definitions/shared.LocalizedText'
|
||||||
billingPassword:
|
billingPassword:
|
||||||
type: string
|
type: string
|
||||||
billingSberPassword:
|
billingSberPassword:
|
||||||
@@ -130,7 +130,7 @@ definitions:
|
|||||||
billingVisaMasterUsername:
|
billingVisaMasterUsername:
|
||||||
type: string
|
type: string
|
||||||
name:
|
name:
|
||||||
$ref: '#/definitions/branches.LocalizedText'
|
$ref: '#/definitions/shared.LocalizedText'
|
||||||
phoneNumbers:
|
phoneNumbers:
|
||||||
type: string
|
type: string
|
||||||
provinceId:
|
provinceId:
|
||||||
@@ -145,21 +145,12 @@ definitions:
|
|||||||
- region
|
- region
|
||||||
- uniqueCode
|
- uniqueCode
|
||||||
type: object
|
type: object
|
||||||
branches.LocalizedText:
|
|
||||||
properties:
|
|
||||||
en:
|
|
||||||
type: string
|
|
||||||
ru:
|
|
||||||
type: string
|
|
||||||
tm:
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
branches.UpdateBranchDTO:
|
branches.UpdateBranchDTO:
|
||||||
properties:
|
properties:
|
||||||
active:
|
active:
|
||||||
type: boolean
|
type: boolean
|
||||||
address:
|
address:
|
||||||
$ref: '#/definitions/branches.LocalizedText'
|
$ref: '#/definitions/shared.LocalizedText'
|
||||||
billingPassword:
|
billingPassword:
|
||||||
type: string
|
type: string
|
||||||
billingSberPassword:
|
billingSberPassword:
|
||||||
@@ -177,7 +168,7 @@ definitions:
|
|||||||
billingVisaMasterUsername:
|
billingVisaMasterUsername:
|
||||||
type: string
|
type: string
|
||||||
name:
|
name:
|
||||||
$ref: '#/definitions/branches.LocalizedText'
|
$ref: '#/definitions/shared.LocalizedText'
|
||||||
phoneNumbers:
|
phoneNumbers:
|
||||||
type: string
|
type: string
|
||||||
provinceId:
|
provinceId:
|
||||||
@@ -1304,6 +1295,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 +1339,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 +1352,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 +1381,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 +1441,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 +1454,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 +1483,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
|
||||||
@@ -1484,6 +1526,23 @@ definitions:
|
|||||||
userId:
|
userId:
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
paymenthistory.PaymentLogDTO:
|
||||||
|
properties:
|
||||||
|
createdAt:
|
||||||
|
type: string
|
||||||
|
createdById:
|
||||||
|
type: integer
|
||||||
|
createdByName:
|
||||||
|
type: string
|
||||||
|
detail:
|
||||||
|
type: object
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
orderId:
|
||||||
|
type: integer
|
||||||
|
step:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
paymentsettings.PaymentSettingsDTO:
|
paymentsettings.PaymentSettingsDTO:
|
||||||
properties:
|
properties:
|
||||||
bankFeeTmt:
|
bankFeeTmt:
|
||||||
@@ -2100,7 +2159,11 @@ definitions:
|
|||||||
host: localhost:5005
|
host: localhost:5005
|
||||||
info:
|
info:
|
||||||
contact: {}
|
contact: {}
|
||||||
description: Online payment system admin API.
|
description: 'Online payment system admin API. Localized fields ({en, ru, tm} objects)
|
||||||
|
come back as a plain string in the language of the `lang` query parameter: tm,
|
||||||
|
ru or en (default tm), falling back to tm, ru, en when that translation is empty.
|
||||||
|
lang=all returns the full {en, ru, tm} objects (for edit forms); any other value
|
||||||
|
is 400.'
|
||||||
title: Service APIs
|
title: Service APIs
|
||||||
version: "1.0"
|
version: "1.0"
|
||||||
paths:
|
paths:
|
||||||
@@ -5563,9 +5626,12 @@ paths:
|
|||||||
- payment-history
|
- payment-history
|
||||||
/payment-history/{id}:
|
/payment-history/{id}:
|
||||||
get:
|
get:
|
||||||
description: Returns the full step-by-step audit trail (visa_master_payment_logs)
|
description: Returns every visa/master/sber payout attempt of one order, newest
|
||||||
recorded while processing an order's payout - evidence of what actually happened,
|
first - one row per payment with whether it was paid (paid/gatewayStatus),
|
||||||
independent of the summary rows returned by the list endpoint
|
the card it was paid from (cardholderName/maskedPan, once GBÜS reports them),
|
||||||
|
its time (createdAt) and period (paymentPeriod). The raw GBÜS response of
|
||||||
|
a row is at /payment-history/payments/{id}, of every row at once at /payment-history/{id}/gateway;
|
||||||
|
the step-by-step logs are at /payment-history/{id}/logs.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Order ID
|
- description: Order ID
|
||||||
in: path
|
in: path
|
||||||
@@ -5578,7 +5644,94 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/appresult.AppSuccess'
|
items:
|
||||||
|
$ref: '#/definitions/paymenthistory.PaymentHistoryItemDTO'
|
||||||
|
type: array
|
||||||
|
"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: List an order's payments
|
||||||
|
tags:
|
||||||
|
- payment-history
|
||||||
|
/payment-history/{id}/gateway:
|
||||||
|
get:
|
||||||
|
description: Returns every payment of one order, newest first, the way the per-order
|
||||||
|
payment table shows them - 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) - each 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: Order ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/paymenthistory.PaymentGatewayDTO'
|
||||||
|
type: array
|
||||||
|
"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: List an order's payments with their HALKBANK responses
|
||||||
|
tags:
|
||||||
|
- payment-history
|
||||||
|
/payment-history/{id}/logs:
|
||||||
|
get:
|
||||||
|
description: Returns the full step-by-step audit trail (visa_master_payment_logs)
|
||||||
|
recorded while processing an order's payout, newest first - evidence of what
|
||||||
|
actually happened, independent of the summary rows returned by /payment-history/{id}
|
||||||
|
parameters:
|
||||||
|
- description: Order ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/paymenthistory.PaymentLogDTO'
|
||||||
|
type: array
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
schema:
|
schema:
|
||||||
@@ -5639,6 +5792,50 @@ 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 every payment of one order, newest first, the way the per-order
|
||||||
|
payment table shows them - 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) - each 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: Order ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/paymenthistory.PaymentGatewayDTO'
|
||||||
|
type: array
|
||||||
|
"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: List an order's payments with their HALKBANK responses
|
||||||
|
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
|
||||||
|
|||||||
230
internal/appresult/lang.go
Normal file
230
internal/appresult/lang.go
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
package appresult
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DefaultLang is the language localized fields collapse to when the caller
|
||||||
|
// passes no ?lang=.
|
||||||
|
const DefaultLang = "tm"
|
||||||
|
|
||||||
|
// LangAll keeps every localized field as its full {en, ru, tm} object - what
|
||||||
|
// admin edit forms need to fill all three inputs.
|
||||||
|
const LangAll = "all"
|
||||||
|
|
||||||
|
// langFallback is the order empty translations are filled from.
|
||||||
|
var langFallback = []string{"tm", "ru", "en"}
|
||||||
|
|
||||||
|
// Localize collapses every {"en", "ru", "tm"} object (shared.LocalizedText)
|
||||||
|
// in a JSON response into the plain string for ?lang= (tm, ru or en;
|
||||||
|
// default tm), so clients only download the language they show. ?lang=all
|
||||||
|
// leaves responses untouched. It rewrites the encoded body rather than the
|
||||||
|
// DTOs, so every module gets it without knowing about it; non-JSON
|
||||||
|
// responses (files, images) are streamed through as-is.
|
||||||
|
func Localize() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
lang := strings.ToLower(strings.TrimSpace(c.Query("lang")))
|
||||||
|
switch lang {
|
||||||
|
case "":
|
||||||
|
lang = DefaultLang
|
||||||
|
case "tm", "ru", "en":
|
||||||
|
case LangAll:
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, ErrMissingParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w := &localizeWriter{ResponseWriter: c.Writer}
|
||||||
|
c.Writer = w
|
||||||
|
c.Next()
|
||||||
|
c.Writer = w.ResponseWriter
|
||||||
|
w.flush(lang)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// localizeWriter buffers JSON bodies until the handler is done, so they can
|
||||||
|
// be rewritten as a whole; anything else goes straight to the client.
|
||||||
|
type localizeWriter struct {
|
||||||
|
gin.ResponseWriter
|
||||||
|
decided bool
|
||||||
|
buffer bool
|
||||||
|
body bytes.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *localizeWriter) Write(data []byte) (int, error) {
|
||||||
|
if !w.decided {
|
||||||
|
w.decided = true
|
||||||
|
w.buffer = strings.HasPrefix(w.Header().Get("Content-Type"), "application/json")
|
||||||
|
}
|
||||||
|
if !w.buffer {
|
||||||
|
return w.ResponseWriter.Write(data)
|
||||||
|
}
|
||||||
|
return w.body.Write(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *localizeWriter) WriteString(s string) (int, error) {
|
||||||
|
return w.Write([]byte(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *localizeWriter) flush(lang string) {
|
||||||
|
if w.body.Len() == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
out, err := localizeJSON(w.body.Bytes(), lang)
|
||||||
|
if err != nil {
|
||||||
|
out = w.body.Bytes()
|
||||||
|
}
|
||||||
|
w.ResponseWriter.Write(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// localizeJSON re-encodes data token by token - keeping key order and
|
||||||
|
// number precision - with localized objects replaced by their lang string.
|
||||||
|
func localizeJSON(data []byte, lang string) ([]byte, error) {
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(data))
|
||||||
|
dec.UseNumber()
|
||||||
|
var out bytes.Buffer
|
||||||
|
if err := localizeValue(dec, &out, lang); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func localizeValue(dec *json.Decoder, out *bytes.Buffer, lang string) error {
|
||||||
|
tok, err := dec.Token()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch t := tok.(type) {
|
||||||
|
case json.Delim:
|
||||||
|
if t == '[' {
|
||||||
|
return localizeArray(dec, out, lang)
|
||||||
|
}
|
||||||
|
return localizeObject(dec, out, lang)
|
||||||
|
case string:
|
||||||
|
return writeString(out, t)
|
||||||
|
case json.Number:
|
||||||
|
out.WriteString(t.String())
|
||||||
|
case bool:
|
||||||
|
if t {
|
||||||
|
out.WriteString("true")
|
||||||
|
} else {
|
||||||
|
out.WriteString("false")
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
out.WriteString("null")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func localizeArray(dec *json.Decoder, out *bytes.Buffer, lang string) error {
|
||||||
|
out.WriteByte('[')
|
||||||
|
for i := 0; dec.More(); i++ {
|
||||||
|
if i > 0 {
|
||||||
|
out.WriteByte(',')
|
||||||
|
}
|
||||||
|
if err := localizeValue(dec, out, lang); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := dec.Token(); err != nil { // ']'
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.WriteByte(']')
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonField struct {
|
||||||
|
key string
|
||||||
|
value []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func localizeObject(dec *json.Decoder, out *bytes.Buffer, lang string) error {
|
||||||
|
var fields []jsonField
|
||||||
|
for dec.More() {
|
||||||
|
keyTok, err := dec.Token()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var value bytes.Buffer
|
||||||
|
if err := localizeValue(dec, &value, lang); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fields = append(fields, jsonField{key: keyTok.(string), value: value.Bytes()})
|
||||||
|
}
|
||||||
|
if _, err := dec.Token(); err != nil { // '}'
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if text, ok := pickLocalized(fields, lang); ok {
|
||||||
|
return writeString(out, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
out.WriteByte('{')
|
||||||
|
for i, f := range fields {
|
||||||
|
if i > 0 {
|
||||||
|
out.WriteByte(',')
|
||||||
|
}
|
||||||
|
if err := writeString(out, f.key); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.WriteByte(':')
|
||||||
|
out.Write(f.value)
|
||||||
|
}
|
||||||
|
out.WriteByte('}')
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// pickLocalized reports whether fields is exactly a {en, ru, tm} object of
|
||||||
|
// strings/nulls and, if so, returns lang's text - falling back through
|
||||||
|
// langFallback when it's empty.
|
||||||
|
func pickLocalized(fields []jsonField, lang string) (string, bool) {
|
||||||
|
if len(fields) != 3 {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
texts := make(map[string]string, 3)
|
||||||
|
for _, f := range fields {
|
||||||
|
if f.key != "en" && f.key != "ru" && f.key != "tm" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
if _, dup := texts[f.key]; dup {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
var text *string
|
||||||
|
if err := json.Unmarshal(f.value, &text); err != nil {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
texts[f.key] = ""
|
||||||
|
if text != nil {
|
||||||
|
texts[f.key] = *text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if text := texts[lang]; text != "" {
|
||||||
|
return text, true
|
||||||
|
}
|
||||||
|
for _, l := range langFallback {
|
||||||
|
if text := texts[l]; text != "" {
|
||||||
|
return text, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", true
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeString encodes s the way gin's c.JSON does (json.Marshal, HTML
|
||||||
|
// escaped), so rewritten bodies match untouched ones byte for byte.
|
||||||
|
func writeString(out *bytes.Buffer, s string) error {
|
||||||
|
encoded, err := json.Marshal(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.Write(encoded)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
106
internal/appresult/lang_test.go
Normal file
106
internal/appresult/lang_test.go
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
package appresult
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func serve(t *testing.T, query string, handler gin.HandlerFunc) *httptest.ResponseRecorder {
|
||||||
|
t.Helper()
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
router := gin.New()
|
||||||
|
router.Use(Localize())
|
||||||
|
router.GET("/x", handler)
|
||||||
|
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/x"+query, nil))
|
||||||
|
return rec
|
||||||
|
}
|
||||||
|
|
||||||
|
func jsonHandler(body string) gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
c.Data(http.StatusOK, "application/json; charset=utf-8", []byte(body))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const branchBody = `{"id":1,"name":{"en":"Branch","ru":"Филиал","tm":"Şahamça"}}`
|
||||||
|
|
||||||
|
func TestLocalizeLanguages(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
query string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"", `{"id":1,"name":"Şahamça"}`},
|
||||||
|
{"?lang=tm", `{"id":1,"name":"Şahamça"}`},
|
||||||
|
{"?lang=ru", `{"id":1,"name":"Филиал"}`},
|
||||||
|
{"?lang=EN", `{"id":1,"name":"Branch"}`},
|
||||||
|
{"?lang=all", branchBody},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
rec := serve(t, tt.query, jsonHandler(branchBody))
|
||||||
|
if rec.Code != http.StatusOK || rec.Body.String() != tt.want {
|
||||||
|
t.Errorf("%q: got %d %s, want %s", tt.query, rec.Code, rec.Body.String(), tt.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocalizeRejectsUnknownLang(t *testing.T) {
|
||||||
|
called := false
|
||||||
|
rec := serve(t, "?lang=xx", func(c *gin.Context) { called = true })
|
||||||
|
if rec.Code != http.StatusBadRequest || called {
|
||||||
|
t.Fatalf("got %d (handler called: %v), want 400 without calling the handler", rec.Code, called)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocalizeFallback(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
body string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{`{"tm":"","ru":"Филиал","en":"Branch"}`, `"Филиал"`},
|
||||||
|
{`{"tm":null,"ru":"","en":"Branch"}`, `"Branch"`},
|
||||||
|
{`{"tm":"","ru":"","en":""}`, `""`},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
if got := serve(t, "", jsonHandler(tt.body)).Body.String(); got != tt.want {
|
||||||
|
t.Errorf("%s: got %s, want %s", tt.body, got, tt.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocalizeKeepsStructure(t *testing.T) {
|
||||||
|
body := `{"z":9007199254740993,"a":[{"b":{"en":"E","ru":"R","tm":"T"},"f":1.10}],` +
|
||||||
|
`"extra":{"en":"E","ru":"R","tm":"T","id":2},"partial":{"en":"E","ru":"R"},` +
|
||||||
|
`"nested":{"en":{"x":1},"ru":"R","tm":"T"},"ok":true,"none":null,"html":"<a&b>"}`
|
||||||
|
want := `{"z":9007199254740993,"a":[{"b":"T","f":1.10}],` +
|
||||||
|
`"extra":{"en":"E","ru":"R","tm":"T","id":2},"partial":{"en":"E","ru":"R"},` +
|
||||||
|
`"nested":{"en":{"x":1},"ru":"R","tm":"T"},"ok":true,"none":null,"html":` + "\"\\u003ca\\u0026b\\u003e\"}"
|
||||||
|
if got := serve(t, "", jsonHandler(body)).Body.String(); got != want {
|
||||||
|
t.Fatalf("got %s\nwant %s", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocalizeMatchesGinJSON(t *testing.T) {
|
||||||
|
rec := serve(t, "?lang=ru", func(c *gin.Context) {
|
||||||
|
c.JSON(http.StatusCreated, SuccessWithData(map[string]interface{}{
|
||||||
|
"name": map[string]string{"en": "Branch", "ru": "Филиал", "tm": "Şahamça"},
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
want := `{"status":true,"message":"Request completed successfully.","code":"SS-10000","data":{"name":"Филиал"}}`
|
||||||
|
if rec.Code != http.StatusCreated || rec.Body.String() != want {
|
||||||
|
t.Fatalf("got %d %s, want 201 %s", rec.Code, rec.Body.String(), want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocalizeSkipsNonJSON(t *testing.T) {
|
||||||
|
body := `{"en":"E","ru":"R","tm":"T"}`
|
||||||
|
rec := serve(t, "", func(c *gin.Context) {
|
||||||
|
c.Data(http.StatusOK, "text/plain", []byte(body))
|
||||||
|
})
|
||||||
|
if rec.Body.String() != body {
|
||||||
|
t.Fatalf("got %s, want body untouched", rec.Body.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"online-back/internal/analytics"
|
"online-back/internal/analytics"
|
||||||
analyticsdb "online-back/internal/analytics/db"
|
analyticsdb "online-back/internal/analytics/db"
|
||||||
|
"online-back/internal/appresult"
|
||||||
"online-back/internal/backup"
|
"online-back/internal/backup"
|
||||||
backupdb "online-back/internal/backup/db"
|
backupdb "online-back/internal/backup/db"
|
||||||
"online-back/internal/cards"
|
"online-back/internal/cards"
|
||||||
@@ -65,6 +66,8 @@ func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin.
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
adminGroup := router.Group(adminAPIPrefix)
|
adminGroup := router.Group(adminAPIPrefix)
|
||||||
|
// First, so it sees every admin response; /swagger stays outside it.
|
||||||
|
adminGroup.Use(appresult.Localize())
|
||||||
adminGroup.Use(activitylog.Record(activitylogdb.NewRepository(client, logger), logger))
|
adminGroup.Use(activitylog.Record(activitylogdb.NewRepository(client, logger), logger))
|
||||||
if err := perm.Sync(context.Background(), client); err != nil {
|
if err := perm.Sync(context.Background(), client); err != nil {
|
||||||
logger.Fatalf("rbac: sync permission catalog: %v", err)
|
logger.Fatalf("rbac: sync permission catalog: %v", err)
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"online-back/internal/shared"
|
||||||
|
)
|
||||||
|
|
||||||
type LoginDTO struct {
|
type LoginDTO struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -12,12 +16,6 @@ type RefreshTokenDTO struct {
|
|||||||
RefreshToken string `json:"refreshToken" binding:"required"`
|
RefreshToken string `json:"refreshToken" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalizedText struct {
|
|
||||||
En string `json:"en"`
|
|
||||||
Ru string `json:"ru"`
|
|
||||||
Tm string `json:"tm"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProfileRoleDTO struct {
|
type ProfileRoleDTO struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
@@ -27,9 +25,9 @@ type ProfileRoleDTO struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ProfileBranchDTO struct {
|
type ProfileBranchDTO struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
UniqueCode string `json:"uniqueCode"`
|
UniqueCode string `json:"uniqueCode"`
|
||||||
Name LocalizedText `json:"name"`
|
Name shared.LocalizedText `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProfilePermissionDTO is one module the caller can open; the front-end
|
// ProfilePermissionDTO is one module the caller can open; the front-end
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
type LocalizedText struct {
|
"online-back/internal/shared"
|
||||||
En string `json:"en"`
|
)
|
||||||
Ru string `json:"ru"`
|
|
||||||
Tm string `json:"tm"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type StaffBranchDTO struct {
|
type StaffBranchDTO struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
UniqueCode string `json:"uniqueCode"`
|
UniqueCode string `json:"uniqueCode"`
|
||||||
Name LocalizedText `json:"name"`
|
Name shared.LocalizedText `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserPermissionDTO struct {
|
type UserPermissionDTO struct {
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
package userbranch
|
package userbranch
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
type LocalizedText struct {
|
"online-back/internal/shared"
|
||||||
En string `json:"en"`
|
)
|
||||||
Ru string `json:"ru"`
|
|
||||||
Tm string `json:"tm"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserBranchDTO struct {
|
type UserBranchDTO struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
UserId int64 `json:"userId"`
|
UserId int64 `json:"userId"`
|
||||||
UserName string `json:"userName"`
|
UserName string `json:"userName"`
|
||||||
BranchId int64 `json:"branchId"`
|
BranchId int64 `json:"branchId"`
|
||||||
BranchName LocalizedText `json:"branchName"`
|
BranchName shared.LocalizedText `json:"branchName"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateUserBranchDTO struct {
|
type CreateUserBranchDTO struct {
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ func (r *repository) ensureProvince(ctx context.Context, provinceID *int64) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalBranchJSON(name, address branches.LocalizedText) ([]byte, []byte, error) {
|
func marshalBranchJSON(name, address shared.LocalizedText) ([]byte, []byte, error) {
|
||||||
nameJSON, err := json.Marshal(name)
|
nameJSON, err := json.Marshal(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|||||||
@@ -1,64 +1,60 @@
|
|||||||
package branches
|
package branches
|
||||||
|
|
||||||
type LocalizedText struct {
|
import "online-back/internal/shared"
|
||||||
En string `json:"en"`
|
|
||||||
Ru string `json:"ru"`
|
|
||||||
Tm string `json:"tm"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type BranchDTO struct {
|
type BranchDTO struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
UniqueCode string `json:"uniqueCode"`
|
UniqueCode string `json:"uniqueCode"`
|
||||||
Name LocalizedText `json:"name"`
|
Name shared.LocalizedText `json:"name"`
|
||||||
Address LocalizedText `json:"address"`
|
Address shared.LocalizedText `json:"address"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region"`
|
||||||
ProvinceId *int64 `json:"provinceId"`
|
ProvinceId *int64 `json:"provinceId"`
|
||||||
ProvinceName LocalizedText `json:"provinceName"`
|
ProvinceName shared.LocalizedText `json:"provinceName"`
|
||||||
PhoneNumbers string `json:"phoneNumbers"`
|
PhoneNumbers string `json:"phoneNumbers"`
|
||||||
BillingUsername string `json:"billingUsername"`
|
BillingUsername string `json:"billingUsername"`
|
||||||
BillingPassword string `json:"billingPassword"`
|
BillingPassword string `json:"billingPassword"`
|
||||||
BillingSberUsername string `json:"billingSberUsername"`
|
BillingSberUsername string `json:"billingSberUsername"`
|
||||||
BillingSberPassword string `json:"billingSberPassword"`
|
BillingSberPassword string `json:"billingSberPassword"`
|
||||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateBranchDTO struct {
|
type CreateBranchDTO struct {
|
||||||
UniqueCode string `json:"uniqueCode" binding:"required,numeric,len=4"`
|
UniqueCode string `json:"uniqueCode" binding:"required,numeric,len=4"`
|
||||||
Name LocalizedText `json:"name" binding:"required"`
|
Name shared.LocalizedText `json:"name" binding:"required"`
|
||||||
Address LocalizedText `json:"address" binding:"required"`
|
Address shared.LocalizedText `json:"address" binding:"required"`
|
||||||
Region string `json:"region" binding:"required"`
|
Region string `json:"region" binding:"required"`
|
||||||
ProvinceId *int64 `json:"provinceId"`
|
ProvinceId *int64 `json:"provinceId"`
|
||||||
PhoneNumbers string `json:"phoneNumbers"`
|
PhoneNumbers string `json:"phoneNumbers"`
|
||||||
BillingUsername string `json:"billingUsername"`
|
BillingUsername string `json:"billingUsername"`
|
||||||
BillingPassword string `json:"billingPassword"`
|
BillingPassword string `json:"billingPassword"`
|
||||||
BillingSberUsername string `json:"billingSberUsername"`
|
BillingSberUsername string `json:"billingSberUsername"`
|
||||||
BillingSberPassword string `json:"billingSberPassword"`
|
BillingSberPassword string `json:"billingSberPassword"`
|
||||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||||
Active *bool `json:"active"`
|
Active *bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateBranchDTO struct {
|
type UpdateBranchDTO struct {
|
||||||
Name LocalizedText `json:"name" binding:"required"`
|
Name shared.LocalizedText `json:"name" binding:"required"`
|
||||||
Address LocalizedText `json:"address" binding:"required"`
|
Address shared.LocalizedText `json:"address" binding:"required"`
|
||||||
Region string `json:"region" binding:"required"`
|
Region string `json:"region" binding:"required"`
|
||||||
ProvinceId *int64 `json:"provinceId"`
|
ProvinceId *int64 `json:"provinceId"`
|
||||||
PhoneNumbers string `json:"phoneNumbers"`
|
PhoneNumbers string `json:"phoneNumbers"`
|
||||||
BillingUsername string `json:"billingUsername"`
|
BillingUsername string `json:"billingUsername"`
|
||||||
BillingPassword string `json:"billingPassword"`
|
BillingPassword string `json:"billingPassword"`
|
||||||
BillingSberUsername string `json:"billingSberUsername"`
|
BillingSberUsername string `json:"billingSberUsername"`
|
||||||
BillingSberPassword string `json:"billingSberPassword"`
|
BillingSberPassword string `json:"billingSberPassword"`
|
||||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListFilter struct {
|
type ListFilter struct {
|
||||||
@@ -74,12 +70,12 @@ type ListFilter struct {
|
|||||||
// BranchListItemDTO is the list row; address, region and billing credentials
|
// BranchListItemDTO is the list row; address, region and billing credentials
|
||||||
// come from GET /branches/:id.
|
// come from GET /branches/:id.
|
||||||
type BranchListItemDTO struct {
|
type BranchListItemDTO struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
UniqueCode string `json:"uniqueCode"`
|
UniqueCode string `json:"uniqueCode"`
|
||||||
Name LocalizedText `json:"name"`
|
Name shared.LocalizedText `json:"name"`
|
||||||
ProvinceName LocalizedText `json:"provinceName"`
|
ProvinceName shared.LocalizedText `json:"provinceName"`
|
||||||
PhoneNumbers string `json:"phoneNumbers"`
|
PhoneNumbers string `json:"phoneNumbers"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListBranchDTO struct {
|
type ListBranchDTO struct {
|
||||||
|
|||||||
@@ -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`
|
||||||
|
|
||||||
@@ -105,6 +117,58 @@ func (r *repository) Get(ctx context.Context, paymentID int64) (paymenthistory.P
|
|||||||
return detail, nil
|
return detail, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *repository) OrderPayments(ctx context.Context, orderID int64) ([]paymenthistory.PaymentHistoryItemDTO, error) {
|
||||||
|
whereClause, args := buildListQuery(paymenthistory.ListFilter{OrderId: &orderID})
|
||||||
|
query := `SELECT ` + historySelectColumns + historyFromClause + whereClause + ` ORDER BY p.id DESC`
|
||||||
|
|
||||||
|
rows, err := r.client.Query(ctx, query, args...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
items := []paymenthistory.PaymentHistoryItemDTO{}
|
||||||
|
for rows.Next() {
|
||||||
|
item, err := r.scanHistoryItem(rows)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, item)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *repository) OrderPaymentDetails(ctx context.Context, orderID int64) ([]paymenthistory.PaymentHistoryDetailDTO, error) {
|
||||||
|
whereClause, args := buildListQuery(paymenthistory.ListFilter{OrderId: &orderID})
|
||||||
|
query := `SELECT ` + historySelectColumns + `, p.gateway_response` + historyFromClause + whereClause + ` ORDER BY p.id DESC`
|
||||||
|
|
||||||
|
rows, err := r.client.Query(ctx, query, args...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
details := []paymenthistory.PaymentHistoryDetailDTO{}
|
||||||
|
for rows.Next() {
|
||||||
|
var detail paymenthistory.PaymentHistoryDetailDTO
|
||||||
|
item, err := r.scanHistoryItem(rows, &detail.GatewayResponse)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
detail.PaymentHistoryItemDTO = item
|
||||||
|
details = append(details, detail)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return details, nil
|
||||||
|
}
|
||||||
|
|
||||||
// OwnerInfo returns orderID's owning user/branch, so the handler can run
|
// OwnerInfo returns orderID's owning user/branch, so the handler can run
|
||||||
// rbac.GuardOrder before returning its logs to a branch/own-scoped caller.
|
// rbac.GuardOrder before returning its logs to a branch/own-scoped caller.
|
||||||
func (r *repository) OwnerInfo(ctx context.Context, orderID int64) (*int64, int64, error) {
|
func (r *repository) OwnerInfo(ctx context.Context, orderID int64) (*int64, int64, error) {
|
||||||
@@ -202,7 +266,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,
|
||||||
@@ -210,8 +273,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,
|
||||||
}
|
}
|
||||||
@@ -223,13 +286,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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -112,7 +167,7 @@ type PaymentLogDTO struct {
|
|||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
OrderId int64 `json:"orderId"`
|
OrderId int64 `json:"orderId"`
|
||||||
Step string `json:"step"`
|
Step string `json:"step"`
|
||||||
Detail json.RawMessage `json:"detail,omitempty"`
|
Detail json.RawMessage `json:"detail,omitempty" swaggertype:"object"`
|
||||||
CreatedById *int64 `json:"createdById,omitempty"`
|
CreatedById *int64 `json:"createdById,omitempty"`
|
||||||
CreatedByName string `json:"createdByName,omitempty"`
|
CreatedByName string `json:"createdByName,omitempty"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
|||||||
@@ -31,7 +31,10 @@ 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("/:id", h.logs)
|
group.GET("/payments/:id/gateway", h.gateway)
|
||||||
|
group.GET("/:id/gateway", h.gateway)
|
||||||
|
group.GET("/:id", h.orderPayments)
|
||||||
|
group.GET("/:id/logs", h.logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// list godoc
|
// list godoc
|
||||||
@@ -104,23 +107,95 @@ func (h *handler) get(c *gin.Context) {
|
|||||||
if !h.guardOrder(c, result.OrderId) {
|
if !h.guardOrder(c, result.OrderId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||||
|
}
|
||||||
|
|
||||||
|
// gateway godoc
|
||||||
|
// @Summary List an order's payments with their HALKBANK responses
|
||||||
|
// @Description Returns every payment of one order, newest first, the way the per-order payment table shows them - 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) - each 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 "Order ID"
|
||||||
|
// @Success 200 {array} 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]
|
||||||
|
// @Router /payment-history/{id}/gateway [get]
|
||||||
|
func (h *handler) gateway(c *gin.Context) {
|
||||||
|
orderID, ok := shared.ParseID(c.Param("id"))
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !h.guardOrder(c, orderID) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
details, err := h.repository.OrderPaymentDetails(c.Request.Context(), orderID)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Errorf("list order payment gateway responses failed (order %d): %v", orderID, err)
|
||||||
|
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]PaymentGatewayDTO, 0, len(details))
|
||||||
|
for _, detail := range details {
|
||||||
|
result = append(result, NewPaymentGatewayDTO(detail))
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderPayments godoc
|
||||||
|
// @Summary List an order's payments
|
||||||
|
// @Description Returns every visa/master/sber payout attempt of one order, newest first - one row per payment with whether it was paid (paid/gatewayStatus), the card it was paid from (cardholderName/maskedPan, once GBÜS reports them), its time (createdAt) and period (paymentPeriod). The raw GBÜS response of a row is at /payment-history/payments/{id}, of every row at once at /payment-history/{id}/gateway; the step-by-step logs are at /payment-history/{id}/logs.
|
||||||
|
// @Tags payment-history
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param id path int true "Order ID"
|
||||||
|
// @Success 200 {array} PaymentHistoryItemDTO
|
||||||
|
// @Failure 400 {object} appresult.AppError
|
||||||
|
// @Failure 403 {object} appresult.AppError
|
||||||
|
// @Failure 404 {object} appresult.AppError
|
||||||
|
// @Failure 500 {object} appresult.AppError
|
||||||
|
// @Router /payment-history/{id} [get]
|
||||||
|
func (h *handler) orderPayments(c *gin.Context) {
|
||||||
|
orderID, ok := shared.ParseID(c.Param("id"))
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !h.guardOrder(c, orderID) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.repository.OrderPayments(c.Request.Context(), orderID)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Errorf("list order payments failed (order %d): %v", orderID, err)
|
||||||
|
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
// logs godoc
|
// logs godoc
|
||||||
// @Summary Get payment logs for an order
|
// @Summary Get payment logs for an order
|
||||||
// @Description Returns the full step-by-step audit trail (visa_master_payment_logs) recorded while processing an order's payout - evidence of what actually happened, independent of the summary rows returned by the list endpoint
|
// @Description Returns the full step-by-step audit trail (visa_master_payment_logs) recorded while processing an order's payout, newest first - evidence of what actually happened, independent of the summary rows returned by /payment-history/{id}
|
||||||
// @Tags payment-history
|
// @Tags payment-history
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Param id path int true "Order ID"
|
// @Param id path int true "Order ID"
|
||||||
// @Success 200 {object} appresult.AppSuccess
|
// @Success 200 {array} PaymentLogDTO
|
||||||
// @Failure 400 {object} appresult.AppError
|
// @Failure 400 {object} appresult.AppError
|
||||||
// @Failure 403 {object} appresult.AppError
|
// @Failure 403 {object} appresult.AppError
|
||||||
// @Failure 404 {object} appresult.AppError
|
// @Failure 404 {object} appresult.AppError
|
||||||
// @Failure 500 {object} appresult.AppError
|
// @Failure 500 {object} appresult.AppError
|
||||||
// @Router /payment-history/{id} [get]
|
// @Router /payment-history/{id}/logs [get]
|
||||||
func (h *handler) logs(c *gin.Context) {
|
func (h *handler) logs(c *gin.Context) {
|
||||||
orderID, ok := shared.ParseID(c.Param("id"))
|
orderID, ok := shared.ParseID(c.Param("id"))
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
133
internal/payment/paymenthistory/handler_test.go
Normal file
133
internal/payment/paymenthistory/handler_test.go
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
type fakeRepository struct {
|
||||||
|
Repository
|
||||||
|
orders map[int64][]PaymentHistoryDetailDTO
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f fakeRepository) OrderPaymentDetails(_ context.Context, orderID int64) ([]PaymentHistoryDetailDTO, error) {
|
||||||
|
return append([]PaymentHistoryDetailDTO{}, f.orders[orderID]...), 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 TestGatewayReturnsOrderPaymentsWithHalkbankJSON(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}`),
|
||||||
|
}
|
||||||
|
failed := PaymentHistoryDetailDTO{PaymentHistoryItemDTO: PaymentHistoryItemDTO{Id: 2921, OrderId: 9437, GatewayStatus: "failed"}}
|
||||||
|
repo := fakeRepository{orders: map[int64][]PaymentHistoryDetailDTO{9437: {paid, failed}}}
|
||||||
|
|
||||||
|
rec := gatewayRequest(t, repo, "9437/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)
|
||||||
|
}
|
||||||
|
if len(body.Data) != 2 {
|
||||||
|
t.Fatalf("got %d payments, want 2", len(body.Data))
|
||||||
|
}
|
||||||
|
if got := string(body.Data[1]["id"]); got != "2921" {
|
||||||
|
t.Errorf("second payment id: got %s, want 2921", got)
|
||||||
|
}
|
||||||
|
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[0]) != len(want) {
|
||||||
|
t.Errorf("got fields %v, want exactly %d", body.Data[0], len(want))
|
||||||
|
}
|
||||||
|
for key, value := range want {
|
||||||
|
if got := string(body.Data[0][key]); got != value {
|
||||||
|
t.Errorf("%s: got %s, want %s", key, got, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGatewayNullsWhenHalkbankNeverAnswered(t *testing.T) {
|
||||||
|
repo := fakeRepository{orders: map[int64][]PaymentHistoryDetailDTO{
|
||||||
|
3: {{PaymentHistoryItemDTO: PaymentHistoryItemDTO{Id: 7, OrderId: 3, GatewayStatus: "failed"}}},
|
||||||
|
}}
|
||||||
|
rec := gatewayRequest(t, repo, "3/gateway")
|
||||||
|
var body struct {
|
||||||
|
Data []map[string]json.RawMessage `json:"data"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(body.Data) != 1 {
|
||||||
|
t.Fatalf("got %d payments, want 1", len(body.Data))
|
||||||
|
}
|
||||||
|
for _, key := range []string{"cardholderName", "maskedPan", "gatewayResponse"} {
|
||||||
|
if got := string(body.Data[0][key]); got != "null" {
|
||||||
|
t.Errorf("%s: got %q, want null", key, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGatewayEmptyOrderAndBadID(t *testing.T) {
|
||||||
|
repo := fakeRepository{orders: map[int64][]PaymentHistoryDetailDTO{}}
|
||||||
|
|
||||||
|
rec := gatewayRequest(t, repo, "999/gateway")
|
||||||
|
if rec.Code != http.StatusOK {
|
||||||
|
t.Fatalf("got %d %s", rec.Code, rec.Body.String())
|
||||||
|
}
|
||||||
|
var body struct {
|
||||||
|
Data json.RawMessage `json:"data"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := string(body.Data); got != "[]" {
|
||||||
|
t.Errorf("data: got %s, want []", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rec := gatewayRequest(t, repo, "abc/gateway"); rec.Code != http.StatusBadRequest {
|
||||||
|
t.Errorf("abc/gateway: got %d, want %d", rec.Code, http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,12 @@ type Repository interface {
|
|||||||
List(ctx context.Context, filter ListFilter) (ListPaymentHistoryDTO, error)
|
List(ctx context.Context, filter ListFilter) (ListPaymentHistoryDTO, error)
|
||||||
// Get returns a single payout attempt by its visa_master_order_payments id.
|
// Get returns a single payout attempt by its visa_master_order_payments id.
|
||||||
Get(ctx context.Context, paymentID int64) (PaymentHistoryDetailDTO, error)
|
Get(ctx context.Context, paymentID int64) (PaymentHistoryDetailDTO, error)
|
||||||
|
// OrderPayments returns every payout attempt of a single order, newest
|
||||||
|
// first - the per-order payment table, without paging.
|
||||||
|
OrderPayments(ctx context.Context, orderID int64) ([]PaymentHistoryItemDTO, error)
|
||||||
|
// OrderPaymentDetails is OrderPayments with each attempt's raw GBÜS
|
||||||
|
// response kept alongside it.
|
||||||
|
OrderPaymentDetails(ctx context.Context, orderID int64) ([]PaymentHistoryDetailDTO, error)
|
||||||
// Logs returns the full visa_master_payment_logs audit trail for a
|
// Logs returns the full visa_master_payment_logs audit trail for a
|
||||||
// single order, newest first.
|
// single order, newest first.
|
||||||
Logs(ctx context.Context, orderID int64) ([]PaymentLogDTO, error)
|
Logs(ctx context.Context, orderID int64) ([]PaymentLogDTO, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user