优化结构
This commit is contained in:
@@ -5,18 +5,17 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"kra/internal/biz/system"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"kra/internal/biz"
|
||||
|
||||
gopayApple "github.com/go-pay/gopay/apple"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type appleAdapter struct{}
|
||||
|
||||
func (a *appleAdapter) Create(_ context.Context, req *biz.PaymentRequest, _ map[string]any) (*biz.PaymentResult, error) {
|
||||
func (a *appleAdapter) Create(_ context.Context, req *system.PaymentRequest, _ map[string]any) (*system.PaymentResult, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("Apple 内购下单参数为空")
|
||||
}
|
||||
@@ -31,9 +30,9 @@ func (a *appleAdapter) Create(_ context.Context, req *biz.PaymentRequest, _ map[
|
||||
return nil, errors.New("Apple 内购 tradeNo 必须是用于 appAccountToken 的 UUID")
|
||||
}
|
||||
payload, _ := json.Marshal(map[string]any{"product_id": productID, "app_account_token": req.TradeNo, "client_only": true, "trade_no": req.TradeNo})
|
||||
return &biz.PaymentResult{Provider: biz.PaymentApple, Status: "client_pending", TradeNo: req.TradeNo, Payload: payload}, nil
|
||||
return &system.PaymentResult{Provider: system.PaymentApple, Status: "client_pending", TradeNo: req.TradeNo, Payload: payload}, nil
|
||||
}
|
||||
func (a *appleAdapter) Query(ctx context.Context, transactionID string, c map[string]any) (*biz.PaymentResult, error) {
|
||||
func (a *appleAdapter) Query(ctx context.Context, transactionID string, c map[string]any) (*system.PaymentResult, error) {
|
||||
transactionID = strings.TrimSpace(transactionID)
|
||||
if transactionID == "" {
|
||||
return nil, errors.New("Apple 查询缺少 transactionId")
|
||||
@@ -82,10 +81,10 @@ func (a *appleAdapter) Query(ctx context.Context, transactionID string, c map[st
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
func (a *appleAdapter) Refund(context.Context, *biz.PaymentRefundRequest, map[string]any) (*biz.PaymentResult, error) {
|
||||
func (a *appleAdapter) Refund(context.Context, *system.PaymentRefundRequest, map[string]any) (*system.PaymentResult, error) {
|
||||
return nil, errors.New("Apple 内购退款由 App Store 管理,服务端不提供主动退款接口")
|
||||
}
|
||||
func (a *appleAdapter) Callback(_ context.Context, callback *biz.PaymentCallback, c map[string]any) (*biz.PaymentResult, error) {
|
||||
func (a *appleAdapter) Callback(_ context.Context, callback *system.PaymentCallback, c map[string]any) (*system.PaymentResult, error) {
|
||||
if callback == nil {
|
||||
return nil, errors.New("Apple 回调为空")
|
||||
}
|
||||
@@ -140,7 +139,7 @@ func (a *appleAdapter) Callback(_ context.Context, callback *biz.PaymentCallback
|
||||
if _, parseErr := uuid.Parse(tradeNo); parseErr != nil {
|
||||
return nil, errors.New("Apple 回调 appAccountToken 不是有效 UUID")
|
||||
}
|
||||
return &biz.PaymentResult{Provider: biz.PaymentApple, Status: "pending", TradeNo: tradeNo, ProviderTradeNo: transactionID, QueryID: transactionID, Payload: payload}, nil
|
||||
return &system.PaymentResult{Provider: system.PaymentApple, Status: "pending", TradeNo: tradeNo, ProviderTradeNo: transactionID, QueryID: transactionID, Payload: payload}, nil
|
||||
}
|
||||
|
||||
func appleClaims(value any) (map[string]any, error) {
|
||||
@@ -155,7 +154,7 @@ func appleClaims(value any) (map[string]any, error) {
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func applePaymentResult(transactionID string, claims map[string]any, payload []byte, c map[string]any) (*biz.PaymentResult, error) {
|
||||
func applePaymentResult(transactionID string, claims map[string]any, payload []byte, c map[string]any) (*system.PaymentResult, error) {
|
||||
revoked, err := appleRevoked(claims)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -175,7 +174,7 @@ func applePaymentResult(transactionID string, claims map[string]any, payload []b
|
||||
if _, err := uuid.Parse(tradeNo); err != nil {
|
||||
return nil, errors.New("Apple 交易 appAccountToken 不是有效 UUID")
|
||||
}
|
||||
result := &biz.PaymentResult{Provider: biz.PaymentApple, Status: status, TradeNo: tradeNo, ProviderTradeNo: providerTradeNo, QueryID: providerTradeNo, Payload: payload}
|
||||
result := &system.PaymentResult{Provider: system.PaymentApple, Status: status, TradeNo: tradeNo, ProviderTradeNo: providerTradeNo, QueryID: providerTradeNo, Payload: payload}
|
||||
if status != "success" {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user