支持后台支付配置管理
This commit is contained in:
@@ -16,8 +16,6 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/config"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -26,10 +24,22 @@ var (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
cfg config.LeshuaPaymentConfig
|
||||
cfg Config
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
GatewayURL string
|
||||
MerchantID string
|
||||
SignKey string
|
||||
NotifyKey string
|
||||
NotifyURL string
|
||||
JumpURL string
|
||||
PayWay string
|
||||
JSPayFlag string
|
||||
SignType string
|
||||
}
|
||||
|
||||
type CreatePaymentRequest struct {
|
||||
ThirdOrderID string
|
||||
AmountCent int64
|
||||
@@ -131,7 +141,7 @@ type VerifyNotifyResult struct {
|
||||
ParamKeys []string
|
||||
}
|
||||
|
||||
func NewClient(cfg config.LeshuaPaymentConfig) *Client {
|
||||
func NewClient(cfg Config) *Client {
|
||||
return &Client{
|
||||
cfg: cfg,
|
||||
httpClient: &http.Client{
|
||||
@@ -234,11 +244,11 @@ func (c *Client) CreateRefund(ctx context.Context, req CreateRefundRequest) (*Cr
|
||||
return nil, nil, err
|
||||
}
|
||||
params := map[string]string{
|
||||
"service": "unified_refund",
|
||||
"merchant_id": c.cfg.MerchantID,
|
||||
"service": "unified_refund",
|
||||
"merchant_id": c.cfg.MerchantID,
|
||||
"merchant_refund_id": req.MerchantRefundID,
|
||||
"refund_amount": fmt.Sprintf("%d", req.RefundAmountCent),
|
||||
"nonce_str": Nonce(32),
|
||||
"refund_amount": fmt.Sprintf("%d", req.RefundAmountCent),
|
||||
"nonce_str": Nonce(32),
|
||||
}
|
||||
if req.LeshuaOrderID != "" {
|
||||
params["leshua_order_id"] = req.LeshuaOrderID
|
||||
|
||||
@@ -3,8 +3,6 @@ package leshua
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"hfb_sys/backend/internal/config"
|
||||
)
|
||||
|
||||
func TestSignUsesASCIISortedNonEmptyParams(t *testing.T) {
|
||||
@@ -32,7 +30,7 @@ func TestSignUsesASCIISortedNonEmptyParams(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyNotifyIncludesEmptyAndExcludesErrorCode(t *testing.T) {
|
||||
client := NewClient(config.LeshuaPaymentConfig{NotifyKey: "notify-secret"})
|
||||
client := NewClient(Config{NotifyKey: "notify-secret"})
|
||||
params := map[string]string{
|
||||
"merchant_id": "1234567890",
|
||||
"third_order_id": "NO1",
|
||||
@@ -59,7 +57,7 @@ func TestVerifyNotifyIncludesEmptyAndExcludesErrorCode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyNotifyDoesNotFallBackToSignKey(t *testing.T) {
|
||||
client := NewClient(config.LeshuaPaymentConfig{
|
||||
client := NewClient(Config{
|
||||
NotifyKey: "wrong-notify-secret",
|
||||
SignKey: "sign-secret",
|
||||
})
|
||||
@@ -85,7 +83,7 @@ func TestVerifyNotifyDoesNotFallBackToSignKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyNotifyUsesDocumentedNotifySignature(t *testing.T) {
|
||||
client := NewClient(config.LeshuaPaymentConfig{NotifyKey: "notify-secret"})
|
||||
client := NewClient(Config{NotifyKey: "notify-secret"})
|
||||
params := map[string]string{
|
||||
"merchant_id": "1234567890",
|
||||
"third_order_id": "NO1",
|
||||
@@ -109,7 +107,7 @@ func TestVerifyNotifyUsesDocumentedNotifySignature(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyNotifyKeepsEmptyXMLFieldsInSignature(t *testing.T) {
|
||||
client := NewClient(config.LeshuaPaymentConfig{NotifyKey: "notify-secret"})
|
||||
client := NewClient(Config{NotifyKey: "notify-secret"})
|
||||
params, err := ParsePayload([]byte(`<leshua>
|
||||
<amount>100</amount>
|
||||
<goods_tag></goods_tag>
|
||||
@@ -190,7 +188,7 @@ func TestSignRefundUsesSameAlgorithm(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyRefundNotify(t *testing.T) {
|
||||
client := NewClient(config.LeshuaPaymentConfig{NotifyKey: "notify-secret"})
|
||||
client := NewClient(Config{NotifyKey: "notify-secret"})
|
||||
params := map[string]string{
|
||||
"merchant_id": "1234567890",
|
||||
"third_order_id": "NO1",
|
||||
|
||||
Reference in New Issue
Block a user