feat: add Airwallex payments and multi-currency support
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -60,6 +61,12 @@ func (h *PaymentWebhookHandler) StripeWebhook(c *gin.Context) {
|
||||
h.handleNotify(c, payment.TypeStripe)
|
||||
}
|
||||
|
||||
// AirwallexWebhook 处理空中云汇 Webhook 事件。
|
||||
// POST /api/v1/payment/webhook/airwallex
|
||||
func (h *PaymentWebhookHandler) AirwallexWebhook(c *gin.Context) {
|
||||
h.handleNotify(c, payment.TypeAirwallex)
|
||||
}
|
||||
|
||||
// handleNotify is the shared logic for all provider webhook handlers.
|
||||
func (h *PaymentWebhookHandler) handleNotify(c *gin.Context, providerKey string) {
|
||||
var rawBody string
|
||||
@@ -146,6 +153,17 @@ func extractOutTradeNo(rawBody, providerKey string) string {
|
||||
if err == nil {
|
||||
return values.Get("out_trade_no")
|
||||
}
|
||||
case payment.TypeAirwallex:
|
||||
var payload struct {
|
||||
Data struct {
|
||||
Object struct {
|
||||
MerchantOrderID string `json:"merchant_order_id"`
|
||||
} `json:"object"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(rawBody), &payload); err == nil {
|
||||
return strings.TrimSpace(payload.Data.Object.MerchantOrderID)
|
||||
}
|
||||
}
|
||||
// For other providers (Stripe, Alipay direct, WxPay direct), the registry
|
||||
// typically has only one instance, so no instance lookup is needed.
|
||||
@@ -183,14 +201,14 @@ const (
|
||||
wxpaySuccessMessage = "成功"
|
||||
)
|
||||
|
||||
// writeSuccessResponse sends the provider-specific success response.
|
||||
// WeChat Pay requires JSON {"code":"SUCCESS","message":"成功"};
|
||||
// Stripe expects an empty 200; others accept plain text "success".
|
||||
// writeSuccessResponse 返回各支付服务商要求的成功响应。
|
||||
// 微信支付需要 JSON {"code":"SUCCESS","message":"成功"};
|
||||
// Stripe 和空中云汇接受空 200,其它服务商接受纯文本 "success"。
|
||||
func writeSuccessResponse(c *gin.Context, providerKey string) {
|
||||
switch providerKey {
|
||||
case payment.TypeWxpay:
|
||||
c.JSON(http.StatusOK, wxpaySuccessResponse{Code: wxpaySuccessCode, Message: wxpaySuccessMessage})
|
||||
case payment.TypeStripe:
|
||||
case payment.TypeStripe, payment.TypeAirwallex:
|
||||
c.String(http.StatusOK, "")
|
||||
default:
|
||||
c.String(http.StatusOK, "success")
|
||||
|
||||
Reference in New Issue
Block a user