From f00ea7e873a018a2d21cdacea0967dae66c78060 Mon Sep 17 00:00:00 2001 From: "Logan.Li" Date: Wed, 12 Aug 2026 15:57:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Waffo=20webhook=20=E6=94=AF=E6=8C=81=20G?= =?UTF-8?q?ET=20=E6=8E=A2=E6=B5=8B=EF=BC=8C=E9=81=BF=E5=85=8D=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E6=89=93=E5=BC=80=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仪表盘/浏览器用 GET 校验 URL 时返回 ready;支付事件仍走 POST。 Co-authored-by: Cursor --- .env.example | 2 +- backend/internal/controller/order/order_controller.go | 10 ++++++++++ backend/internal/service/payment/waffo.go | 2 +- backend/internal/service/payment/waffo_test.go | 6 +++--- backend/router/router.go | 1 + 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 67ca835..897d095 100644 --- a/.env.example +++ b/.env.example @@ -49,7 +49,7 @@ WAFFO_STORE_SLUG=opsxshell-pwsi6m4n WAFFO_PRODUCT_ID=PROD_0pcnzzT4nalEkkcdyIUoD5 WAFFO_PRODUCT_ID_YEARLY=PROD_2WmkUVoYWt0NN8OVEyC6n3 WAFFO_PRODUCT_ID_PERPETUAL=PROD_0pcnzzT4nalEkkcdyIUoD5 -WAFFO_CURRENCY=CNY +WAFFO_CURRENCY=USD # test | live(test 时自动附加 test=true) WAFFO_ENVIRONMENT=test # 支付成功回跳(桌面端 deep link;CreateOrder/Checkout 的 return_url 可覆盖) diff --git a/backend/internal/controller/order/order_controller.go b/backend/internal/controller/order/order_controller.go index a5e996d..87ea4e6 100644 --- a/backend/internal/controller/order/order_controller.go +++ b/backend/internal/controller/order/order_controller.go @@ -113,6 +113,16 @@ func (ctrl *OrderController) PaymentWebhook(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"code": 0, "message": "Webhook processed"}) } +// WaffoWebhookReady GET/HEAD probe for dashboard URL checks (browser opens as GET). // Logan.Li +func (ctrl *OrderController) WaffoWebhookReady(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "message": "waffo webhook ready", + "methods": []string{"POST"}, + "hint": "Payment events must POST JSON with order_no / orderNo", + }) +} + // WaffoWebhook accepts loosely-shaped Waffo payment events and maps to PaymentWebhook. // Logan.Li func (ctrl *OrderController) WaffoWebhook(c *gin.Context) { body, err := io.ReadAll(c.Request.Body) diff --git a/backend/internal/service/payment/waffo.go b/backend/internal/service/payment/waffo.go index 4bf48ac..64a3bcd 100644 --- a/backend/internal/service/payment/waffo.go +++ b/backend/internal/service/payment/waffo.go @@ -31,7 +31,7 @@ func LoadWaffoConfig() WaffoConfig { } currency := strings.TrimSpace(os.Getenv("WAFFO_CURRENCY")) if currency == "" { - currency = "CNY" + currency = "USD" } defaultProduct := strings.TrimSpace(os.Getenv("WAFFO_PRODUCT_ID")) yearly := strings.TrimSpace(os.Getenv("WAFFO_PRODUCT_ID_YEARLY")) diff --git a/backend/internal/service/payment/waffo_test.go b/backend/internal/service/payment/waffo_test.go index 33b7753..9f7c620 100644 --- a/backend/internal/service/payment/waffo_test.go +++ b/backend/internal/service/payment/waffo_test.go @@ -11,7 +11,7 @@ func TestBuildCheckoutURL_YearlySubscription(t *testing.T) { StoreSlug: "opsxshell-pwsi6m4n", ProductIDYearly: "PROD_2WmkUVoYWt0NN8OVEyC6n3", ProductIDPerpetual: "PROD_0pcnzzT4nalEkkcdyIUoD5", - Currency: "CNY", + Currency: "USD", Environment: "test", SuccessURL: "opsxshell://pro/activated", } @@ -30,7 +30,7 @@ func TestBuildCheckoutURL_YearlySubscription(t *testing.T) { if q.Get("type") != "subscription" { t.Fatalf("type=%s want subscription", q.Get("type")) } - if q.Get("currency") != "CNY" { + if q.Get("currency") != "USD" { t.Fatalf("currency=%s", q.Get("currency")) } if q.Get("test") != "true" { @@ -43,7 +43,7 @@ func TestBuildCheckoutURL_PerpetualOnetime(t *testing.T) { StoreSlug: "opsxshell-pwsi6m4n", ProductIDYearly: "PROD_2WmkUVoYWt0NN8OVEyC6n3", ProductIDPerpetual: "PROD_0pcnzzT4nalEkkcdyIUoD5", - Currency: "CNY", + Currency: "USD", Environment: "test", SuccessURL: "opsxshell://pro/activated", } diff --git a/backend/router/router.go b/backend/router/router.go index 78f7b2a..bba80dc 100644 --- a/backend/router/router.go +++ b/backend/router/router.go @@ -109,6 +109,7 @@ func SetupRouter(db *gorm.DB, cfg *config.Config) *gin.Engine { register(clientAPI, "POST", "/checkout", orderController.Checkout) register(clientAPI, "POST", "/purchase/claim", orderController.ClaimPurchase) register(clientAPI, "POST", "/webhooks/payment", orderController.PaymentWebhook) + register(clientAPI, "GET", "/webhooks/waffo", orderController.WaffoWebhookReady) register(clientAPI, "POST", "/webhooks/waffo", orderController.WaffoWebhook) register(clientAPI, "POST", "/purchase/check", orderController.CheckDuplicatePurchase) register(clientAPI, "POST", "/purchase/status", orderController.CheckPurchaseStatus)