payment rails

This commit is contained in:
Stephan D
2025-12-10 18:40:55 +01:00
parent 81d2db394b
commit 47899e25d4
39 changed files with 3043 additions and 909 deletions

View File

@@ -7,8 +7,8 @@ import (
"strings"
"time"
chainclient "github.com/tech/sendico/gateway/chain/client"
oracleclient "github.com/tech/sendico/fx/oracle/client"
chainclient "github.com/tech/sendico/gateway/chain/client"
ledgerclient "github.com/tech/sendico/ledger/client"
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrator"
"github.com/tech/sendico/payments/orchestrator/storage"
@@ -41,10 +41,11 @@ type Imp struct {
type config struct {
*grpcapp.Config `yaml:",inline"`
Fees clientConfig `yaml:"fees"`
Ledger clientConfig `yaml:"ledger"`
Gateway clientConfig `yaml:"gateway"`
Oracle clientConfig `yaml:"oracle"`
Fees clientConfig `yaml:"fees"`
Ledger clientConfig `yaml:"ledger"`
Gateway clientConfig `yaml:"gateway"`
Oracle clientConfig `yaml:"oracle"`
CardGateways map[string]cardGatewayRouteConfig `yaml:"card_gateways"`
}
type clientConfig struct {
@@ -54,6 +55,11 @@ type clientConfig struct {
InsecureTransport bool `yaml:"insecure"`
}
type cardGatewayRouteConfig struct {
FundingAddress string `yaml:"funding_address"`
FeeAddress string `yaml:"fee_address"`
}
func (c clientConfig) address() string {
return strings.TrimSpace(c.Address)
}
@@ -107,7 +113,7 @@ func (i *Imp) Shutdown() {
func (i *Imp) Start() error {
cfg, err := i.loadConfig()
if err != nil {
if err != nil {
return err
}
i.config = cfg
@@ -150,6 +156,9 @@ func (i *Imp) Start() error {
if oracleClient != nil {
opts = append(opts, orchestrator.WithOracleClient(oracleClient))
}
if routes := buildCardGatewayRoutes(cfg.CardGateways); len(routes) > 0 {
opts = append(opts, orchestrator.WithCardGatewayRoutes(routes))
}
return orchestrator.NewService(logger, repo, opts...), nil
}
@@ -296,3 +305,21 @@ func (i *Imp) loadConfig() (*config, error) {
return cfg, nil
}
func buildCardGatewayRoutes(src map[string]cardGatewayRouteConfig) map[string]orchestrator.CardGatewayRoute {
if len(src) == 0 {
return nil
}
result := make(map[string]orchestrator.CardGatewayRoute, len(src))
for key, route := range src {
trimmedKey := strings.TrimSpace(key)
if trimmedKey == "" {
continue
}
result[trimmedKey] = orchestrator.CardGatewayRoute{
FundingAddress: strings.TrimSpace(route.FundingAddress),
FeeAddress: strings.TrimSpace(route.FeeAddress),
}
}
return result
}