// Package paymenthistory exposes a read-only, branch-scoped audit view over // every visa/master/sber payout attempt (visa_master_order_payments) - the // full trail visamasterpay.PaymentResultDTO deliberately keeps per-order // (see its doc comment), denormalized here with order/branch/operator info // so an admin/operator can browse and filter payment history across orders // without N+1 calls. package paymenthistory import ( "encoding/json" "time" "online-back/internal/shared" ) // PaymentHistoryItemDTO is one payout attempt (paid, failed, or still // pending) enriched with the order/branch/client/operator context needed to // display it in a history list, without requiring a separate lookup per row. type PaymentHistoryItemDTO struct { Id int64 `json:"id"` OrderId int64 `json:"orderId"` OrderNumber string `json:"orderNumber"` OrderUniqueId string `json:"orderUniqueId"` Type string `json:"type"` BranchId int64 `json:"branchId"` BranchName shared.LocalizedText `json:"branchName"` PassportName string `json:"passportName"` PassportSurname string `json:"passportSurname"` UserId int64 `json:"userId"` Paid bool `json:"paid"` AmountTmt float64 `json:"amountTmt"` BankFeeTmt float64 `json:"bankFeeTmt"` GbusFeeTmt *float64 `json:"gbusFeeTmt,omitempty"` TvebFeeUsd *float64 `json:"tvebFeeUsd,omitempty"` TvebFeeTmt *float64 `json:"tvebFeeTmt,omitempty"` TotalAmountTmt float64 `json:"totalAmountTmt"` // AmountMinor is the amount registered with GBÜS, in tetri. AmountMinor int64 `json:"amountMinor"` // AmountUsd is amount_tmt converted back at the attempt's own // exchange_rate_usd - the USD figure the payout was quoted in. AmountUsd float64 `json:"amountUsd"` ExchangeRateUsd float64 `json:"exchangeRateUsd"` ExchangeRateRub *float64 `json:"exchangeRateRub,omitempty"` PaymentPeriod time.Time `json:"paymentPeriod"` GatewayStatus string `json:"gatewayStatus"` GatewayReference *string `json:"gatewayReference,omitempty"` // ApiClient is the branch's GBÜS merchant username for this order type // (visa/master or sber) and Description the text sent with register.do - // both as visamasterpay's Pay picks them. ApiClient string `json:"apiClient"` Description string `json:"description"` // CardholderName/MaskedPan come from GBÜS's getOrderStatusExtended // cardAuthInfo, so they're only known once an attempt has been // finalized by the callback/status check (unset while pending, and for // attempts that never reached the card form). CardholderName *string `json:"cardholderName,omitempty"` MaskedPan *string `json:"maskedPan,omitempty"` // FormUrl/SuccessUrl are only set while the attempt is still pending // (awaiting the customer to finish paying on GBÜS's hosted page) - once // an attempt is finalized (success/failed), gateway_response no longer // holds a formUrl, so there's nothing left to resume. FormUrl *string `json:"formUrl,omitempty"` SuccessUrl *string `json:"successUrl,omitempty"` CreatedById *int64 `json:"createdById,omitempty"` CreatedByName string `json:"createdByName,omitempty"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } // PaymentHistoryDetailDTO is a single payout attempt with the raw GBÜS // response kept alongside it - the list deliberately leaves the jsonb out // so pages stay small. type PaymentHistoryDetailDTO struct { PaymentHistoryItemDTO GatewayResponse json.RawMessage `json:"gatewayResponse,omitempty" swaggertype:"object"` } // ListFilter narrows the history list. BranchIds is populated by // rbac.BindBranchIDs and takes priority over BranchId when set (see // rbac.AppendBranchIDs), the same way visamaster.ListFilter works. type ListFilter struct { OrderId *int64 BranchId *int64 BranchIds []int64 UserId *int64 Status *string // gateway_status: pending/success/failed Search string // matches order passport name/surname or unique id Sort string // one of SortColumns' keys; empty means id Desc bool Page int Limit int } // SortColumns maps the accepted ?sort= values to their SQL expressions. var SortColumns = map[string]string{ "id": "p.id", "created_at": "p.created_at", "status": "p.gateway_status", "amount": "p.amount_tmt", } type ListPaymentHistoryDTO struct { Count int64 `json:"count"` Items []PaymentHistoryItemDTO `json:"items"` } // PaymentLogDTO is one step-by-step entry from visa_master_payment_logs - // the granular audit trail recorded while processing an order's payout // (see visamasterpay's logStep), independent of and more detailed than // the summary rows in visa_master_order_payments. type PaymentLogDTO struct { Id int64 `json:"id"` OrderId int64 `json:"orderId"` Step string `json:"step"` Detail json.RawMessage `json:"detail,omitempty"` CreatedById *int64 `json:"createdById,omitempty"` CreatedByName string `json:"createdByName,omitempty"` CreatedAt time.Time `json:"createdAt"` }