feat: 实现订单支付功能模块
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m36s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m36s
- 新增订单管理、支付回调、购买验证等核心服务 - 实现订单、订单项目的数据存储层和 API 接口 - 添加订单数据库迁移和 DTO 定义 - 更新 API 文档和路由配置 - 同步 3 个新规范到主规范库(订单管理、订单支付、套餐购买验证) - 完成 OpenSpec 变更归档 Ultraworked with Sisyphus
This commit is contained in:
60
internal/handler/callback/payment.go
Normal file
60
internal/handler/callback/payment.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package callback
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
orderService "github.com/break/junhong_cmp_fiber/internal/service/order"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type PaymentHandler struct {
|
||||
orderService *orderService.Service
|
||||
}
|
||||
|
||||
func NewPaymentHandler(orderService *orderService.Service) *PaymentHandler {
|
||||
return &PaymentHandler{orderService: orderService}
|
||||
}
|
||||
|
||||
type WechatPayCallbackRequest struct {
|
||||
OrderNo string `json:"order_no" xml:"out_trade_no"`
|
||||
}
|
||||
|
||||
func (h *PaymentHandler) WechatPayCallback(c *fiber.Ctx) error {
|
||||
var req WechatPayCallbackRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
if req.OrderNo == "" {
|
||||
return errors.New(errors.CodeInvalidParam, "订单号不能为空")
|
||||
}
|
||||
|
||||
if err := h.orderService.HandlePaymentCallback(c.UserContext(), req.OrderNo, model.PaymentMethodWechat); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, map[string]string{"return_code": "SUCCESS"})
|
||||
}
|
||||
|
||||
type AlipayCallbackRequest struct {
|
||||
OrderNo string `json:"out_trade_no" form:"out_trade_no"`
|
||||
}
|
||||
|
||||
func (h *PaymentHandler) AlipayCallback(c *fiber.Ctx) error {
|
||||
var req AlipayCallbackRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
if req.OrderNo == "" {
|
||||
return errors.New(errors.CodeInvalidParam, "订单号不能为空")
|
||||
}
|
||||
|
||||
if err := h.orderService.HandlePaymentCallback(c.UserContext(), req.OrderNo, model.PaymentMethodAlipay); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.SendString("success")
|
||||
}
|
||||
Reference in New Issue
Block a user