Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 6m27s
feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package notify
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/perfect-panel/server/pkg/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/perfect-panel/server/internal/logic/notify"
|
|
"github.com/perfect-panel/server/internal/svc"
|
|
"github.com/perfect-panel/server/internal/types"
|
|
"github.com/perfect-panel/server/pkg/logger"
|
|
"github.com/perfect-panel/server/pkg/payment"
|
|
"github.com/perfect-panel/server/pkg/result"
|
|
)
|
|
|
|
// PaymentNotifyHandler Payment Notify
|
|
func PaymentNotifyHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
platform, ok := c.Request.Context().Value(constant.CtxKeyPlatform).(string)
|
|
if !ok {
|
|
logger.WithContext(c.Request.Context()).Errorf("platform not found")
|
|
result.HttpResult(c, nil, fmt.Errorf("platform not found"))
|
|
return
|
|
}
|
|
|
|
switch payment.ParsePlatform(platform) {
|
|
case payment.EPay, payment.CryptoSaaS:
|
|
req := &types.EPayNotifyRequest{}
|
|
if err := c.ShouldBind(req); err != nil {
|
|
result.HttpResult(c, nil, err)
|
|
return
|
|
}
|
|
l := notify.NewEPayNotifyLogic(c, svcCtx)
|
|
if err := l.EPayNotify(req); err != nil {
|
|
logger.WithContext(c.Request.Context()).Errorf("EPayNotify failed: %v", err.Error())
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
c.String(http.StatusOK, "%s", "success")
|
|
case payment.Stripe:
|
|
l := notify.NewStripeNotifyLogic(c.Request.Context(), svcCtx)
|
|
if err := l.StripeNotify(c.Request, c.Writer); err != nil {
|
|
result.HttpResult(c, nil, err)
|
|
return
|
|
}
|
|
result.HttpResult(c, nil, nil)
|
|
|
|
case payment.AlipayF2F:
|
|
l := notify.NewAlipayNotifyLogic(c.Request.Context(), svcCtx)
|
|
if err := l.AlipayNotify(c.Request); err != nil {
|
|
result.HttpResult(c, nil, err)
|
|
return
|
|
}
|
|
// Return success to alipay
|
|
c.String(http.StatusOK, "%s", "success")
|
|
|
|
default:
|
|
logger.WithContext(c.Request.Context()).Errorf("platform %s not support", platform)
|
|
}
|
|
}
|
|
}
|