fix: update payment method handling in topup controller
- Refactored payment method validation to check against available methods. - Changed payment method types from "zfb" to "alipay" and "wx" to "wxpay" for consistency. - Updated the purchase request to use the validated payment method directly.
This commit is contained in:
@@ -97,14 +97,12 @@ func RequestEpay(c *gin.Context) {
|
|||||||
c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
|
c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
payType := "wxpay"
|
|
||||||
if req.PaymentMethod == "zfb" {
|
if !setting.ContainsPayMethod(req.PaymentMethod) {
|
||||||
payType = "alipay"
|
c.JSON(200, gin.H{"message": "error", "data": "支付方式不存在"})
|
||||||
}
|
return
|
||||||
if req.PaymentMethod == "wx" {
|
|
||||||
req.PaymentMethod = "wxpay"
|
|
||||||
payType = "wxpay"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callBackAddress := service.GetCallbackAddress()
|
callBackAddress := service.GetCallbackAddress()
|
||||||
returnUrl, _ := url.Parse(setting.ServerAddress + "/console/log")
|
returnUrl, _ := url.Parse(setting.ServerAddress + "/console/log")
|
||||||
notifyUrl, _ := url.Parse(callBackAddress + "/api/user/epay/notify")
|
notifyUrl, _ := url.Parse(callBackAddress + "/api/user/epay/notify")
|
||||||
@@ -116,7 +114,7 @@ func RequestEpay(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
uri, params, err := client.Purchase(&epay.PurchaseArgs{
|
uri, params, err := client.Purchase(&epay.PurchaseArgs{
|
||||||
Type: payType,
|
Type: req.PaymentMethod,
|
||||||
ServiceTradeNo: tradeNo,
|
ServiceTradeNo: tradeNo,
|
||||||
Name: fmt.Sprintf("TUC%d", req.Amount),
|
Name: fmt.Sprintf("TUC%d", req.Amount),
|
||||||
Money: strconv.FormatFloat(payMoney, 'f', 2, 64),
|
Money: strconv.FormatFloat(payMoney, 'f', 2, 64),
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ var PayMethods = []map[string]string{
|
|||||||
{
|
{
|
||||||
"name": "支付宝",
|
"name": "支付宝",
|
||||||
"color": "rgba(var(--semi-blue-5), 1)",
|
"color": "rgba(var(--semi-blue-5), 1)",
|
||||||
"type": "zfb",
|
"type": "alipay",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "微信",
|
"name": "微信",
|
||||||
"color": "rgba(var(--semi-green-5), 1)",
|
"color": "rgba(var(--semi-green-5), 1)",
|
||||||
"type": "wx",
|
"type": "wxpay",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user