fixed rail & operation names
This commit is contained in:
@@ -2,6 +2,12 @@ package discovery
|
||||
|
||||
import "strings"
|
||||
|
||||
// Rail identifies a canonical payment rail token.
|
||||
type Rail string
|
||||
|
||||
// RailOperation identifies a canonical payment-plan rail action token.
|
||||
type RailOperation string
|
||||
|
||||
const (
|
||||
OperationDiscoveryLookup = "discovery.lookup"
|
||||
|
||||
@@ -33,6 +39,33 @@ const (
|
||||
OperationFXConvert = "fx.convert"
|
||||
)
|
||||
|
||||
// Canonical rail identifiers.
|
||||
const (
|
||||
RailUnspecified = "UNSPECIFIED"
|
||||
RailCrypto = "CRYPTO"
|
||||
RailProviderSettlement = "SETTLEMENT"
|
||||
RailLedger = "LEDGER"
|
||||
RailCardPayout = "CARD"
|
||||
RailFiatOnRamp = "ONRAMP"
|
||||
RailFiatOffRamp = "OFFRAMP"
|
||||
)
|
||||
|
||||
// Canonical payment-plan rail operation identifiers.
|
||||
const (
|
||||
RailOperationUnspecified = "UNSPECIFIED"
|
||||
RailOperationDebit = "DEBIT"
|
||||
RailOperationCredit = "CREDIT"
|
||||
RailOperationExternalDebit = "EXTERNAL_DEBIT"
|
||||
RailOperationExternalCredit = "EXTERNAL_CREDIT"
|
||||
RailOperationMove = "MOVE"
|
||||
RailOperationSend = "SEND"
|
||||
RailOperationFee = "FEE"
|
||||
RailOperationObserveConfirm = "OBSERVE_CONFIRM"
|
||||
RailOperationFXConvert = "FX_CONVERT"
|
||||
RailOperationBlock = "BLOCK"
|
||||
RailOperationRelease = "RELEASE"
|
||||
)
|
||||
|
||||
// NormalizeOperation canonicalizes an operation string for comparisons.
|
||||
func NormalizeOperation(value string) string {
|
||||
return strings.ToLower(strings.TrimSpace(value))
|
||||
|
||||
@@ -2,28 +2,6 @@ package discovery
|
||||
|
||||
import "strings"
|
||||
|
||||
const (
|
||||
RailCrypto = "CRYPTO"
|
||||
RailProviderSettlement = "SETTLEMENT"
|
||||
RailLedger = "LEDGER"
|
||||
RailCardPayout = "CARD"
|
||||
RailFiatOnRamp = "ONRAMP"
|
||||
)
|
||||
|
||||
const (
|
||||
RailOperationDebit = "DEBIT"
|
||||
RailOperationCredit = "CREDIT"
|
||||
RailOperationExternalDebit = "EXTERNAL_DEBIT"
|
||||
RailOperationExternalCredit = "EXTERNAL_CREDIT"
|
||||
RailOperationMove = "MOVE"
|
||||
RailOperationSend = "SEND"
|
||||
RailOperationFee = "FEE"
|
||||
RailOperationObserveConfirm = "OBSERVE_CONFIRM"
|
||||
RailOperationFXConvert = "FX_CONVERT"
|
||||
RailOperationBlock = "BLOCK"
|
||||
RailOperationRelease = "RELEASE"
|
||||
)
|
||||
|
||||
var knownRails = map[string]struct{}{
|
||||
RailCrypto: {},
|
||||
RailProviderSettlement: {},
|
||||
@@ -57,21 +35,7 @@ func NormalizeRail(value string) string {
|
||||
for strings.Contains(clean, "__") {
|
||||
clean = strings.ReplaceAll(clean, "__", "_")
|
||||
}
|
||||
|
||||
switch clean {
|
||||
case RailCrypto, "RAIL_CRYPTO":
|
||||
return RailCrypto
|
||||
case RailProviderSettlement, "PROVIDER_SETTLEMENT", "RAIL_SETTLEMENT", "RAIL_PROVIDER_SETTLEMENT":
|
||||
return RailProviderSettlement
|
||||
case RailLedger, "RAIL_LEDGER":
|
||||
return RailLedger
|
||||
case RailCardPayout, "CARD_PAYOUT", "RAIL_CARD", "RAIL_CARD_PAYOUT":
|
||||
return RailCardPayout
|
||||
case RailFiatOnRamp, "FIAT_ONRAMP", "RAIL_ONRAMP", "RAIL_FIAT_ONRAMP":
|
||||
return RailFiatOnRamp
|
||||
default:
|
||||
return clean
|
||||
}
|
||||
return clean
|
||||
}
|
||||
|
||||
// IsKnownRail reports whether the value is a recognized payment rail.
|
||||
@@ -82,11 +46,7 @@ func IsKnownRail(value string) bool {
|
||||
|
||||
// NormalizeRailOperation canonicalizes a rail operation token.
|
||||
func NormalizeRailOperation(value string) string {
|
||||
clean := strings.ToUpper(strings.TrimSpace(value))
|
||||
if after, ok := strings.CutPrefix(clean, "RAIL_OPERATION_"); ok {
|
||||
clean = after
|
||||
}
|
||||
return clean
|
||||
return strings.ToUpper(strings.TrimSpace(value))
|
||||
}
|
||||
|
||||
// IsKnownRailOperation reports whether the value is a recognized rail operation.
|
||||
@@ -104,24 +64,16 @@ func ExpandRailOperation(value string) []string {
|
||||
}
|
||||
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case OperationExternalDebit, "external_debit":
|
||||
case OperationExternalDebit:
|
||||
return []string{RailOperationExternalDebit}
|
||||
case OperationExternalCredit, "external_credit":
|
||||
case OperationExternalCredit:
|
||||
return []string{RailOperationExternalCredit}
|
||||
case "payin", "payin.crypto", "payin.fiat", "payin.card":
|
||||
return []string{RailOperationExternalDebit}
|
||||
case "payout", "payout.crypto", "payout.fiat", "payout.card":
|
||||
return []string{RailOperationExternalCredit, RailOperationSend}
|
||||
case "fee.send", "fees.send", OperationFee:
|
||||
case OperationFee:
|
||||
return []string{RailOperationFee}
|
||||
case OperationObserveConfirm, "observe_confirm":
|
||||
case OperationObserveConfirm:
|
||||
return []string{RailOperationObserveConfirm}
|
||||
case OperationFXConvert, "fx_convert":
|
||||
case OperationFXConvert:
|
||||
return []string{RailOperationFXConvert}
|
||||
case "funds.block", "hold.balance", "block":
|
||||
return []string{RailOperationBlock}
|
||||
case "funds.release", "release", "unblock":
|
||||
return []string{RailOperationRelease}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -159,12 +111,6 @@ func CryptoRailGatewayOperations() []string {
|
||||
OperationExternalCredit,
|
||||
OperationFee,
|
||||
OperationObserveConfirm,
|
||||
// Legacy rail tokens retained for backward compatibility.
|
||||
RailOperationSend,
|
||||
RailOperationExternalDebit,
|
||||
RailOperationExternalCredit,
|
||||
RailOperationFee,
|
||||
RailOperationObserveConfirm,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,10 +120,6 @@ func CardPayoutRailGatewayOperations() []string {
|
||||
OperationSend,
|
||||
OperationExternalCredit,
|
||||
OperationObserveConfirm,
|
||||
// Legacy rail tokens retained for backward compatibility.
|
||||
RailOperationSend,
|
||||
RailOperationExternalCredit,
|
||||
RailOperationObserveConfirm,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +128,5 @@ func ProviderSettlementRailGatewayOperations() []string {
|
||||
return []string{
|
||||
OperationFXConvert,
|
||||
OperationObserveConfirm,
|
||||
// Legacy rail tokens retained for backward compatibility.
|
||||
RailOperationFXConvert,
|
||||
RailOperationObserveConfirm,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ import "testing"
|
||||
func TestNormalizeRailOperations(t *testing.T) {
|
||||
got := NormalizeRailOperations([]string{
|
||||
"send",
|
||||
"payout.crypto",
|
||||
"observe.confirm",
|
||||
"external.credit",
|
||||
"fx.convert",
|
||||
"payout.crypto",
|
||||
"unknown",
|
||||
})
|
||||
|
||||
want := []string{
|
||||
RailOperationSend,
|
||||
RailOperationExternalCredit,
|
||||
RailOperationObserveConfirm,
|
||||
RailOperationExternalCredit,
|
||||
RailOperationFXConvert,
|
||||
}
|
||||
if len(got) != len(want) {
|
||||
@@ -28,16 +28,9 @@ func TestNormalizeRailOperations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandRailOperationLegacyAliases(t *testing.T) {
|
||||
got := ExpandRailOperation("payout.fiat")
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("unexpected operations count: got=%d want=2", len(got))
|
||||
}
|
||||
if got[0] != RailOperationExternalCredit {
|
||||
t.Fatalf("unexpected first operation: got=%q want=%q", got[0], RailOperationExternalCredit)
|
||||
}
|
||||
if got[1] != RailOperationSend {
|
||||
t.Fatalf("unexpected second operation: got=%q want=%q", got[1], RailOperationSend)
|
||||
func TestExpandRailOperationRejectsLegacyAliases(t *testing.T) {
|
||||
if got := ExpandRailOperation("payout.fiat"); len(got) != 0 {
|
||||
t.Fatalf("expected no expansion for legacy alias, got=%v", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,14 +43,65 @@ func TestIsKnownRail(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRailAliases(t *testing.T) {
|
||||
if got := NormalizeRail("provider_settlement"); got != RailProviderSettlement {
|
||||
t.Fatalf("provider_settlement alias mismatch: got=%q want=%q", got, RailProviderSettlement)
|
||||
func TestNormalizeRailRejectsLegacyAliases(t *testing.T) {
|
||||
if IsKnownRail("provider_settlement") {
|
||||
t.Fatalf("did not expect provider_settlement alias to be known")
|
||||
}
|
||||
if got := NormalizeRail("card_payout"); got != RailCardPayout {
|
||||
t.Fatalf("card_payout alias mismatch: got=%q want=%q", got, RailCardPayout)
|
||||
if IsKnownRail("card_payout") {
|
||||
t.Fatalf("did not expect card_payout alias to be known")
|
||||
}
|
||||
if got := NormalizeRail("RAIL_SETTLEMENT"); got != RailProviderSettlement {
|
||||
t.Fatalf("RAIL_SETTLEMENT alias mismatch: got=%q want=%q", got, RailProviderSettlement)
|
||||
if IsKnownRail("RAIL_SETTLEMENT") {
|
||||
t.Fatalf("did not expect RAIL_SETTLEMENT alias to be known")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatewayOperationSetsAreCanonicalOnly(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
got []string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "crypto rail gateway operations",
|
||||
got: CryptoRailGatewayOperations(),
|
||||
want: []string{
|
||||
OperationBalanceRead,
|
||||
OperationSend,
|
||||
OperationExternalDebit,
|
||||
OperationExternalCredit,
|
||||
OperationFee,
|
||||
OperationObserveConfirm,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "card payout rail gateway operations",
|
||||
got: CardPayoutRailGatewayOperations(),
|
||||
want: []string{
|
||||
OperationSend,
|
||||
OperationExternalCredit,
|
||||
OperationObserveConfirm,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "provider settlement rail gateway operations",
|
||||
got: ProviderSettlementRailGatewayOperations(),
|
||||
want: []string{
|
||||
OperationFXConvert,
|
||||
OperationObserveConfirm,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if len(tt.got) != len(tt.want) {
|
||||
t.Fatalf("unexpected operations count: got=%d want=%d", len(tt.got), len(tt.want))
|
||||
}
|
||||
for i := range tt.want {
|
||||
if tt.got[i] != tt.want[i] {
|
||||
t.Fatalf("unexpected operation[%d]: got=%q want=%q", i, tt.got[i], tt.want[i])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user