Commit 79396745 by zhongyuanzhao-alt Committed by GitHub

fix: add Waffo goods info and webhook SDK update (#5704)

* fix: add Waffo goods info and webhook SDK update

* chore: remove Waffo test code from PR
parent 9ba251ce
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"io" "io"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/QuantumNous/new-api/common" "github.com/QuantumNous/new-api/common"
...@@ -59,6 +60,17 @@ func getWaffoCurrency() string { ...@@ -59,6 +60,17 @@ func getWaffoCurrency() string {
return "USD" return "USD"
} }
func buildWaffoTopUpGoodsInfo(amount int64) *order.GoodsInfo {
appName := strings.TrimSpace(common.SystemName)
if appName == "" {
appName = "New API"
}
return &order.GoodsInfo{
GoodsName: fmt.Sprintf("Recharge %d credits", amount),
AppName: appName,
}
}
// zeroDecimalCurrencies 零小数位币种,金额不能带小数点 // zeroDecimalCurrencies 零小数位币种,金额不能带小数点
var zeroDecimalCurrencies = map[string]bool{ var zeroDecimalCurrencies = map[string]bool{
"IDR": true, "JPY": true, "KRW": true, "VND": true, "IDR": true, "JPY": true, "KRW": true, "VND": true,
...@@ -242,12 +254,13 @@ func RequestWaffoPay(c *gin.Context) { ...@@ -242,12 +254,13 @@ func RequestWaffoPay(c *gin.Context) {
} }
currency := getWaffoCurrency() currency := getWaffoCurrency()
goodsInfo := buildWaffoTopUpGoodsInfo(req.Amount)
createParams := &order.CreateOrderParams{ createParams := &order.CreateOrderParams{
PaymentRequestID: paymentRequestId, PaymentRequestID: paymentRequestId,
MerchantOrderID: merchantOrderId, MerchantOrderID: merchantOrderId,
OrderAmount: formatWaffoAmount(payMoney, currency), OrderAmount: formatWaffoAmount(payMoney, currency),
OrderCurrency: currency, OrderCurrency: currency,
OrderDescription: fmt.Sprintf("Recharge %d credits", req.Amount), OrderDescription: goodsInfo.GoodsName,
OrderRequestedAt: time.Now().UTC().Format("2006-01-02T15:04:05.000Z"), OrderRequestedAt: time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
NotifyURL: notifyUrl, NotifyURL: notifyUrl,
MerchantInfo: &order.MerchantInfo{ MerchantInfo: &order.MerchantInfo{
...@@ -263,6 +276,7 @@ func RequestWaffoPay(c *gin.Context) { ...@@ -263,6 +276,7 @@ func RequestWaffoPay(c *gin.Context) {
PayMethodType: resolvedPayMethodType, PayMethodType: resolvedPayMethodType,
PayMethodName: resolvedPayMethodName, PayMethodName: resolvedPayMethodName,
}, },
GoodsInfo: goodsInfo,
SuccessRedirectURL: returnUrl, SuccessRedirectURL: returnUrl,
FailedRedirectURL: returnUrl, FailedRedirectURL: returnUrl,
} }
......
...@@ -46,7 +46,7 @@ require ( ...@@ -46,7 +46,7 @@ require (
github.com/tidwall/gjson v1.18.0 github.com/tidwall/gjson v1.18.0
github.com/tidwall/sjson v1.2.5 github.com/tidwall/sjson v1.2.5
github.com/tiktoken-go/tokenizer v0.6.2 github.com/tiktoken-go/tokenizer v0.6.2
github.com/waffo-com/waffo-go v1.3.1 github.com/waffo-com/waffo-go v1.3.2
github.com/yapingcat/gomedia v0.0.0-20240906162731-17feea57090c github.com/yapingcat/gomedia v0.0.0-20240906162731-17feea57090c
golang.org/x/crypto v0.48.0 golang.org/x/crypto v0.48.0
golang.org/x/image v0.38.0 golang.org/x/image v0.38.0
......
...@@ -1994,6 +1994,8 @@ github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1 ...@@ -1994,6 +1994,8 @@ github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/waffo-com/waffo-go v1.3.1 h1:NCYD3oQ59DTJj1bwS5T/659LI4h8PuAIW4Qj/w7fKPw= github.com/waffo-com/waffo-go v1.3.1 h1:NCYD3oQ59DTJj1bwS5T/659LI4h8PuAIW4Qj/w7fKPw=
github.com/waffo-com/waffo-go v1.3.1/go.mod h1:IaXVYq6mmYtrLFFsLxPslNwuIZx0mIadWWjhe+eWb0g= github.com/waffo-com/waffo-go v1.3.1/go.mod h1:IaXVYq6mmYtrLFFsLxPslNwuIZx0mIadWWjhe+eWb0g=
github.com/waffo-com/waffo-go v1.3.2 h1:HCaG7hPcj4vGIW5rJ4J8DI6BHuvO4Nt0ChsQc39pazs=
github.com/waffo-com/waffo-go v1.3.2/go.mod h1:IaXVYq6mmYtrLFFsLxPslNwuIZx0mIadWWjhe+eWb0g=
github.com/waffo-com/waffo-pancake-sdk-go v0.3.1 h1:ngQSN/oVB35xTwFPLfg++bxPC+SptcF145Mb6c62YCc= github.com/waffo-com/waffo-pancake-sdk-go v0.3.1 h1:ngQSN/oVB35xTwFPLfg++bxPC+SptcF145Mb6c62YCc=
github.com/waffo-com/waffo-pancake-sdk-go v0.3.1/go.mod h1:OB2MyFIQaefoPO0FV3J+yu9sDP8RVFQ+sbFsXqGuObc= github.com/waffo-com/waffo-pancake-sdk-go v0.3.1/go.mod h1:OB2MyFIQaefoPO0FV3J+yu9sDP8RVFQ+sbFsXqGuObc=
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment