added payment history
This commit is contained in:
1 parent
23d208769c
commit
99788a853f
9 files changed
+768
No files matched your search
+177
@@ -4897,6 +4897,89 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/payment-history": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns a paginated, branch-scoped audit trail of visa/master/sber payout attempts (paid, failed, or pending), across orders",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-history"
|
||||||
|
],
|
||||||
|
"summary": "List payment history",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by order ID",
|
||||||
|
"name": "order_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by branch ID",
|
||||||
|
"name": "branch_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by order owner (client) user ID",
|
||||||
|
"name": "user_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Filter by gateway status (pending, success, failed)",
|
||||||
|
"name": "status",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Filter by passport name/surname or order unique ID",
|
||||||
|
"name": "search",
|
||||||
|
"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/paymenthistory.ListPaymentHistoryDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/payment-settings": {
|
"/payment-settings": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -9289,6 +9372,100 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"paymenthistory.ListPaymentHistoryDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"count": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/paymenthistory.PaymentHistoryItemDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"paymenthistory.PaymentHistoryItemDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"branchId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"branchName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdById": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"createdByName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"exchangeRateRub": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gatewayReference": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gatewayStatus": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"orderId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"orderUniqueId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"paid": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"passportName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"passportSurname": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"paymentPeriod": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"totalAmountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updatedAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"userId": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"paymentsettings.PaymentSettingsDTO": {
|
"paymentsettings.PaymentSettingsDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -4891,6 +4891,89 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/payment-history": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns a paginated, branch-scoped audit trail of visa/master/sber payout attempts (paid, failed, or pending), across orders",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-history"
|
||||||
|
],
|
||||||
|
"summary": "List payment history",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by order ID",
|
||||||
|
"name": "order_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by branch ID",
|
||||||
|
"name": "branch_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by order owner (client) user ID",
|
||||||
|
"name": "user_id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Filter by gateway status (pending, success, failed)",
|
||||||
|
"name": "status",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Filter by passport name/surname or order unique ID",
|
||||||
|
"name": "search",
|
||||||
|
"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/paymenthistory.ListPaymentHistoryDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/payment-settings": {
|
"/payment-settings": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -9283,6 +9366,100 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"paymenthistory.ListPaymentHistoryDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"count": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/paymenthistory.PaymentHistoryItemDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"paymenthistory.PaymentHistoryItemDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"branchId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"branchName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdById": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"createdByName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"exchangeRateRub": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gatewayReference": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gatewayStatus": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"orderId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"orderUniqueId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"paid": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"passportName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"passportSurname": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"paymentPeriod": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"totalAmountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updatedAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"userId": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"paymentsettings.PaymentSettingsDTO": {
|
"paymentsettings.PaymentSettingsDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -1295,6 +1295,68 @@ definitions:
|
|||||||
- price
|
- price
|
||||||
- title
|
- title
|
||||||
type: object
|
type: object
|
||||||
|
paymenthistory.ListPaymentHistoryDTO:
|
||||||
|
properties:
|
||||||
|
count:
|
||||||
|
type: integer
|
||||||
|
items:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/paymenthistory.PaymentHistoryItemDTO'
|
||||||
|
type: array
|
||||||
|
type: object
|
||||||
|
paymenthistory.PaymentHistoryItemDTO:
|
||||||
|
properties:
|
||||||
|
amountTmt:
|
||||||
|
type: number
|
||||||
|
bankFeeTmt:
|
||||||
|
type: number
|
||||||
|
branchId:
|
||||||
|
type: integer
|
||||||
|
branchName:
|
||||||
|
type: string
|
||||||
|
createdAt:
|
||||||
|
type: string
|
||||||
|
createdById:
|
||||||
|
type: integer
|
||||||
|
createdByName:
|
||||||
|
type: string
|
||||||
|
exchangeRateRub:
|
||||||
|
type: number
|
||||||
|
exchangeRateUsd:
|
||||||
|
type: number
|
||||||
|
gatewayReference:
|
||||||
|
type: string
|
||||||
|
gatewayStatus:
|
||||||
|
type: string
|
||||||
|
gbusFeeTmt:
|
||||||
|
type: number
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
orderId:
|
||||||
|
type: integer
|
||||||
|
orderUniqueId:
|
||||||
|
type: string
|
||||||
|
paid:
|
||||||
|
type: boolean
|
||||||
|
passportName:
|
||||||
|
type: string
|
||||||
|
passportSurname:
|
||||||
|
type: string
|
||||||
|
paymentPeriod:
|
||||||
|
type: string
|
||||||
|
totalAmountTmt:
|
||||||
|
type: number
|
||||||
|
tvebFeeTmt:
|
||||||
|
type: number
|
||||||
|
tvebFeeUsd:
|
||||||
|
type: number
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
updatedAt:
|
||||||
|
type: string
|
||||||
|
userId:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
paymentsettings.PaymentSettingsDTO:
|
paymentsettings.PaymentSettingsDTO:
|
||||||
properties:
|
properties:
|
||||||
bankFeeTmt:
|
bankFeeTmt:
|
||||||
@@ -4869,6 +4931,61 @@ paths:
|
|||||||
summary: Update payment card active
|
summary: Update payment card active
|
||||||
tags:
|
tags:
|
||||||
- payment-card
|
- payment-card
|
||||||
|
/payment-history:
|
||||||
|
get:
|
||||||
|
description: Returns a paginated, branch-scoped audit trail of visa/master/sber
|
||||||
|
payout attempts (paid, failed, or pending), across orders
|
||||||
|
parameters:
|
||||||
|
- description: Filter by order ID
|
||||||
|
in: query
|
||||||
|
name: order_id
|
||||||
|
type: integer
|
||||||
|
- description: Filter by branch ID
|
||||||
|
in: query
|
||||||
|
name: branch_id
|
||||||
|
type: integer
|
||||||
|
- description: Filter by order owner (client) user ID
|
||||||
|
in: query
|
||||||
|
name: user_id
|
||||||
|
type: integer
|
||||||
|
- description: Filter by gateway status (pending, success, failed)
|
||||||
|
in: query
|
||||||
|
name: status
|
||||||
|
type: string
|
||||||
|
- description: Filter by passport name/surname or order unique ID
|
||||||
|
in: query
|
||||||
|
name: search
|
||||||
|
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/paymenthistory.ListPaymentHistoryDTO'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: List payment history
|
||||||
|
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
|
||||||
|
|||||||
@@ -556,6 +556,7 @@ func operatorPathModule(_, path string) string {
|
|||||||
"/card-pin-orders",
|
"/card-pin-orders",
|
||||||
"/card-rekwizit-orders",
|
"/card-rekwizit-orders",
|
||||||
"/visa-master-payment-orders",
|
"/visa-master-payment-orders",
|
||||||
|
"/payment-history",
|
||||||
"/payment-cards",
|
"/payment-cards",
|
||||||
"/reasons-cards",
|
"/reasons-cards",
|
||||||
}):
|
}):
|
||||||
@@ -671,6 +672,7 @@ var operatorGetPrefixes = []string{
|
|||||||
"/payment-cards",
|
"/payment-cards",
|
||||||
"/reasons-cards",
|
"/reasons-cards",
|
||||||
"/visa-master-payment-orders",
|
"/visa-master-payment-orders",
|
||||||
|
"/payment-history",
|
||||||
"/loan-orders",
|
"/loan-orders",
|
||||||
"/loan-types",
|
"/loan-types",
|
||||||
"/loans-documents",
|
"/loans-documents",
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"online-back/internal/identity/rbac"
|
||||||
|
"online-back/internal/payment/paymenthistory"
|
||||||
|
"online-back/internal/shared"
|
||||||
|
"online-back/pkg/client/postgresql"
|
||||||
|
"online-back/pkg/logging"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
type repository struct {
|
||||||
|
client postgresql.Client
|
||||||
|
logger *logging.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(client postgresql.Client, logger *logging.Logger) paymenthistory.Repository {
|
||||||
|
return &repository{client: client, logger: logger}
|
||||||
|
}
|
||||||
|
|
||||||
|
const historyFromClause = ` FROM visa_master_order_payments p
|
||||||
|
JOIN visa_master_payment_orders o ON o.id = p.order_id
|
||||||
|
LEFT JOIN branches b ON b.id = o.branch_id
|
||||||
|
LEFT JOIN users u ON u.id = p.created_by`
|
||||||
|
|
||||||
|
const historySelectColumns = `p.id, p.order_id, COALESCE(o.unique_id, ''), COALESCE(o.type, ''),
|
||||||
|
o.branch_id, COALESCE(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.exchange_rate_usd, p.exchange_rate_rub, p.payment_period,
|
||||||
|
p.gateway_status, p.gateway_reference, p.created_by, ` + shared.UserDisplaySQL + `,
|
||||||
|
p.created_at, p.updated_at`
|
||||||
|
|
||||||
|
func (r *repository) List(ctx context.Context, filter paymenthistory.ListFilter) (paymenthistory.ListPaymentHistoryDTO, error) {
|
||||||
|
whereClause, args := buildListQuery(filter)
|
||||||
|
|
||||||
|
var count int64
|
||||||
|
countQuery := `SELECT COUNT(*)` + historyFromClause + whereClause
|
||||||
|
if err := r.client.QueryRow(ctx, countQuery, args...).Scan(&count); err != nil {
|
||||||
|
return paymenthistory.ListPaymentHistoryDTO{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
offset := (filter.Page - 1) * filter.Limit
|
||||||
|
limitPlaceholder := len(args) + 1
|
||||||
|
offsetPlaceholder := len(args) + 2
|
||||||
|
query := fmt.Sprintf(
|
||||||
|
`SELECT %s%s%s ORDER BY p.id DESC LIMIT $%d OFFSET $%d`,
|
||||||
|
historySelectColumns, historyFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
|
||||||
|
)
|
||||||
|
|
||||||
|
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
|
||||||
|
if err != nil {
|
||||||
|
return paymenthistory.ListPaymentHistoryDTO{}, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
var items []paymenthistory.PaymentHistoryItemDTO
|
||||||
|
for rows.Next() {
|
||||||
|
item, err := scanHistoryItem(rows)
|
||||||
|
if err != nil {
|
||||||
|
return paymenthistory.ListPaymentHistoryDTO{}, err
|
||||||
|
}
|
||||||
|
items = append(items, item)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return paymenthistory.ListPaymentHistoryDTO{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return paymenthistory.ListPaymentHistoryDTO{Count: count, Items: items}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildListQuery(filter paymenthistory.ListFilter) (whereClause string, args []interface{}) {
|
||||||
|
conditions := []string{"p.deleted_at IS NULL", "o.deleted_at IS NULL"}
|
||||||
|
|
||||||
|
if filter.OrderId != nil {
|
||||||
|
args = append(args, *filter.OrderId)
|
||||||
|
conditions = append(conditions, fmt.Sprintf("p.order_id = $%d", len(args)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(filter.BranchIds) > 0 {
|
||||||
|
conditions, args = rbac.AppendBranchIDs(conditions, args, "o.branch_id", filter.BranchIds)
|
||||||
|
} else if filter.BranchId != nil {
|
||||||
|
args = append(args, *filter.BranchId)
|
||||||
|
conditions = append(conditions, fmt.Sprintf("o.branch_id = $%d", len(args)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if filter.UserId != nil {
|
||||||
|
args = append(args, *filter.UserId)
|
||||||
|
conditions = append(conditions, fmt.Sprintf("p.user_id = $%d", len(args)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if filter.Status != nil {
|
||||||
|
args = append(args, *filter.Status)
|
||||||
|
conditions = append(conditions, fmt.Sprintf("p.gateway_status = $%d", len(args)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if filter.Search != "" {
|
||||||
|
args = append(args, shared.LikePattern(filter.Search))
|
||||||
|
n := len(args)
|
||||||
|
conditions = append(conditions, fmt.Sprintf(`(
|
||||||
|
o.passport_name ILIKE $%[1]d OR o.passport_surname ILIKE $%[1]d OR o.unique_id ILIKE $%[1]d
|
||||||
|
)`, n))
|
||||||
|
}
|
||||||
|
|
||||||
|
return " WHERE " + strings.Join(conditions, " AND "), args
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanHistoryItem(row pgx.Row) (paymenthistory.PaymentHistoryItemDTO, error) {
|
||||||
|
var item paymenthistory.PaymentHistoryItemDTO
|
||||||
|
var gatewayStatus string
|
||||||
|
if err := row.Scan(
|
||||||
|
&item.Id, &item.OrderId, &item.OrderUniqueId, &item.Type,
|
||||||
|
&item.BranchId, &item.BranchName, &item.PassportName, &item.PassportSurname, &item.UserId,
|
||||||
|
&item.AmountTmt, &item.BankFeeTmt, &item.GbusFeeTmt, &item.TvebFeeUsd, &item.TvebFeeTmt, &item.TotalAmountTmt,
|
||||||
|
&item.ExchangeRateUsd, &item.ExchangeRateRub, &item.PaymentPeriod,
|
||||||
|
&gatewayStatus, &item.GatewayReference, &item.CreatedById, &item.CreatedByName,
|
||||||
|
&item.CreatedAt, &item.UpdatedAt,
|
||||||
|
); err != nil {
|
||||||
|
return paymenthistory.PaymentHistoryItemDTO{}, err
|
||||||
|
}
|
||||||
|
item.GatewayStatus = gatewayStatus
|
||||||
|
item.Paid = gatewayStatus == "success"
|
||||||
|
return item, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
// 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 "time"
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
OrderUniqueId string `json:"orderUniqueId"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
BranchId int64 `json:"branchId"`
|
||||||
|
BranchName string `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"`
|
||||||
|
ExchangeRateUsd float64 `json:"exchangeRateUsd"`
|
||||||
|
ExchangeRateRub *float64 `json:"exchangeRateRub,omitempty"`
|
||||||
|
PaymentPeriod time.Time `json:"paymentPeriod"`
|
||||||
|
GatewayStatus string `json:"gatewayStatus"`
|
||||||
|
GatewayReference *string `json:"gatewayReference,omitempty"`
|
||||||
|
CreatedById *int64 `json:"createdById,omitempty"`
|
||||||
|
CreatedByName string `json:"createdByName,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
Page int
|
||||||
|
Limit int
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListPaymentHistoryDTO struct {
|
||||||
|
Count int64 `json:"count"`
|
||||||
|
Items []PaymentHistoryItemDTO `json:"items"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package paymenthistory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"online-back/internal/appresult"
|
||||||
|
"online-back/internal/handlers"
|
||||||
|
"online-back/internal/identity/rbac"
|
||||||
|
"online-back/internal/shared"
|
||||||
|
"online-back/pkg/logging"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
const baseURL = "/payment-history"
|
||||||
|
|
||||||
|
type handler struct {
|
||||||
|
logger *logging.Logger
|
||||||
|
repository Repository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler {
|
||||||
|
return &handler{logger: logger, repository: repository}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handler) Register(router *gin.RouterGroup) {
|
||||||
|
group := router.Group(baseURL, appresult.JwtTokenCheck())
|
||||||
|
group.GET("", h.list)
|
||||||
|
}
|
||||||
|
|
||||||
|
// list godoc
|
||||||
|
// @Summary List payment history
|
||||||
|
// @Description Returns a paginated, branch-scoped audit trail of visa/master/sber payout attempts (paid, failed, or pending), across orders
|
||||||
|
// @Tags payment-history
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param order_id query int false "Filter by order ID"
|
||||||
|
// @Param branch_id query int false "Filter by branch ID"
|
||||||
|
// @Param user_id query int false "Filter by order owner (client) user ID"
|
||||||
|
// @Param status query string false "Filter by gateway status (pending, success, failed)"
|
||||||
|
// @Param search query string false "Filter by passport name/surname or order unique ID"
|
||||||
|
// @Param page query int false "Page number" default(1)
|
||||||
|
// @Param limit query int false "Items per page" default(10)
|
||||||
|
// @Success 200 {object} ListPaymentHistoryDTO
|
||||||
|
// @Failure 400 {object} appresult.AppError
|
||||||
|
// @Failure 500 {object} appresult.AppError
|
||||||
|
// @Router /payment-history [get]
|
||||||
|
func (h *handler) list(c *gin.Context) {
|
||||||
|
filter, ok := parseListFilter(c)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.repository.List(c.Request.Context(), filter)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Errorf("list payment history failed: %v", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||||
|
page, limit, ok := shared.ParsePageLimit(c)
|
||||||
|
if !ok {
|
||||||
|
return ListFilter{}, false
|
||||||
|
}
|
||||||
|
filter := ListFilter{Page: page, Limit: limit}
|
||||||
|
|
||||||
|
if id, ok := shared.OptionalQueryID(c, "order_id", "orderId"); !ok {
|
||||||
|
return ListFilter{}, false
|
||||||
|
} else if id != nil {
|
||||||
|
filter.OrderId = id
|
||||||
|
}
|
||||||
|
|
||||||
|
if id, ok := shared.OptionalQueryID(c, "branch_id", "branchId"); !ok {
|
||||||
|
return ListFilter{}, false
|
||||||
|
} else if id != nil {
|
||||||
|
filter.BranchId = id
|
||||||
|
}
|
||||||
|
|
||||||
|
if id, ok := shared.OptionalQueryID(c, "user_id", "userId"); !ok {
|
||||||
|
return ListFilter{}, false
|
||||||
|
} else if id != nil {
|
||||||
|
filter.UserId = id
|
||||||
|
}
|
||||||
|
|
||||||
|
if raw := shared.QueryValue(c, "status"); raw != "" {
|
||||||
|
filter.Status = &raw
|
||||||
|
}
|
||||||
|
|
||||||
|
filter.Search = shared.QueryValue(c, "search", "q")
|
||||||
|
|
||||||
|
rbac.BindBranchIDs(c, &filter.BranchIds)
|
||||||
|
return filter, true
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package paymenthistory
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type Repository interface {
|
||||||
|
List(ctx context.Context, filter ListFilter) (ListPaymentHistoryDTO, error)
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ package payment
|
|||||||
import (
|
import (
|
||||||
"online-back/internal/currency"
|
"online-back/internal/currency"
|
||||||
"online-back/internal/handlers"
|
"online-back/internal/handlers"
|
||||||
|
"online-back/internal/payment/paymenthistory"
|
||||||
|
paymenthistorydb "online-back/internal/payment/paymenthistory/db"
|
||||||
"online-back/internal/payment/paymentsettings"
|
"online-back/internal/payment/paymentsettings"
|
||||||
paymentsettingsdb "online-back/internal/payment/paymentsettings/db"
|
paymentsettingsdb "online-back/internal/payment/paymentsettings/db"
|
||||||
"online-back/internal/payment/visamasterpay"
|
"online-back/internal/payment/visamasterpay"
|
||||||
@@ -30,5 +32,6 @@ func Handlers(client postgresql.Client, logger *logging.Logger, currencyRepo cur
|
|||||||
return []handlers.Handler{
|
return []handlers.Handler{
|
||||||
paymentsettings.NewHandler(logger, settingsRepo),
|
paymentsettings.NewHandler(logger, settingsRepo),
|
||||||
visamasterpay.NewHandler(logger, visamasterpaydb.NewRepository(client, logger, currencyRepo, settingsRepo, gateway, publicBaseURL)),
|
visamasterpay.NewHandler(logger, visamasterpaydb.NewRepository(client, logger, currencyRepo, settingsRepo, gateway, publicBaseURL)),
|
||||||
|
paymenthistory.NewHandler(logger, paymenthistorydb.NewRepository(client, logger)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user