支付成功回调

This commit is contained in:
Hiven
2023-07-28 11:15:42 +08:00
parent dbf500813c
commit 334ea4aa3f
13 changed files with 199 additions and 51 deletions

View File

@@ -18,7 +18,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: OrderPaymentIntentHandler(serverCtx),
},
{
Method: http.MethodGet,
Method: http.MethodPost,
Path: "/api/pay/stripe-webhook",
Handler: StripeWebhookHandler(serverCtx),
},

View File

@@ -1,6 +1,7 @@
package handler
import (
"io"
"net/http"
"reflect"
@@ -14,19 +15,31 @@ import (
func StripeWebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.StripeWebhookReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
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
// }
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, userinfo)
resp := l.StripeWebhook(&req, nil)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)