MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / StripeWebhook

Function StripeWebhook

controller/topup_stripe.go:124–154  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

122}
123
124func StripeWebhook(c *gin.Context) {
125 payload, err := io.ReadAll(c.Request.Body)
126 if err != nil {
127 log.Printf("解析Stripe Webhook参数失败: %v\n", err)
128 c.AbortWithStatus(http.StatusServiceUnavailable)
129 return
130 }
131
132 signature := c.GetHeader("Stripe-Signature")
133 endpointSecret := setting.StripeWebhookSecret
134 event, err := webhook.ConstructEventWithOptions(payload, signature, endpointSecret, webhook.ConstructEventOptions{
135 IgnoreAPIVersionMismatch: true,
136 })
137
138 if err != nil {
139 log.Printf("Stripe Webhook验签失败: %v\n", err)
140 c.AbortWithStatus(http.StatusBadRequest)
141 return
142 }
143
144 switch event.Type {
145 case stripe.EventTypeCheckoutSessionCompleted:
146 sessionCompleted(event)
147 case stripe.EventTypeCheckoutSessionExpired:
148 sessionExpired(event)
149 default:
150 log.Printf("不支持的Stripe Webhook事件类型: %s\n", event.Type)
151 }
152
153 c.Status(http.StatusOK)
154}
155
156func sessionCompleted(event stripe.Event) {
157 customerId := event.GetObjectValue("customer")

Callers

nothing calls this directly

Calls 2

sessionCompletedFunction · 0.85
sessionExpiredFunction · 0.85

Tested by

no test coverage detected