支付相关

This commit is contained in:
Yvan
2026-08-20 12:21:08 +08:00
parent e54cbd1207
commit b88c220e20
42 changed files with 6173 additions and 274 deletions
+32 -2
View File
@@ -17,6 +17,7 @@ import (
const (
PaymentAlipay = "alipay"
PaymentAlipayV3 = "alipay-v3"
PaymentWechatV2 = "wechat-v2"
PaymentWechatV3 = "wechat-v3"
PaymentApple = "apple-iap"
@@ -40,7 +41,7 @@ const (
)
var SupportedPaymentProviders = []string{
PaymentAlipay, PaymentWechatV2, PaymentWechatV3, PaymentApple,
PaymentAlipay, PaymentAlipayV3, PaymentWechatV2, PaymentWechatV3, PaymentApple,
PaymentChinaums, PaymentSFT, PaymentSuperPay, PaymentWechatGame, PaymentDouyinGame,
PaymentDouyin, PaymentQQ, PaymentAllinPay, PaymentLakala, PaymentPayPal, PaymentSaobei,
}
@@ -228,7 +229,7 @@ func DefaultPaymentCallbackAck(provider string, success bool) PaymentCallbackAck
status = 500
}
switch provider {
case PaymentAlipay:
case PaymentAlipay, PaymentAlipayV3:
body := "success"
if !success {
body = "failure"
@@ -1071,6 +1072,35 @@ func validatePaymentConfirmation(intent *PaymentIntent, provider, tradeNo string
if strings.TrimSpace(intent.BusinessType) == "" || strings.TrimSpace(intent.BusinessID) == "" {
return errors.New("支付业务标识不完整")
}
if provider == PaymentApple {
if err := validateAppleProduct(intent.Extra, result.Payload); err != nil {
return err
}
}
return nil
}
func validateAppleProduct(intentExtra, providerPayload json.RawMessage) error {
var expected struct {
ProductID string `json:"product_id"`
}
if err := json.Unmarshal(intentExtra, &expected); err != nil {
return errors.New("Apple 支付订单商品配置无效")
}
expected.ProductID = strings.TrimSpace(expected.ProductID)
if expected.ProductID == "" {
return errors.New("Apple 支付订单缺少 product_id")
}
var actual struct {
ProductID string `json:"productId"`
}
if err := json.Unmarshal(providerPayload, &actual); err != nil {
return errors.New("Apple 交易载荷无效")
}
actual.ProductID = strings.TrimSpace(actual.ProductID)
if actual.ProductID == "" || actual.ProductID != expected.ProductID {
return errors.New("Apple 交易 productId 与业务订单不匹配")
}
return nil
}