package hdl

import (
	"applet/app/e"
	"applet/app/svc"
	"applet/app/utils/logx"
	"errors"
	"github.com/gin-gonic/gin"
)

// 整合所有支付回调
func PayCallback(c *gin.Context) {
	// 统一处理回调参数
	data, orderType, payMethod := svc.CheckAllCallbackParams(c)
	if data == nil {
		e.OutErr(c, e.ERR_INVALID_ARGS)
		return
	}
	c.Set("callback", data)
	payCallbackFunc, ok := svc.PayCallbackFuncList[orderType][payMethod]
	if !ok || payCallbackFunc == nil {
		_ = logx.Warn(errors.New("回调不存在"))
		return
	}
	payCallbackFunc(c)
	c.String(200, "success")
	return
}
