add payment type field (alipay/wxpay) to EPay config

This commit is contained in:
Ember Moth 2025-10-15 20:55:57 +08:00 committed by Leif Draven
parent 643d234a88
commit 8b48286365
6 changed files with 26 additions and 19 deletions

View File

@ -57,7 +57,7 @@ func (l *EPayNotifyLogic) EPayNotify(req *types.EPayNotifyRequest) error {
return err return err
} }
// Verify sign // Verify sign
client := epay.NewClient(config.Pid, config.Url, config.Key) client := epay.NewClient(config.Pid, config.Url, config.Key, config.Type)
if !client.VerifySign(urlParamsToMap(l.ctx.Request.URL.RawQuery)) && !l.svcCtx.Config.Debug { if !client.VerifySign(urlParamsToMap(l.ctx.Request.URL.RawQuery)) && !l.svcCtx.Config.Debug {
l.Logger.Error("[EPayNotify] Verify sign failed") l.Logger.Error("[EPayNotify] Verify sign failed")
return nil return nil

View File

@ -267,7 +267,7 @@ func (l *PurchaseCheckoutLogic) epayPayment(config *payment.Payment, info *order
return "", errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Unmarshal error: %s", err.Error()) return "", errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Unmarshal error: %s", err.Error())
} }
// Initialize EPay client with merchant credentials // Initialize EPay client with merchant credentials
client := epay.NewClient(epayConfig.Pid, epayConfig.Url, epayConfig.Key) client := epay.NewClient(epayConfig.Pid, epayConfig.Url, epayConfig.Key, epayConfig.Type)
// Convert order amount to CNY using current exchange rate // Convert order amount to CNY using current exchange rate
amount, err := l.queryExchangeRate("CNY", info.Amount) amount, err := l.queryExchangeRate("CNY", info.Amount)
@ -309,7 +309,7 @@ func (l *PurchaseCheckoutLogic) CryptoSaaSPayment(config *payment.Payment, info
return "", errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Unmarshal error: %s", err.Error()) return "", errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Unmarshal error: %s", err.Error())
} }
// Initialize EPay client with merchant credentials // Initialize EPay client with merchant credentials
client := epay.NewClient(epayConfig.AccountID, epayConfig.Endpoint, epayConfig.SecretKey) client := epay.NewClient(epayConfig.AccountID, epayConfig.Endpoint, epayConfig.SecretKey, epayConfig.Type)
// Convert order amount to CNY using current exchange rate // Convert order amount to CNY using current exchange rate
amount, err := l.queryExchangeRate("CNY", info.Amount) amount, err := l.queryExchangeRate("CNY", info.Amount)

View File

@ -85,9 +85,10 @@ func (l *AlipayF2FConfig) Unmarshal(data []byte) error {
} }
type EPayConfig struct { type EPayConfig struct {
Pid string `json:"pid"` Pid string `json:"pid"`
Url string `json:"url"` Url string `json:"url"`
Key string `json:"key"` Key string `json:"key"`
Type string `json:"type"`
} }
func (l *EPayConfig) Marshal() ([]byte, error) { func (l *EPayConfig) Marshal() ([]byte, error) {
@ -109,6 +110,7 @@ type CryptoSaaSConfig struct {
Endpoint string `json:"endpoint"` Endpoint string `json:"endpoint"`
AccountID string `json:"account_id"` AccountID string `json:"account_id"`
SecretKey string `json:"secret_key"` SecretKey string `json:"secret_key"`
Type string `json:"type"`
} }
func (l *CryptoSaaSConfig) Marshal() ([]byte, error) { func (l *CryptoSaaSConfig) Marshal() ([]byte, error) {

View File

@ -14,9 +14,10 @@ import (
) )
type Client struct { type Client struct {
Pid string Pid string
Url string Url string
Key string Key string
Type string
} }
type Order struct { type Order struct {
@ -37,11 +38,12 @@ type queryOrderStatusResponse struct {
Status int `json:"status"` Status int `json:"status"`
} }
func NewClient(pid, url, key string) *Client { func NewClient(pid, url, key string, Type string) *Client {
return &Client{ return &Client{
Pid: pid, Pid: pid,
Url: url, Url: url,
Key: key, Key: key,
Type: Type,
} }
} }
@ -53,6 +55,7 @@ func (c *Client) CreatePayUrl(order Order) string {
params.Set("notify_url", order.NotifyUrl) params.Set("notify_url", order.NotifyUrl)
params.Set("out_trade_no", order.OrderNo) params.Set("out_trade_no", order.OrderNo)
params.Set("pid", c.Pid) params.Set("pid", c.Pid)
params.Set("type", c.Type)
params.Set("return_url", order.ReturnUrl) params.Set("return_url", order.ReturnUrl)
// Generate the sign using the CreateSign function // Generate the sign using the CreateSign function
@ -117,6 +120,7 @@ func (c *Client) structToMap(order Order) map[string]string {
result["notify_url"] = order.NotifyUrl result["notify_url"] = order.NotifyUrl
result["out_trade_no"] = order.OrderNo result["out_trade_no"] = order.OrderNo
result["pid"] = c.Pid result["pid"] = c.Pid
result["type"] = c.Type
result["return_url"] = order.ReturnUrl result["return_url"] = order.ReturnUrl
return result return result
} }

View File

@ -3,7 +3,7 @@ package epay
import "testing" import "testing"
func TestEpay(t *testing.T) { func TestEpay(t *testing.T) {
client := NewClient("", "http://127.0.0.1", "") client := NewClient("", "http://127.0.0.1", "", "")
order := Order{ order := Order{
Name: "测试", Name: "测试",
OrderNo: "123456789", OrderNo: "123456789",
@ -19,7 +19,7 @@ func TestEpay(t *testing.T) {
func TestQueryOrderStatus(t *testing.T) { func TestQueryOrderStatus(t *testing.T) {
t.Skipf("Skip TestQueryOrderStatus test") t.Skipf("Skip TestQueryOrderStatus test")
client := NewClient("Pid", "Url", "Key") client := NewClient("Pid", "Url", "Key", "Type")
orderNo := "123456789" orderNo := "123456789"
status := client.QueryOrderStatus(orderNo) status := client.QueryOrderStatus(orderNo)
t.Logf("OrderNo: %s, Status: %v\n", orderNo, status) t.Logf("OrderNo: %s, Status: %v\n", orderNo, status)
@ -40,7 +40,7 @@ func TestVerifySign(t *testing.T) {
} }
key := "LbTabbB580zWyhXhyyww7wwvy5u8k0wl" key := "LbTabbB580zWyhXhyyww7wwvy5u8k0wl"
c := NewClient("Pid", "Url", key) c := NewClient("Pid", "Url", key, "Type")
if c.VerifySign(params) { if c.VerifySign(params) {
t.Logf("Sign verification success!") t.Logf("Sign verification success!")
} else { } else {

View File

@ -65,9 +65,10 @@ func GetSupportedPlatforms() []types.PlatformInfo {
Platform: EPay.String(), Platform: EPay.String(),
PlatformUrl: "", PlatformUrl: "",
PlatformFieldDescription: map[string]string{ PlatformFieldDescription: map[string]string{
"pid": "PID", "pid": "PID",
"url": "URL", "url": "URL",
"key": "Key", "key": "Key",
"type": "Type",
}, },
}, },
{ {