58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"reflect"
|
|
|
|
"fusenapi/utils/basic"
|
|
|
|
"fusenapi/server/pay/internal/logic"
|
|
"fusenapi/server/pay/internal/svc"
|
|
"fusenapi/server/pay/internal/types"
|
|
)
|
|
|
|
func StripeWebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
const MaxBodyBytes = int64(65536)
|
|
r.Body = http.MaxBytesReader(w, r.Body, MaxBodyBytes)
|
|
defer r.Body.Close()
|
|
payload, err := io.ReadAll(r.Body)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
var req types.StripeWebhookReq
|
|
|
|
// userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
// if err != nil {
|
|
// return
|
|
// }
|
|
|
|
IPAddress := r.Header.Get("X-Real-Ip")
|
|
if IPAddress == "" {
|
|
IPAddress = r.Header.Get("X-Forwarded-For")
|
|
}
|
|
if IPAddress == "" {
|
|
IPAddress = r.RemoteAddr
|
|
}
|
|
|
|
req.RemoteAddr = IPAddress
|
|
req.Payload = payload
|
|
req.StripeSignature = r.Header.Get("Stripe-Signature")
|
|
|
|
// 创建一个业务逻辑层实例
|
|
l := logic.NewStripeWebhookLogic(r.Context(), svcCtx)
|
|
|
|
rl := reflect.ValueOf(l)
|
|
basic.BeforeLogic(w, r, rl)
|
|
|
|
resp := l.StripeWebhook(&req, nil)
|
|
|
|
if !basic.AfterLogic(w, r, rl, resp) {
|
|
basic.NormalAfterLogic(w, r, resp)
|
|
}
|
|
}
|
|
}
|