2026-04-04 01:28:57 +08:00

37 lines
904 B
Go

package pay
import (
"context"
"strings"
gatewaypb "chatappgateway/api/proto"
"chatappgateway/internal/apperr"
)
// Client 定义支付服务 gRPC 客户端能力。
type Client interface {
QueryOrder(ctx context.Context, request *gatewaypb.QueryOrderRequest) (*gatewaypb.QueryOrderResponse, error)
}
// Service 负责订单号校验和下游支付查询。
type Service struct {
client Client
}
// New 创建支付查询服务。
func New(client Client) *Service {
return &Service{client: client}
}
// QueryOrder 校验订单号并调用支付服务。
func (s *Service) QueryOrder(ctx context.Context, orderNo string) (*gatewaypb.QueryOrderResponse, error) {
normalized := strings.TrimSpace(orderNo)
if normalized == "" {
return nil, apperr.New(400, "bad_request", "order_no is required")
}
return s.client.QueryOrder(ctx, &gatewaypb.QueryOrderRequest{
OrderNo: normalized,
})
}