钱包充值为开发态测试功能(生产环境本就禁用),且支付回调存在重复入账风险:入账与标记 paid 两步非原子、wallet_ledger 去重无唯一索引、幂等键使用了可变的 ProviderOrderID。直接删除该功能从根本上消除风险。 后端: - payment 移除 StartWalletRecharge/QueryWalletRecharge 及相关 handler/DTO/常量;confirmPaid 增加 OrderID 守卫;解除对 wallet 仓库的依赖 - wallet 移除 Recharge/ConfirmRechargeFromChannel 及相关定义 - 移除三条充值路由;adminfinance 财务统计口径只统计 order_pay - 清理充值相关测试用例 前端: - 移除充值 API、WalletView 充值面板/弹窗、admin 充值标签与筛选 - 保留钱包余额、流水、提现等核心能力 go build/vet 与 vue-tsc typecheck 均通过。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
94 lines
2.7 KiB
Go
94 lines
2.7 KiB
Go
package payment
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
var (
|
|
ErrDependencyUnavailable = errors.New("dependency unavailable")
|
|
ErrPaymentUnavailable = errors.New("payment unavailable")
|
|
ErrPaymentCannotStart = errors.New("payment cannot start")
|
|
ErrPaymentVerifyFailed = errors.New("payment verify failed")
|
|
ErrPaymentNotFound = errors.New("payment not found")
|
|
ErrRefundCannotStart = errors.New("refund cannot start")
|
|
)
|
|
|
|
type Service struct {
|
|
repo *Repository
|
|
}
|
|
|
|
func NewService(repo *Repository) *Service {
|
|
return &Service{repo: repo}
|
|
}
|
|
|
|
func (s *Service) Start(ctx context.Context, userID uint64, orderID uint64, req StartPaymentRequest, clientIP string) (*PaymentDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if userID == 0 || orderID == 0 {
|
|
return nil, ErrPaymentCannotStart
|
|
}
|
|
return s.repo.Start(ctx, userID, orderID, req, clientIP)
|
|
}
|
|
|
|
func (s *Service) Query(ctx context.Context, userID uint64, orderID uint64) (*PaymentDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if userID == 0 || orderID == 0 {
|
|
return nil, ErrPaymentNotFound
|
|
}
|
|
return s.repo.Query(ctx, userID, orderID)
|
|
}
|
|
|
|
func (s *Service) HandleLeshuaNotify(ctx context.Context, params map[string]string, rawPayload string, contentType string) (*NotifyResult, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.HandleLeshuaNotify(ctx, params, rawPayload, contentType)
|
|
}
|
|
|
|
func (s *Service) HandleNotify(ctx context.Context, provider string, params map[string]string, rawPayload string, contentType string, authorization string) (*NotifyResult, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.HandleNotify(ctx, provider, params, rawPayload, contentType, authorization)
|
|
}
|
|
|
|
func (s *Service) StartRefund(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string, remark string) (*RefundDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if orderID == 0 || refundAmountCent <= 0 {
|
|
return nil, ErrRefundCannotStart
|
|
}
|
|
return s.repo.StartRefund(ctx, orderID, refundAmountCent, bizType, remark)
|
|
}
|
|
|
|
func (s *Service) QueryRefundStatus(ctx context.Context, orderID uint64) (*RefundDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if orderID == 0 {
|
|
return nil, ErrPaymentNotFound
|
|
}
|
|
return s.repo.QueryRefundStatus(ctx, orderID)
|
|
}
|
|
|
|
func (s *Service) AdminList(ctx context.Context, query AdminPaymentQuery) (*PaginatedResult, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if query.Page < 1 {
|
|
query.Page = 1
|
|
}
|
|
if query.PageSize < 1 {
|
|
query.PageSize = 20
|
|
}
|
|
if query.PageSize > 100 {
|
|
query.PageSize = 100
|
|
}
|
|
return s.repo.AdminList(ctx, query)
|
|
}
|