优化结构

This commit is contained in:
Yvan
2026-08-22 12:13:16 +08:00
parent d987244d0e
commit b27a66e9d3
200 changed files with 1794 additions and 1715 deletions
+11 -12
View File
@@ -3,13 +3,12 @@ package payment
import (
"context"
"encoding/json"
"kra/internal/biz/system"
"net/http"
"net/http/httptest"
"strings"
"testing"
"kra/internal/biz"
"github.com/go-pay/gopay/paypal"
)
@@ -52,7 +51,7 @@ func TestPayPalCreateAndQueryKeepOrderAndCaptureIDsSeparate(t *testing.T) {
adapter := &paypalAdapter{}
config := paypalTestConfig(server.URL)
created, err := adapter.Create(context.Background(), &biz.PaymentRequest{
created, err := adapter.Create(context.Background(), &system.PaymentRequest{
TradeNo: "LOCAL-1",
Subject: "Order one",
Amount: 1099,
@@ -143,7 +142,7 @@ func TestPayPalCreateRejectsMismatchedResponseIdentityAndAmount(t *testing.T) {
}))
defer server.Close()
_, err := (&paypalAdapter{}).Create(context.Background(), &biz.PaymentRequest{
_, err := (&paypalAdapter{}).Create(context.Background(), &system.PaymentRequest{
TradeNo: "LOCAL-1", Subject: "Order one", Amount: 1099, Currency: "USD",
}, paypalTestConfig(server.URL))
if err == nil || !strings.Contains(err.Error(), tc.want) {
@@ -243,8 +242,8 @@ func TestPayPalRefundUsesPersistedCaptureID(t *testing.T) {
config := paypalTestConfig(server.URL)
config["provider_trade_no"] = "WRONG-CONFIG-CAPTURE"
result, err := (&paypalAdapter{}).Refund(context.Background(), &biz.PaymentRefundRequest{
Provider: biz.PaymentPayPal, TradeNo: "LOCAL-1", ProviderTradeNo: "CAPTURE-1",
result, err := (&paypalAdapter{}).Refund(context.Background(), &system.PaymentRefundRequest{
Provider: system.PaymentPayPal, TradeNo: "LOCAL-1", ProviderTradeNo: "CAPTURE-1",
QueryID: "ORDER-1", RefundNo: "REFUND-1", Amount: 123, TotalAmount: 1099, Currency: "USD",
}, config)
if err != nil {
@@ -287,8 +286,8 @@ func TestPayPalRefundResolvesCaptureFromPersistedQueryID(t *testing.T) {
config := paypalTestConfig(server.URL)
config["capture_id"] = "WRONG-CONFIG-CAPTURE"
result, err := (&paypalAdapter{}).Refund(context.Background(), &biz.PaymentRefundRequest{
Provider: biz.PaymentPayPal, TradeNo: "LOCAL-1", QueryID: "ORDER-1",
result, err := (&paypalAdapter{}).Refund(context.Background(), &system.PaymentRefundRequest{
Provider: system.PaymentPayPal, TradeNo: "LOCAL-1", QueryID: "ORDER-1",
RefundNo: "REFUND-2", Amount: 123, TotalAmount: 1099, Currency: "USD",
}, config)
if err != nil {
@@ -302,8 +301,8 @@ func TestPayPalRefundResolvesCaptureFromPersistedQueryID(t *testing.T) {
func TestPayPalRefundRejectsStaticCaptureIDWithoutDurableIdentity(t *testing.T) {
config := paypalTestConfig("https://paypal.invalid")
config["capture_id"] = "CONFIG-CAPTURE"
_, err := (&paypalAdapter{}).Refund(context.Background(), &biz.PaymentRefundRequest{
Provider: biz.PaymentPayPal, TradeNo: "LOCAL-1", RefundNo: "REFUND-1", Amount: 123, Currency: "USD",
_, err := (&paypalAdapter{}).Refund(context.Background(), &system.PaymentRefundRequest{
Provider: system.PaymentPayPal, TradeNo: "LOCAL-1", RefundNo: "REFUND-1", Amount: 123, Currency: "USD",
}, config)
if err == nil {
t.Fatal("Refund() accepted a static config capture ID")
@@ -311,7 +310,7 @@ func TestPayPalRefundRejectsStaticCaptureIDWithoutDurableIdentity(t *testing.T)
}
func TestPayPalRefundResultBindsRefundIdentity(t *testing.T) {
req := &biz.PaymentRefundRequest{TradeNo: "LOCAL-1", RefundNo: "REFUND-1", Amount: 123, Currency: "USD"}
req := &system.PaymentRefundRequest{TradeNo: "LOCAL-1", RefundNo: "REFUND-1", Amount: 123, Currency: "USD"}
base := func() *paypal.PaymentCaptureRefund {
return &paypal.PaymentCaptureRefund{
Id: "PAYPAL-REFUND-1", InvoiceId: "REFUND-1", Status: "PENDING",
@@ -368,7 +367,7 @@ func TestPayPalCallbackUsesGoPayWebhookVerification(t *testing.T) {
}`)
config := paypalTestConfig(server.URL)
config["webhook_id"] = "HOOK-1"
result, err := (&paypalAdapter{}).Callback(context.Background(), &biz.PaymentCallback{
result, err := (&paypalAdapter{}).Callback(context.Background(), &system.PaymentCallback{
Body: body,
Headers: map[string]string{
"Paypal-Auth-Algo": "SHA256withRSA",