unified gateway interfaces

This commit is contained in:
Stephan D
2026-01-04 12:47:43 +01:00
parent 743f683d92
commit 59c83e414a
41 changed files with 927 additions and 186 deletions

View File

@@ -4,7 +4,6 @@ import (
"strings"
chainclient "github.com/tech/sendico/gateway/chain/client"
mntxclient "github.com/tech/sendico/gateway/mntx/client"
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrator"
"github.com/tech/sendico/payments/orchestrator/storage/model"
"github.com/tech/sendico/pkg/discovery"
@@ -48,15 +47,15 @@ func buildFeeLedgerAccounts(src map[string]string) map[string]string {
return result
}
func buildGatewayRegistry(logger mlogger.Logger, mntxClient mntxclient.Client, src []gatewayInstanceConfig, registry *discovery.Registry) orchestrator.GatewayRegistry {
func buildGatewayRegistry(logger mlogger.Logger, src []gatewayInstanceConfig, registry *discovery.Registry) orchestrator.GatewayRegistry {
static := buildGatewayInstances(logger, src)
staticRegistry := orchestrator.NewGatewayRegistry(logger, mntxClient, static)
staticRegistry := orchestrator.NewGatewayRegistry(logger, static)
discoveryRegistry := orchestrator.NewDiscoveryGatewayRegistry(logger, registry)
return orchestrator.NewCompositeGatewayRegistry(logger, staticRegistry, discoveryRegistry)
}
func buildRailGateways(chainClient chainclient.Client, src []gatewayInstanceConfig) map[string]rail.RailGateway {
if chainClient == nil || len(src) == 0 {
func buildRailGateways(chainClient chainclient.Client, paymentGatewayClient chainclient.Client, src []gatewayInstanceConfig) map[string]rail.RailGateway {
if len(src) == 0 || (chainClient == nil && paymentGatewayClient == nil) {
return nil
}
instances := buildGatewayInstances(nil, src)
@@ -68,9 +67,6 @@ func buildRailGateways(chainClient chainclient.Client, src []gatewayInstanceConf
if inst == nil || !inst.IsEnabled {
continue
}
if inst.Rail != model.RailCrypto {
continue
}
cfg := chainclient.RailGatewayConfig{
Rail: string(inst.Rail),
Network: inst.Network,
@@ -82,7 +78,18 @@ func buildRailGateways(chainClient chainclient.Client, src []gatewayInstanceConf
RequiresObserveConfirm: inst.Capabilities.RequiresObserveConfirm,
},
}
result[inst.ID] = chainclient.NewRailGateway(chainClient, cfg)
switch inst.Rail {
case model.RailCrypto:
if chainClient == nil {
continue
}
result[inst.ID] = chainclient.NewRailGateway(chainClient, cfg)
case model.RailProviderSettlement:
if paymentGatewayClient == nil {
continue
}
result[inst.ID] = orchestrator.NewProviderSettlementGateway(paymentGatewayClient, cfg)
}
}
if len(result) == 0 {
return nil

View File

@@ -85,6 +85,29 @@ func (i *Imp) initGatewayClient(cfg clientConfig) chainclient.Client {
return client
}
func (i *Imp) initPaymentGatewayClient(cfg clientConfig) chainclient.Client {
addr := cfg.address()
if addr == "" {
return nil
}
ctx, cancel := context.WithTimeout(context.Background(), cfg.dialTimeout())
defer cancel()
client, err := chainclient.New(ctx, chainclient.Config{
Address: addr,
DialTimeout: cfg.dialTimeout(),
CallTimeout: cfg.callTimeout(),
Insecure: cfg.InsecureTransport,
})
if err != nil {
i.logger.Warn("failed to connect to payment gateway service", zap.String("address", addr), zap.Error(err))
return nil
}
i.logger.Info("connected to payment gateway service", zap.String("address", addr))
return client
}
func (i *Imp) initMntxClient(cfg clientConfig) mntxclient.Client {
addr := cfg.address()
if addr == "" {
@@ -138,6 +161,9 @@ func (i *Imp) closeClients() {
if i.gatewayClient != nil {
_ = i.gatewayClient.Close()
}
if i.paymentGatewayClient != nil {
_ = i.paymentGatewayClient.Close()
}
if i.mntxClient != nil {
_ = i.mntxClient.Close()
}

View File

@@ -16,6 +16,7 @@ type config struct {
Fees clientConfig `yaml:"fees"`
Ledger clientConfig `yaml:"ledger"`
Gateway clientConfig `yaml:"gateway"`
PaymentGateway clientConfig `yaml:"payment_gateway"`
Mntx clientConfig `yaml:"mntx"`
Oracle clientConfig `yaml:"oracle"`
CardGateways map[string]cardGatewayRouteConfig `yaml:"card_gateways"`

View File

@@ -10,11 +10,12 @@ import (
)
type orchestratorDeps struct {
feesClient feesv1.FeeEngineClient
ledgerClient ledgerclient.Client
gatewayClient chainclient.Client
mntxClient mntxclient.Client
oracleClient oracleclient.Client
feesClient feesv1.FeeEngineClient
ledgerClient ledgerclient.Client
gatewayClient chainclient.Client
paymentGatewayClient chainclient.Client
mntxClient mntxclient.Client
oracleClient oracleclient.Client
}
func (i *Imp) initDependencies(cfg *config) *orchestratorDeps {
@@ -35,6 +36,11 @@ func (i *Imp) initDependencies(cfg *config) *orchestratorDeps {
i.gatewayClient = deps.gatewayClient
}
deps.paymentGatewayClient = i.initPaymentGatewayClient(cfg.PaymentGateway)
if deps.paymentGatewayClient != nil {
i.paymentGatewayClient = deps.paymentGatewayClient
}
deps.mntxClient = i.initMntxClient(cfg.Mntx)
if deps.mntxClient != nil {
i.mntxClient = deps.mntxClient
@@ -62,7 +68,10 @@ func (i *Imp) buildServiceOptions(cfg *config, deps *orchestratorDeps) []orchest
if deps.gatewayClient != nil {
opts = append(opts, orchestrator.WithChainGatewayClient(deps.gatewayClient))
}
if railGateways := buildRailGateways(deps.gatewayClient, cfg.GatewayInstances); len(railGateways) > 0 {
if deps.paymentGatewayClient != nil {
opts = append(opts, orchestrator.WithProviderSettlementGatewayClient(deps.paymentGatewayClient))
}
if railGateways := buildRailGateways(deps.gatewayClient, deps.paymentGatewayClient, cfg.GatewayInstances); len(railGateways) > 0 {
opts = append(opts, orchestrator.WithRailGateways(railGateways))
}
if deps.mntxClient != nil {
@@ -77,7 +86,7 @@ func (i *Imp) buildServiceOptions(cfg *config, deps *orchestratorDeps) []orchest
if feeAccounts := buildFeeLedgerAccounts(cfg.FeeAccounts); len(feeAccounts) > 0 {
opts = append(opts, orchestrator.WithFeeLedgerAccounts(feeAccounts))
}
if registry := buildGatewayRegistry(i.logger, deps.mntxClient, cfg.GatewayInstances, i.discoveryReg); registry != nil {
if registry := buildGatewayRegistry(i.logger, cfg.GatewayInstances, i.discoveryReg); registry != nil {
opts = append(opts, orchestrator.WithGatewayRegistry(registry))
}
return opts

View File

@@ -18,15 +18,16 @@ type Imp struct {
file string
debug bool
config *config
app *grpcapp.App[storage.Repository]
discoveryWatcher *discovery.RegistryWatcher
discoveryReg *discovery.Registry
discoveryAnnouncer *discovery.Announcer
service *orchestrator.Service
feesConn *grpc.ClientConn
ledgerClient ledgerclient.Client
gatewayClient chainclient.Client
mntxClient mntxclient.Client
oracleClient oracleclient.Client
config *config
app *grpcapp.App[storage.Repository]
discoveryWatcher *discovery.RegistryWatcher
discoveryReg *discovery.Registry
discoveryAnnouncer *discovery.Announcer
service *orchestrator.Service
feesConn *grpc.ClientConn
ledgerClient ledgerclient.Client
gatewayClient chainclient.Client
paymentGatewayClient chainclient.Client
mntxClient mntxclient.Client
oracleClient oracleclient.Client
}