优化结构
This commit is contained in:
@@ -4,11 +4,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"kra/internal/biz/system"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
|
||||
"github.com/go-pay/gopay"
|
||||
"github.com/go-pay/gopay/saobei"
|
||||
)
|
||||
@@ -35,7 +34,7 @@ func (a *saobeiAdapter) client(c map[string]any) (saobeiClient, error) {
|
||||
return saobei.NewClient(text(c, "inst_no"), text(c, "key"), text(c, "merchant_no"), text(c, "terminal_id"), text(c, "access_token"), !strings.EqualFold(text(c, "environment"), "sandbox"))
|
||||
}
|
||||
|
||||
func (a *saobeiAdapter) Create(ctx context.Context, req *biz.PaymentRequest, c map[string]any) (*biz.PaymentResult, error) {
|
||||
func (a *saobeiAdapter) Create(ctx context.Context, req *system.PaymentRequest, c map[string]any) (*system.PaymentResult, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("扫呗支付下单请求为空")
|
||||
}
|
||||
@@ -70,7 +69,7 @@ func (a *saobeiAdapter) Create(ctx context.Context, req *biz.PaymentRequest, c m
|
||||
if strings.TrimSpace(rsp.ResultCode) == saobei.ResultCodePaying {
|
||||
status = "pending"
|
||||
}
|
||||
return &biz.PaymentResult{Provider: biz.PaymentSaobei, Status: status, TradeNo: req.TradeNo, QueryID: strings.TrimSpace(rsp.OutTradeNo), Payload: mustJSON(rsp)}, nil
|
||||
return &system.PaymentResult{Provider: system.PaymentSaobei, Status: status, TradeNo: req.TradeNo, QueryID: strings.TrimSpace(rsp.OutTradeNo), Payload: mustJSON(rsp)}, nil
|
||||
}
|
||||
rsp, err := client.MiniPay(ctx, bm)
|
||||
if err != nil {
|
||||
@@ -82,7 +81,7 @@ func (a *saobeiAdapter) Create(ctx context.Context, req *biz.PaymentRequest, c m
|
||||
if strings.TrimSpace(rsp.OutTradeNo) == "" {
|
||||
return nil, errors.New("扫呗支付下单响应缺少 out_trade_no")
|
||||
}
|
||||
return &biz.PaymentResult{Provider: biz.PaymentSaobei, Status: "client_pending", TradeNo: req.TradeNo, QueryID: strings.TrimSpace(rsp.OutTradeNo), Payload: mustJSON(rsp)}, nil
|
||||
return &system.PaymentResult{Provider: system.PaymentSaobei, Status: "client_pending", TradeNo: req.TradeNo, QueryID: strings.TrimSpace(rsp.OutTradeNo), Payload: mustJSON(rsp)}, nil
|
||||
}
|
||||
|
||||
func saobeiCreateMethod(extra, config map[string]any) (string, error) {
|
||||
@@ -101,7 +100,7 @@ func saobeiCreateMethod(extra, config map[string]any) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *saobeiAdapter) Query(ctx context.Context, tradeNo string, c map[string]any) (*biz.PaymentResult, error) {
|
||||
func (a *saobeiAdapter) Query(ctx context.Context, tradeNo string, c map[string]any) (*system.PaymentResult, error) {
|
||||
tradeNo = strings.TrimSpace(tradeNo)
|
||||
if tradeNo == "" {
|
||||
return nil, errors.New("扫呗支付查单缺少 out_trade_no")
|
||||
@@ -141,7 +140,7 @@ func (a *saobeiAdapter) Query(ctx context.Context, tradeNo string, c map[string]
|
||||
if strings.TrimSpace(rsp.ResultCode) == saobei.ResultCodePaying {
|
||||
status = "pending"
|
||||
}
|
||||
result := &biz.PaymentResult{Provider: biz.PaymentSaobei, Status: status, TradeNo: tradeNoResult, ProviderTradeNo: strings.TrimSpace(rsp.ChannelTradeNo), QueryID: queryID, Payload: mustJSON(rsp), Currency: strings.ToUpper(firstAnyOr(c, "CNY", "currency", "default_currency"))}
|
||||
result := &system.PaymentResult{Provider: system.PaymentSaobei, Status: status, TradeNo: tradeNoResult, ProviderTradeNo: strings.TrimSpace(rsp.ChannelTradeNo), QueryID: queryID, Payload: mustJSON(rsp), Currency: strings.ToUpper(firstAnyOr(c, "CNY", "currency", "default_currency"))}
|
||||
if rsp.TotalFee != "" {
|
||||
result.Amount, err = parseIntegerAmount(rsp.TotalFee)
|
||||
if err != nil {
|
||||
@@ -162,7 +161,7 @@ func (a *saobeiAdapter) Query(ctx context.Context, tradeNo string, c map[string]
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (a *saobeiAdapter) Refund(ctx context.Context, req *biz.PaymentRefundRequest, c map[string]any) (*biz.PaymentResult, error) {
|
||||
func (a *saobeiAdapter) Refund(ctx context.Context, req *system.PaymentRefundRequest, c map[string]any) (*system.PaymentResult, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("扫呗支付退款请求为空")
|
||||
}
|
||||
@@ -215,9 +214,9 @@ func (a *saobeiAdapter) Refund(ctx context.Context, req *biz.PaymentRefundReques
|
||||
if refundAmount != req.Amount {
|
||||
return nil, errors.New("扫呗支付退款响应金额不匹配")
|
||||
}
|
||||
return &biz.PaymentResult{Provider: biz.PaymentSaobei, Status: "pending", TradeNo: tradeNo, ProviderTradeNo: providerRefundID, Amount: refundAmount, Currency: strings.ToUpper(req.Currency), Payload: mustJSON(rsp)}, nil
|
||||
return &system.PaymentResult{Provider: system.PaymentSaobei, Status: "pending", TradeNo: tradeNo, ProviderTradeNo: providerRefundID, Amount: refundAmount, Currency: strings.ToUpper(req.Currency), Payload: mustJSON(rsp)}, nil
|
||||
}
|
||||
|
||||
func (a *saobeiAdapter) Callback(_ context.Context, _ *biz.PaymentCallback, _ map[string]any) (*biz.PaymentResult, error) {
|
||||
func (a *saobeiAdapter) Callback(_ context.Context, _ *system.PaymentCallback, _ map[string]any) (*system.PaymentResult, error) {
|
||||
return nil, errors.New("扫呗支付回调没有可复用的 GoPay 验签器,请改用主动查单")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user