Fixed billing fees unreachable error propagation. Added USDT ledger creation. Fixed ledger boundaries operation types
This commit is contained in:
71
api/pkg/discovery/operations.go
Normal file
71
api/pkg/discovery/operations.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package discovery
|
||||
|
||||
import "strings"
|
||||
|
||||
const (
|
||||
OperationDiscoveryLookup = "discovery.lookup"
|
||||
|
||||
OperationDocumentsBatchResolve = "documents.batch_resolve"
|
||||
OperationDocumentsGet = "documents.get"
|
||||
OperationFeeCalc = "fee.calc"
|
||||
OperationNotifySend = "notify.send"
|
||||
OperationFXQuote = "fx.quote"
|
||||
OperationFXIngest = "fx.ingest"
|
||||
|
||||
OperationPaymentInitiate = "payment.initiate"
|
||||
OperationPaymentQuote = "payment.quote"
|
||||
OperationPaymentMultiQuote = "payment.multiquote"
|
||||
OperationPaymentMethodsManage = "payment_methods.manage"
|
||||
OperationPaymentMethodsRead = "payment_methods.read"
|
||||
|
||||
OperationBalanceRead = "balance.read"
|
||||
|
||||
OperationLedgerDebit = "ledger.debit"
|
||||
OperationLedgerCredit = "ledger.credit"
|
||||
OperationLedgerTransfer = "ledger.transfer"
|
||||
OperationLedgerFX = "ledger.fx"
|
||||
OperationExternalDebit = "external.debit"
|
||||
OperationExternalCredit = "external.credit"
|
||||
|
||||
OperationSend = "send"
|
||||
OperationFee = "fee"
|
||||
OperationObserveConfirm = "observe.confirm"
|
||||
OperationFXConvert = "fx.convert"
|
||||
)
|
||||
|
||||
// NormalizeOperation canonicalizes an operation string for comparisons.
|
||||
func NormalizeOperation(value string) string {
|
||||
return strings.ToLower(strings.TrimSpace(value))
|
||||
}
|
||||
|
||||
// HasAnyOperation reports whether ops contains any of required operations.
|
||||
func HasAnyOperation(ops []string, required []string) bool {
|
||||
if len(required) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, op := range ops {
|
||||
normalized := NormalizeOperation(op)
|
||||
if normalized == "" {
|
||||
continue
|
||||
}
|
||||
for _, target := range required {
|
||||
if normalized == NormalizeOperation(target) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// LedgerServiceOperations returns canonical operations announced by ledger.
|
||||
func LedgerServiceOperations() []string {
|
||||
return []string{
|
||||
OperationBalanceRead,
|
||||
OperationLedgerDebit,
|
||||
OperationLedgerCredit,
|
||||
OperationLedgerTransfer,
|
||||
OperationLedgerFX,
|
||||
OperationExternalCredit,
|
||||
OperationExternalDebit,
|
||||
}
|
||||
}
|
||||
@@ -104,14 +104,20 @@ func ExpandRailOperation(value string) []string {
|
||||
}
|
||||
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case OperationExternalDebit, "external_debit":
|
||||
return []string{RailOperationExternalDebit}
|
||||
case OperationExternalCredit, "external_credit":
|
||||
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":
|
||||
case "fee.send", "fees.send", OperationFee:
|
||||
return []string{RailOperationFee}
|
||||
case "observe.confirm", "observe_confirm":
|
||||
case OperationObserveConfirm, "observe_confirm":
|
||||
return []string{RailOperationObserveConfirm}
|
||||
case OperationFXConvert, "fx_convert":
|
||||
return []string{RailOperationFXConvert}
|
||||
case "funds.block", "hold.balance", "block":
|
||||
return []string{RailOperationBlock}
|
||||
case "funds.release", "release", "unblock":
|
||||
@@ -147,6 +153,13 @@ func NormalizeRailOperations(values []string) []string {
|
||||
// CryptoRailGatewayOperations returns canonical operations for crypto rail gateways.
|
||||
func CryptoRailGatewayOperations() []string {
|
||||
return []string{
|
||||
OperationBalanceRead,
|
||||
OperationSend,
|
||||
OperationExternalDebit,
|
||||
OperationExternalCredit,
|
||||
OperationFee,
|
||||
OperationObserveConfirm,
|
||||
// Legacy rail tokens retained for backward compatibility.
|
||||
RailOperationSend,
|
||||
RailOperationExternalDebit,
|
||||
RailOperationExternalCredit,
|
||||
@@ -158,6 +171,10 @@ func CryptoRailGatewayOperations() []string {
|
||||
// CardPayoutRailGatewayOperations returns canonical operations for card payout gateways.
|
||||
func CardPayoutRailGatewayOperations() []string {
|
||||
return []string{
|
||||
OperationSend,
|
||||
OperationExternalCredit,
|
||||
OperationObserveConfirm,
|
||||
// Legacy rail tokens retained for backward compatibility.
|
||||
RailOperationSend,
|
||||
RailOperationExternalCredit,
|
||||
RailOperationObserveConfirm,
|
||||
@@ -167,6 +184,9 @@ func CardPayoutRailGatewayOperations() []string {
|
||||
// ProviderSettlementRailGatewayOperations returns canonical operations for settlement gateways.
|
||||
func ProviderSettlementRailGatewayOperations() []string {
|
||||
return []string{
|
||||
OperationFXConvert,
|
||||
OperationObserveConfirm,
|
||||
// Legacy rail tokens retained for backward compatibility.
|
||||
RailOperationFXConvert,
|
||||
RailOperationObserveConfirm,
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@ func TestNormalizeRailOperations(t *testing.T) {
|
||||
"send",
|
||||
"payout.crypto",
|
||||
"observe.confirm",
|
||||
"external.credit",
|
||||
"fx.convert",
|
||||
"unknown",
|
||||
"EXTERNAL_CREDIT",
|
||||
})
|
||||
|
||||
want := []string{
|
||||
RailOperationSend,
|
||||
RailOperationExternalCredit,
|
||||
RailOperationObserveConfirm,
|
||||
RailOperationFXConvert,
|
||||
}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("unexpected operations count: got=%d want=%d", len(got), len(want))
|
||||
|
||||
Reference in New Issue
Block a user