ch something
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
2026-09-30 14:41:13 +05:00
parent 3b33e25703
commit 60787c8149
8 changed files with 383 additions and 23 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 KiB

View File

@@ -657,6 +657,32 @@ INSERT INTO visa_master_payment_orders (
'Atayew Kerim Begliýewiç', 'I-AG', '101010', '23202984200010101011',
'Gurbanowa Leyla Saparowna', 'I-AG', '303030', NULL,
true
),
(
'VMP-2026-0003', 'sber', 'Batyr', 'Saparow', '+993 61 92 92 48', NULL,
'AG', 1, 5, 'Aşgabat, Bitarap Türkmenistan 12',
'{"fullName":"Saparow Batyr Annaýewiç","passportSerie":"I-AG","passportNumber":"202020","depositAccount":"23202984200020202022"}'::json,
'[{"fullName":"Saparowa Aýna Batyrowna","passportSerie":"I-AG","passportNumber":"404040"}]'::json,
'{
"student_visa_card_details":["sber-card-3.pdf"],
"student_enrollment_certificate":["enrollment-3.pdf"],
"student_ticket_copy":[],
"student_internal_passport":["student-internal-3.pdf"],
"student_foreign_passport":["student-foreign-3.pdf"],
"student_visa_page":[],
"student_stamp_page":[],
"student_enrollment_clarification":[],
"sender_internal_passport":["sender-internal-3.pdf"],
"sender_foreign_passport":[],
"sender_stamp_page":[],
"kinship_documents":["kinship-3.pdf"],
"first_passport_series_info":[],
"police_passport_series_info":[]
}'::json,
'pending', 'Sber tölegi garaşylýar',
'Saparow Batyr Annaýewiç', 'I-AG', '202020', '23202984200020202022',
'Saparowa Aýna Batyrowna', 'I-AG', '404040', NULL,
false
);
-- ---------------------------------------------------------------------------

View File

