优化结构
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"kra/internal/biz/system"
|
||||
bizpayment "kra/internal/biz/payment"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -31,7 +31,7 @@ func (a *paypalAdapter) client(c map[string]any) (*paypal.Client, error) {
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func (a *paypalAdapter) Create(ctx context.Context, req *system.PaymentRequest, c map[string]any) (*system.PaymentResult, error) {
|
||||
func (a *paypalAdapter) Create(ctx context.Context, req *bizpayment.PaymentRequest, c map[string]any) (*bizpayment.PaymentResult, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("PayPal 下单参数为空")
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (a *paypalAdapter) Create(ctx context.Context, req *system.PaymentRequest,
|
||||
return paypalCreateResult(req, order, c)
|
||||
}
|
||||
|
||||
func (a *paypalAdapter) Query(ctx context.Context, orderID string, c map[string]any) (*system.PaymentResult, error) {
|
||||
func (a *paypalAdapter) Query(ctx context.Context, orderID string, c map[string]any) (*bizpayment.PaymentResult, error) {
|
||||
orderID = strings.TrimSpace(orderID)
|
||||
if orderID == "" {
|
||||
return nil, errors.New("PayPal 查单缺少 order ID")
|
||||
@@ -153,7 +153,7 @@ func paypalAutoCaptureEnabled(c map[string]any) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *paypalAdapter) Refund(ctx context.Context, req *system.PaymentRefundRequest, c map[string]any) (*system.PaymentResult, error) {
|
||||
func (a *paypalAdapter) Refund(ctx context.Context, req *bizpayment.PaymentRefundRequest, c map[string]any) (*bizpayment.PaymentResult, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("PayPal 退款请求为空")
|
||||
}
|
||||
@@ -201,7 +201,7 @@ func (a *paypalAdapter) Refund(ctx context.Context, req *system.PaymentRefundReq
|
||||
return paypalRefundResult(req, rsp.Response, c)
|
||||
}
|
||||
|
||||
func paypalRefundResult(req *system.PaymentRefundRequest, refund *paypal.PaymentCaptureRefund, c map[string]any) (*system.PaymentResult, error) {
|
||||
func paypalRefundResult(req *bizpayment.PaymentRefundRequest, refund *paypal.PaymentCaptureRefund, c map[string]any) (*bizpayment.PaymentResult, error) {
|
||||
if req == nil || refund == nil {
|
||||
return nil, errors.New("PayPal 退款响应为空")
|
||||
}
|
||||
@@ -215,8 +215,8 @@ func paypalRefundResult(req *system.PaymentRefundRequest, refund *paypal.Payment
|
||||
return nil, errors.New("PayPal 退款响应缺少 refund ID")
|
||||
}
|
||||
currency := strings.ToUpper(strings.TrimSpace(req.Currency))
|
||||
result := &system.PaymentResult{
|
||||
Provider: system.PaymentPayPal,
|
||||
result := &bizpayment.PaymentResult{
|
||||
Provider: bizpayment.PaymentPayPal,
|
||||
Status: normalizePayPalRefundState(refund.Status),
|
||||
TradeNo: req.TradeNo,
|
||||
ProviderTradeNo: providerRefundID,
|
||||
@@ -246,7 +246,7 @@ func paypalRefundResult(req *system.PaymentRefundRequest, refund *paypal.Payment
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func paypalCreateResult(req *system.PaymentRequest, order *paypal.OrderDetail, c map[string]any) (*system.PaymentResult, error) {
|
||||
func paypalCreateResult(req *bizpayment.PaymentRequest, order *paypal.OrderDetail, c map[string]any) (*bizpayment.PaymentResult, error) {
|
||||
if req == nil || order == nil {
|
||||
return nil, errors.New("PayPal 下单响应为空")
|
||||
}
|
||||
@@ -277,7 +277,7 @@ func paypalCreateResult(req *system.PaymentRequest, order *paypal.OrderDetail, c
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *paypalAdapter) Callback(ctx context.Context, callback *system.PaymentCallback, c map[string]any) (*system.PaymentResult, error) {
|
||||
func (a *paypalAdapter) Callback(ctx context.Context, callback *bizpayment.PaymentCallback, c map[string]any) (*bizpayment.PaymentResult, error) {
|
||||
if callback == nil || len(callback.Body) == 0 {
|
||||
return nil, errors.New("PayPal 回调为空")
|
||||
}
|
||||
@@ -325,7 +325,7 @@ func (a *paypalAdapter) Callback(ctx context.Context, callback *system.PaymentCa
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func paypalApplicationContext(req *system.PaymentRequest, c map[string]any) map[string]any {
|
||||
func paypalApplicationContext(req *bizpayment.PaymentRequest, c map[string]any) map[string]any {
|
||||
applicationContext := map[string]any{}
|
||||
if configured, ok := req.Extra["application_context"].(map[string]any); ok {
|
||||
for key, value := range configured {
|
||||
@@ -352,7 +352,7 @@ func paypalApplicationContext(req *system.PaymentRequest, c map[string]any) map[
|
||||
return applicationContext
|
||||
}
|
||||
|
||||
func paypalOrderResult(order *paypal.OrderDetail, queryID, fallbackTradeNo string, c map[string]any) (*system.PaymentResult, error) {
|
||||
func paypalOrderResult(order *paypal.OrderDetail, queryID, fallbackTradeNo string, c map[string]any) (*bizpayment.PaymentResult, error) {
|
||||
if order == nil {
|
||||
return nil, errors.New("PayPal 订单结果为空")
|
||||
}
|
||||
@@ -364,8 +364,8 @@ func paypalOrderResult(order *paypal.OrderDetail, queryID, fallbackTradeNo strin
|
||||
tradeNo = fallbackTradeNo
|
||||
}
|
||||
capture := paypalOrderCapture(order)
|
||||
result := &system.PaymentResult{
|
||||
Provider: system.PaymentPayPal,
|
||||
result := &bizpayment.PaymentResult{
|
||||
Provider: bizpayment.PaymentPayPal,
|
||||
Status: paypalOrderCaptureState(order),
|
||||
TradeNo: tradeNo,
|
||||
QueryID: queryID,
|
||||
@@ -498,7 +498,7 @@ func paypalOrderAmount(order *paypal.OrderDetail, c map[string]any) (int64, stri
|
||||
return total, currency, found, nil
|
||||
}
|
||||
|
||||
func paypalRefundCaptureID(ctx context.Context, client *paypal.Client, req *system.PaymentRefundRequest) (string, error) {
|
||||
func paypalRefundCaptureID(ctx context.Context, client *paypal.Client, req *bizpayment.PaymentRefundRequest) (string, error) {
|
||||
if req == nil {
|
||||
return "", errors.New("PayPal 退款请求为空")
|
||||
}
|
||||
@@ -533,7 +533,7 @@ func paypalRefundCaptureID(ctx context.Context, client *paypal.Client, req *syst
|
||||
return capture.Id, nil
|
||||
}
|
||||
|
||||
func paypalWebhookResult(event *paypal.WebhookEvent) (*system.PaymentResult, error) {
|
||||
func paypalWebhookResult(event *paypal.WebhookEvent) (*bizpayment.PaymentResult, error) {
|
||||
var resource map[string]any
|
||||
if err := json.Unmarshal(event.Resource, &resource); err != nil {
|
||||
return nil, fmt.Errorf("PayPal 回调 resource 无效: %w", err)
|
||||
@@ -567,8 +567,8 @@ func paypalWebhookResult(event *paypal.WebhookEvent) (*system.PaymentResult, err
|
||||
if tradeNo == "" || queryID == "" {
|
||||
return nil, errors.New("PayPal 回调缺少商户订单号或 order ID")
|
||||
}
|
||||
return &system.PaymentResult{
|
||||
Provider: system.PaymentPayPal,
|
||||
return &bizpayment.PaymentResult{
|
||||
Provider: bizpayment.PaymentPayPal,
|
||||
Status: status,
|
||||
TradeNo: tradeNo,
|
||||
ProviderTradeNo: providerTradeNo,
|
||||
@@ -587,7 +587,7 @@ func paypalPurchaseUnitTradeNo(resource map[string]any) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func paypalCallbackHeader(callback *system.PaymentCallback, name string) string {
|
||||
func paypalCallbackHeader(callback *bizpayment.PaymentCallback, name string) string {
|
||||
for key, value := range callback.Headers {
|
||||
if strings.EqualFold(key, name) {
|
||||
return strings.TrimSpace(value)
|
||||
|
||||
Reference in New Issue
Block a user