优化结构

This commit is contained in:
Yvan
2026-08-22 15:53:14 +08:00
parent ca52de5db0
commit 491ed21d48
72 changed files with 746 additions and 695 deletions
+11 -11
View File
@@ -3,7 +3,7 @@ package payment
import (
"context"
"encoding/json"
"kra/internal/biz/system"
bizpayment "kra/internal/biz/payment"
"net/http"
"net/http/httptest"
"strings"
@@ -51,7 +51,7 @@ func TestPayPalCreateAndQueryKeepOrderAndCaptureIDsSeparate(t *testing.T) {
adapter := &paypalAdapter{}
config := paypalTestConfig(server.URL)
created, err := adapter.Create(context.Background(), &system.PaymentRequest{
created, err := adapter.Create(context.Background(), &bizpayment.PaymentRequest{
TradeNo: "LOCAL-1",
Subject: "Order one",
Amount: 1099,
@@ -142,7 +142,7 @@ func TestPayPalCreateRejectsMismatchedResponseIdentityAndAmount(t *testing.T) {
}))
defer server.Close()
_, err := (&paypalAdapter{}).Create(context.Background(), &system.PaymentRequest{
_, err := (&paypalAdapter{}).Create(context.Background(), &bizpayment.PaymentRequest{
TradeNo: "LOCAL-1", Subject: "Order one", Amount: 1099, Currency: "USD",
}, paypalTestConfig(server.URL))
if err == nil || !strings.Contains(err.Error(), tc.want) {
@@ -242,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(), &system.PaymentRefundRequest{
Provider: system.PaymentPayPal, TradeNo: "LOCAL-1", ProviderTradeNo: "CAPTURE-1",
result, err := (&paypalAdapter{}).Refund(context.Background(), &bizpayment.PaymentRefundRequest{
Provider: bizpayment.PaymentPayPal, TradeNo: "LOCAL-1", ProviderTradeNo: "CAPTURE-1",
QueryID: "ORDER-1", RefundNo: "REFUND-1", Amount: 123, TotalAmount: 1099, Currency: "USD",
}, config)
if err != nil {
@@ -286,8 +286,8 @@ func TestPayPalRefundResolvesCaptureFromPersistedQueryID(t *testing.T) {
config := paypalTestConfig(server.URL)
config["capture_id"] = "WRONG-CONFIG-CAPTURE"
result, err := (&paypalAdapter{}).Refund(context.Background(), &system.PaymentRefundRequest{
Provider: system.PaymentPayPal, TradeNo: "LOCAL-1", QueryID: "ORDER-1",
result, err := (&paypalAdapter{}).Refund(context.Background(), &bizpayment.PaymentRefundRequest{
Provider: bizpayment.PaymentPayPal, TradeNo: "LOCAL-1", QueryID: "ORDER-1",
RefundNo: "REFUND-2", Amount: 123, TotalAmount: 1099, Currency: "USD",
}, config)
if err != nil {
@@ -301,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(), &system.PaymentRefundRequest{
Provider: system.PaymentPayPal, TradeNo: "LOCAL-1", RefundNo: "REFUND-1", Amount: 123, Currency: "USD",
_, err := (&paypalAdapter{}).Refund(context.Background(), &bizpayment.PaymentRefundRequest{
Provider: bizpayment.PaymentPayPal, TradeNo: "LOCAL-1", RefundNo: "REFUND-1", Amount: 123, Currency: "USD",
}, config)
if err == nil {
t.Fatal("Refund() accepted a static config capture ID")
@@ -310,7 +310,7 @@ func TestPayPalRefundRejectsStaticCaptureIDWithoutDurableIdentity(t *testing.T)
}
func TestPayPalRefundResultBindsRefundIdentity(t *testing.T) {
req := &system.PaymentRefundRequest{TradeNo: "LOCAL-1", RefundNo: "REFUND-1", Amount: 123, Currency: "USD"}
req := &bizpayment.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",
@@ -367,7 +367,7 @@ func TestPayPalCallbackUsesGoPayWebhookVerification(t *testing.T) {
}`)
config := paypalTestConfig(server.URL)
config["webhook_id"] = "HOOK-1"
result, err := (&paypalAdapter{}).Callback(context.Background(), &system.PaymentCallback{
result, err := (&paypalAdapter{}).Callback(context.Background(), &bizpayment.PaymentCallback{
Body: body,
Headers: map[string]string{
"Paypal-Auth-Algo": "SHA256withRSA",