refactor payment platform canonicalization and order method consistency
Build docker and publish / build (20.15.1) (push) Failing after 8m1s

This commit is contained in:
2026-03-04 02:15:32 -08:00
parent 82626dd749
commit 0c544268e5
10 changed files with 160 additions and 23 deletions
+60 -14
View File
@@ -1,6 +1,10 @@
package payment
import "github.com/perfect-panel/server/internal/types"
import (
"strings"
"github.com/perfect-panel/server/internal/types"
)
type Platform int
@@ -14,32 +18,74 @@ const (
UNSUPPORTED Platform = -1
)
var platformNames = map[string]Platform{
"CryptoSaaS": CryptoSaaS,
"Stripe": Stripe,
"AlipayF2F": AlipayF2F,
"EPay": EPay,
"AppleIAP": AppleIAP,
const (
platformNameStripe = "Stripe"
platformNameAlipayF2F = "AlipayF2F"
platformNameEPay = "EPay"
platformNameBalance = "balance"
platformNameCryptoSaaS = "CryptoSaaS"
platformNameAppleIAP = "AppleIAP"
platformNameUnsupported = "unsupported"
)
var platformAliasToType = map[string]Platform{
"stripe": Stripe,
"alipayf2f": AlipayF2F,
"alipay_f2f": AlipayF2F,
"epay": EPay,
"balance": Balance,
"unsupported": UNSUPPORTED,
"cryptosaas": CryptoSaaS,
"crypto_saas": CryptoSaaS,
"appleiap": AppleIAP,
"apple_iap": AppleIAP,
}
func (p Platform) String() string {
for k, v := range platformNames {
if v == p {
return k
}
switch p {
case Stripe:
return platformNameStripe
case AlipayF2F:
return platformNameAlipayF2F
case EPay:
return platformNameEPay
case Balance:
return platformNameBalance
case CryptoSaaS:
return platformNameCryptoSaaS
case AppleIAP:
return platformNameAppleIAP
default:
return platformNameUnsupported
}
return "unsupported"
}
func ParsePlatform(s string) Platform {
if p, ok := platformNames[s]; ok {
normalized := normalizePlatformAlias(s)
if p, ok := platformAliasToType[normalized]; ok {
return p
}
compact := strings.ReplaceAll(normalized, "_", "")
if p, ok := platformAliasToType[compact]; ok {
return p
}
return UNSUPPORTED
}
func CanonicalPlatformName(input string) (string, bool) {
platform := ParsePlatform(input)
if platform == UNSUPPORTED {
return "", false
}
return platform.String(), true
}
func normalizePlatformAlias(input string) string {
normalized := strings.ToLower(strings.TrimSpace(input))
normalized = strings.ReplaceAll(normalized, "-", "_")
normalized = strings.ReplaceAll(normalized, " ", "")
return normalized
}
func GetSupportedPlatforms() []types.PlatformInfo {
return []types.PlatformInfo{
{