@@ -6758,7 +6758,7 @@ const docTemplate = `{
"BearerAuth": []
}
],
"description": "Returns paginated visa/master payment orders with branch and user details",
"description": "Returns paginated visa/master payment orders; sber orders are excluded (see /visa-master-payment-orders/sber)",
"produces": [
"application/json"
],
@@ -6773,6 +6773,12 @@ const docTemplate = `{
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Filter by order type (e.g. student), case-insensitive",
"name": "type",
"in": "query"
},
{
"type": "string",
"description": "Filter by status",
@@ -6912,6 +6918,89 @@ const docTemplate = `{
}
}
},
"/visa-master-payment-orders/sber": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "Returns paginated payment orders of type sber",
"produces": [
"application/json"
],
"tags": [
"visa-master-payment-orders"
],
"summary": "List sber payment orders",
"parameters": [
{
"type": "string",
"description": "Filter by passport name or surname",
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Filter by status",
"name": "status",
"in": "query"
},
{
"type": "integer",
"description": "Filter by branch ID",
"name": "branch_id",
"in": "query"
},
{
"type": "integer",
"description": "Filter by user ID",
"name": "user_id",
"in": "query"
},
{
"type": "string",
"description": "Filter by region",
"name": "region",
"in": "query"
},
{
"type": "integer",
"default": 1,
"description": "Page number",
"name": "page",
"in": "query"
},
{
"type": "integer",
"default": 10,
"description": "Items per page",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/appresult.AppSuccess"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
}
}
}
},
"/visa-master-payment-orders/{id}": {
"get": {
"security": [
@@ -9177,6 +9266,9 @@ const docTemplate = `{
"orderId": {
"type": "integer"
},
"orderNumber": {
"type": "string"
},
"orderUniqueId": {
"type": "string"
},
@@ -9824,6 +9916,9 @@ const docTemplate = `{
"orderId": {
"type": "integer"
},
"orderNumber": {
"type": "string"
},
"paymentId": {
"type": "integer"
},
@@ -9900,6 +9995,9 @@ const docTemplate = `{
"orderId": {
"type": "integer"
},
"orderNumber": {
"type": "string"
},
"paid": {
"type": "boolean"
},

View File

@@ -6752,7 +6752,7 @@
"BearerAuth": []
}
],
"description": "Returns paginated visa/master payment orders with branch and user details",
"description": "Returns paginated visa/master payment orders; sber orders are excluded (see /visa-master-payment-orders/sber)",
"produces": [
"application/json"
],
@@ -6767,6 +6767,12 @@
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Filter by order type (e.g. student), case-insensitive",
"name": "type",
"in": "query"
},
{
"type": "string",
"description": "Filter by status",
@@ -6906,6 +6912,89 @@
}
}
},
"/visa-master-payment-orders/sber": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "Returns paginated payment orders of type sber",
"produces": [
"application/json"
],
"tags": [
"visa-master-payment-orders"
],
"summary": "List sber payment orders",
"parameters": [
{
"type": "string",
"description": "Filter by passport name or surname",
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Filter by status",
"name": "status",
"in": "query"
},
{
"type": "integer",
"description": "Filter by branch ID",
"name": "branch_id",
"in": "query"
},
{
"type": "integer",
"description": "Filter by user ID",
"name": "user_id",
"in": "query"
},
{
"type": "string",
"description": "Filter by region",
"name": "region",
"in": "query"
},
{
"type": "integer",
"default": 1,
"description": "Page number",
"name": "page",
"in": "query"
},
{
"type": "integer",
"default": 10,
"description": "Items per page",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/appresult.AppSuccess"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
}
}
}
},
"/visa-master-payment-orders/{id}": {
"get": {
"security": [
@@ -9171,6 +9260,9 @@
"orderId": {
"type": "integer"
},
"orderNumber": {
"type": "string"
},
"orderUniqueId": {
"type": "string"
},
@@ -9818,6 +9910,9 @@
"orderId": {
"type": "integer"
},
"orderNumber": {
"type": "string"
},
"paymentId": {
"type": "integer"
},
@@ -9894,6 +9989,9 @@
"orderId": {
"type": "integer"
},
"orderNumber": {
"type": "string"
},
"paid": {
"type": "boolean"
},

View File

@@ -1341,6 +1341,8 @@ definitions:
type: integer
orderId:
type: integer
orderNumber:
type: string
orderUniqueId:
type: string
paid:
@@ -1790,6 +1792,8 @@ definitions:
type: string
orderId:
type: integer
orderNumber:
type: string
paymentId:
type: integer
successUrl:
@@ -1840,6 +1844,8 @@ definitions:
type: integer
orderId:
type: integer
orderNumber:
type: string
paid:
type: boolean
paymentPeriod:
@@ -6212,13 +6218,17 @@ paths:
- user
/visa-master-payment-orders:
get:
description: Returns paginated visa/master payment orders with branch and user
details
description: Returns paginated visa/master payment orders; sber orders are excluded
(see /visa-master-payment-orders/sber)
parameters:
- description: Filter by passport name or surname
in: query
name: name
type: string
- description: Filter by order type (e.g. student), case-insensitive
in: query
name: type
type: string
- description: Filter by status
in: query
name: status
@@ -6535,6 +6545,60 @@ paths:
summary: GBÜS payment callback
tags:
- visa-master-payment-orders
/visa-master-payment-orders/sber:
get:
description: Returns paginated payment orders of type sber
parameters:
- description: Filter by passport name or surname
in: query
name: name
type: string
- description: Filter by status
in: query
name: status
type: string
- description: Filter by branch ID
in: query
name: branch_id
type: integer
- description: Filter by user ID
in: query
name: user_id
type: integer
- description: Filter by region
in: query
name: region
type: string
- default: 1
description: Page number
in: query
name: page
type: integer
- default: 10
description: Items per page
in: query
name: limit
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/appresult.AppSuccess'
"400":
description: Bad Request
schema:
$ref: '#/definitions/appresult.AppError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/appresult.AppError'
security:
- BearerAuth: []
summary: List sber payment orders
tags:
- visa-master-payment-orders
securityDefinitions:
BearerAuth:
in: header

View File

@@ -109,8 +109,8 @@ func (r *repository) List(ctx context.Context, filter visamaster.ListFilter) (vi
limitPlaceholder := len(args) + 1
offsetPlaceholder := len(args) + 2
query := fmt.Sprintf(
`SELECT o.id, o.type, o.created_at, o.region, o.branch_id, b.name, p.name,
o.passport_name, o.passport_surname, o.phone, o.status, o.paid
`SELECT o.id, o.unique_id, o.type, o.created_at, o.region, p.region, o.branch_id, b.name, p.name,
o.passport_name, o.passport_surname, o.phone, o.status, o.paid, `+paidThisMonthSQL+`
FROM visa_master_payment_orders o
LEFT JOIN branches b ON b.id = o.branch_id
LEFT JOIN provinces p ON p.id = b.province_id%s ORDER BY o.id DESC LIMIT $%d OFFSET $%d`,
@@ -150,6 +150,18 @@ func buildListQuery(filter visamaster.ListFilter) (whereClause string, args []in
)`, n))
}
// Case-insensitive and trimmed, the same match visamasterpay uses to
// pick Sber fees and credentials.
if filter.Type != "" {
args = append(args, strings.TrimSpace(filter.Type))
conditions = append(conditions, fmt.Sprintf("LOWER(TRIM(o.type)) = LOWER($%d)", len(args)))
}
if filter.ExcludeType != "" {
args = append(args, strings.TrimSpace(filter.ExcludeType))
conditions = append(conditions, fmt.Sprintf("LOWER(TRIM(COALESCE(o.type, ''))) <> LOWER($%d)", len(args)))
}
if filter.Status != nil {
args = append(args, *filter.Status)
conditions = append(conditions, fmt.Sprintf("o.status = $%d", len(args)))
@@ -296,18 +308,29 @@ func jsonOrDefault(raw []byte, fallback string) json.RawMessage {
return json.RawMessage(raw)
}
// paidThisMonthSQL: the order has a successful payment whose payment_period
// falls in the current month in Ashgabat time (UTC+5, as visamasterpay).
const paidThisMonthSQL = `EXISTS (
SELECT 1 FROM visa_master_order_payments vp
WHERE vp.order_id = o.id AND vp.gateway_status = 'success' AND vp.deleted_at IS NULL
AND date_trunc('month', vp.payment_period) = date_trunc('month', (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') + INTERVAL '5 hours')
)`
func scanOrderListItem(row genericrepo.Scanner) (visamaster.VisaMasterPaymentOrderListItemDTO, error) {
var item visamaster.VisaMasterPaymentOrderListItemDTO
var branchId int64
var branchNameJSON, provinceNameJSON []byte
var regionNameJSON, branchNameJSON, provinceNameJSON []byte
if err := row.Scan(
&item.Id, &item.Type, &item.CreatedAt, &item.Region, &branchId, &branchNameJSON, &provinceNameJSON,
&item.PassportName, &item.PassportSurname, &item.Phone, &item.Status, &item.Paid,
&item.Id, &item.UniqueId, &item.Type, &item.CreatedAt, &item.Region, &regionNameJSON, &branchId, &branchNameJSON, &provinceNameJSON,
&item.PassportName, &item.PassportSurname, &item.Phone, &item.Status, &item.Paid, &item.PaidThisMonth,
); err != nil {
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err
}
if err := shared.UnmarshalLocalized(regionNameJSON, &item.RegionName); err != nil {
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err
}
var branchName shared.LocalizedText
if err := shared.UnmarshalLocalized(branchNameJSON, &branchName); err != nil {
return visamaster.VisaMasterPaymentOrderListItemDTO{}, err

View File

@@ -107,24 +107,31 @@ type UpdateVisaMasterPaymentOrderDTO struct {
}
type ListFilter struct {
Name string
Status *string
BranchId *int64
BranchIds []int64
UserId *int64
Region string
Page int
Limit int
Name string
// Type narrows to one order type; ExcludeType drops one (the Visa/Master
// page hides sber, which has its own page).
Type string
ExcludeType string
Status *string
BranchId *int64
BranchIds []int64
UserId *int64
Region string
Page int
Limit int
}
// VisaMasterPaymentOrderListItemDTO is the list row (visa/master and sber);
// sender, receiver, documents and amounts come from GET /visa-master-payment-orders/:id.
type VisaMasterPaymentOrderListItemDTO struct {
Id int64 `json:"id"`
Type *string `json:"type"`
CreatedAt time.Time `json:"createdAt"`
Region string `json:"region"`
Branch *shared.NamedInfo `json:"branch,omitempty"`
Id int64 `json:"id"`
UniqueId *string `json:"uniqueId"`
Type *string `json:"type"`
CreatedAt time.Time `json:"createdAt"`
Region string `json:"region"`
// RegionName is the welaýat of the branch's province (Mary, Lebap, ...).
RegionName shared.LocalizedText `json:"regionName"`
Branch *shared.NamedInfo `json:"branch,omitempty"`
// ProvinceName is the branch's province (etrap).
ProvinceName shared.LocalizedText `json:"provinceName"`
PassportName string `json:"passportName"`
@@ -132,6 +139,9 @@ type VisaMasterPaymentOrderListItemDTO struct {
Phone string `json:"phone"`
Status *string `json:"status"`
Paid bool `json:"paid"`
// PaidThisMonth: a successful payment exists for the current month's
// payment period (Ashgabat time).
PaidThisMonth bool `json:"paidThisMonth"`
}
type ListVisaMasterPaymentOrderDTO struct {

View File

@@ -15,6 +15,10 @@ import (
"github.com/jackc/pgx/v4"
)
// orderTypeSber is the type value of Sber orders, matched case-insensitively
// like visamasterpay does when it picks Sber fees and credentials.
const orderTypeSber = "sber"
const baseURL = "/visa-master-payment-orders"
type handler struct {
@@ -29,6 +33,7 @@ func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler
func (h *handler) Register(router *gin.RouterGroup) {
group := rbac.Group(router, baseURL, rbac.Require(perm.Cards))
group.GET("", h.list)
group.GET("/sber", h.listSber)
group.GET("/:id", h.getByID)
group.POST("", h.create)
group.PUT("/:id", h.update)
@@ -37,11 +42,12 @@ func (h *handler) Register(router *gin.RouterGroup) {
// list godoc
// @Summary List visa/master payment orders
// @Description Returns paginated visa/master payment orders with branch and user details
// @Description Returns paginated visa/master payment orders; sber orders are excluded (see /visa-master-payment-orders/sber)
// @Tags visa-master-payment-orders
// @Produce json
// @Security BearerAuth
// @Param name query string false "Filter by passport name or surname"
// @Param type query string false "Filter by order type (e.g. student), case-insensitive"
// @Param status query string false "Filter by status"
// @Param branch_id query int false "Filter by branch ID"
// @Param user_id query int false "Filter by user ID"
@@ -58,7 +64,38 @@ func (h *handler) list(c *gin.Context) {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
}
filter.ExcludeType = orderTypeSber
h.respondList(c, filter)
}
// listSber godoc
// @Summary List sber payment orders
// @Description Returns paginated payment orders of type sber
// @Tags visa-master-payment-orders
// @Produce json
// @Security BearerAuth
// @Param name query string false "Filter by passport name or surname"
// @Param status query string false "Filter by status"
// @Param branch_id query int false "Filter by branch ID"
// @Param user_id query int false "Filter by user ID"
// @Param region query string false "Filter by region"
// @Param page query int false "Page number" default(1)
// @Param limit query int false "Items per page" default(10)
// @Success 200 {object} appresult.AppSuccess
// @Failure 400 {object} appresult.AppError
// @Failure 500 {object} appresult.AppError
// @Router /visa-master-payment-orders/sber [get]
func (h *handler) listSber(c *gin.Context) {
filter, ok := parseListFilter(c)
if !ok {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
}
filter.Type = orderTypeSber
h.respondList(c, filter)
}
func (h *handler) respondList(c *gin.Context, filter ListFilter) {
result, err := h.repository.List(c.Request.Context(), filter)
if err != nil {
h.logger.Errorf("list visa master payment orders failed: %v", err)
@@ -225,6 +262,10 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
filter.Name = raw
}
if raw := shared.QueryValue(c, "type"); raw != "" {
filter.Type = raw
}
if raw := shared.QueryValue(c, "status"); raw != "" {
filter.Status = &raw
}