hi-server/internal/handler/notify/paymentNotifyHandler.go
shanshanzhong a80d6af035
Some checks failed
Build docker and publish / build (20.15.1) (push) Has been cancelled
refactor(payment): 移除ApplePay支付平台支持并整合到Stripe
将ApplePay支付方式整合到Stripe平台处理,移除独立的ApplePay平台代码
简化支付逻辑,统一通过Stripe处理所有支付方式
2025-12-09 00:58:03 -08:00

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)
}
}
}