diff --git a/api/gateway/mntx/config.yml b/api/gateway/mntx/config.yml index ec21cfd..532eeb3 100644 --- a/api/gateway/mntx/config.yml +++ b/api/gateway/mntx/config.yml @@ -26,7 +26,7 @@ monetix: base_url_env: MONETIX_BASE_URL project_id_env: MONETIX_PROJECT_ID secret_key_env: MONETIX_SECRET_KEY - allowed_currencies: ["USD", "EUR"] + allowed_currencies: ["RUB"] require_customer_address: false request_timeout_seconds: 15 status_success: "success" diff --git a/api/payments/orchestrator/config.yml b/api/payments/orchestrator/config.yml index fde7feb..a5d2a19 100644 --- a/api/payments/orchestrator/config.yml +++ b/api/payments/orchestrator/config.yml @@ -51,6 +51,12 @@ gateway: call_timeout_seconds: 3 insecure: true +mntx: + address: "sendico_mntx_gateway:50075" + dial_timeout_seconds: 5 + call_timeout_seconds: 3 + insecure: true + oracle: address: "sendico_fx_oracle:50051" dial_timeout_seconds: 5 diff --git a/api/payments/orchestrator/internal/server/internal/serverimp.go b/api/payments/orchestrator/internal/server/internal/serverimp.go index 2390577..1e26c44 100644 --- a/api/payments/orchestrator/internal/server/internal/serverimp.go +++ b/api/payments/orchestrator/internal/server/internal/serverimp.go @@ -9,6 +9,7 @@ import ( oracleclient "github.com/tech/sendico/fx/oracle/client" chainclient "github.com/tech/sendico/gateway/chain/client" + mntxclient "github.com/tech/sendico/gateway/mntx/client" ledgerclient "github.com/tech/sendico/ledger/client" "github.com/tech/sendico/payments/orchestrator/internal/service/orchestrator" "github.com/tech/sendico/payments/orchestrator/storage" @@ -36,6 +37,7 @@ type Imp struct { feesConn *grpc.ClientConn ledgerClient ledgerclient.Client gatewayClient chainclient.Client + mntxClient mntxclient.Client oracleClient oracleclient.Client } @@ -44,6 +46,7 @@ type config struct { Fees clientConfig `yaml:"fees"` Ledger clientConfig `yaml:"ledger"` Gateway clientConfig `yaml:"gateway"` + Mntx clientConfig `yaml:"mntx"` Oracle clientConfig `yaml:"oracle"` CardGateways map[string]cardGatewayRouteConfig `yaml:"card_gateways"` FeeAccounts map[string]string `yaml:"fee_ledger_accounts"` @@ -105,6 +108,9 @@ func (i *Imp) Shutdown() { if i.gatewayClient != nil { _ = i.gatewayClient.Close() } + if i.mntxClient != nil { + _ = i.mntxClient.Close() + } if i.oracleClient != nil { _ = i.oracleClient.Close() } @@ -139,6 +145,11 @@ func (i *Imp) Start() error { i.gatewayClient = gatewayClient } + mntxClient := i.initMntxClient(cfg.Mntx) + if mntxClient != nil { + i.mntxClient = mntxClient + } + oracleClient := i.initOracleClient(cfg.Oracle) if oracleClient != nil { i.oracleClient = oracleClient @@ -155,6 +166,9 @@ func (i *Imp) Start() error { if gatewayClient != nil { opts = append(opts, orchestrator.WithChainGatewayClient(gatewayClient)) } + if mntxClient != nil { + opts = append(opts, orchestrator.WithMntxGateway(mntxClient)) + } if oracleClient != nil { opts = append(opts, orchestrator.WithOracleClient(oracleClient)) } @@ -192,11 +206,11 @@ func (i *Imp) initFeesClient(cfg clientConfig) (feesv1.FeeEngineClient, *grpc.Cl conn, err := grpc.DialContext(dialCtx, addr, grpc.WithTransportCredentials(creds)) if err != nil { - i.logger.Warn("failed to connect to fees service", zap.String("address", addr), zap.Error(err)) + i.logger.Warn("Failed to connect to fees service", zap.String("address", addr), zap.Error(err)) return nil, nil } - i.logger.Info("connected to fees service", zap.String("address", addr)) + i.logger.Info("Connected to fees service", zap.String("address", addr)) return feesv1.NewFeeEngineClient(conn), conn } @@ -216,10 +230,10 @@ func (i *Imp) initLedgerClient(cfg clientConfig) ledgerclient.Client { Insecure: cfg.InsecureTransport, }) if err != nil { - i.logger.Warn("failed to connect to ledger service", zap.String("address", addr), zap.Error(err)) + i.logger.Warn("Failed to connect to ledger service", zap.String("address", addr), zap.Error(err)) return nil } - i.logger.Info("connected to ledger service", zap.String("address", addr)) + i.logger.Info("Connected to ledger service", zap.String("address", addr)) return client } @@ -246,6 +260,28 @@ func (i *Imp) initGatewayClient(cfg clientConfig) chainclient.Client { return client } +func (i *Imp) initMntxClient(cfg clientConfig) mntxclient.Client { + addr := cfg.address() + if addr == "" { + return nil + } + + ctx, cancel := context.WithTimeout(context.Background(), cfg.dialTimeout()) + defer cancel() + + client, err := mntxclient.New(ctx, mntxclient.Config{ + Address: addr, + DialTimeout: cfg.dialTimeout(), + CallTimeout: cfg.callTimeout(), + }) + if err != nil { + i.logger.Warn("Failed to connect to mntx gateway service", zap.String("address", addr), zap.Error(err)) + return nil + } + i.logger.Info("Connected to mntx gateway service", zap.String("address", addr)) + return client +} + func (i *Imp) initOracleClient(cfg clientConfig) oracleclient.Client { addr := cfg.address() if addr == "" { @@ -262,10 +298,10 @@ func (i *Imp) initOracleClient(cfg clientConfig) oracleclient.Client { Insecure: cfg.InsecureTransport, }) if err != nil { - i.logger.Warn("failed to connect to oracle service", zap.String("address", addr), zap.Error(err)) + i.logger.Warn("Failed to connect to oracle service", zap.String("address", addr), zap.Error(err)) return nil } - i.logger.Info("connected to oracle service", zap.String("address", addr)) + i.logger.Info("Connected to oracle service", zap.String("address", addr)) return client }