feat: snapshot payment provider keys on orders

This commit is contained in:
IanShaw027
2026-04-20 20:47:14 +08:00
parent e3f69e0246
commit c0b24aefba
14 changed files with 400 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"strconv"
"strings"
"time"
dbent "github.com/Wei-Shaw/sub2api/ent"
@@ -241,7 +242,10 @@ func (s *PaymentService) getOrderProvider(ctx context.Context, o *dbent.PaymentO
if err == nil {
cfg, err := s.loadBalancer.GetInstanceConfig(ctx, instID)
if err == nil {
providerKey := s.registry.GetProviderKey(o.PaymentType)
providerKey := strings.TrimSpace(psStringValue(o.ProviderKey))
if providerKey == "" {
providerKey = s.registry.GetProviderKey(o.PaymentType)
}
if providerKey == "" {
providerKey = o.PaymentType
}
@@ -255,3 +259,10 @@ func (s *PaymentService) getOrderProvider(ctx context.Context, o *dbent.PaymentO
s.EnsureProviders(ctx)
return s.registry.GetProvider(o.PaymentType)
}
func psStringValue(value *string) string {
if value == nil {
return ""
}
return *value
}