From 446d4d737cda4f781fa96eacb4310401b1cababc Mon Sep 17 00:00:00 2001 From: Stephan D Date: Tue, 3 Feb 2026 15:19:06 +0100 Subject: [PATCH] better logging + fixed tg messaging --- .../internal/service/gateway/connector.go | 19 ++++++++++++------- .../internal/service/gateway/service.go | 16 +++++++++++++++- .../service/gateway/transfer_notifications.go | 10 ---------- .../tgsettle/storage/mongo/store/payments.go | 4 ++++ .../orchestrator/payment_plan_steps.go | 2 +- .../orchestrator/provider_settlement.go | 6 +++++- api/proto/gateway/chain/v1/chain.proto | 1 + 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/api/gateway/tgsettle/internal/service/gateway/connector.go b/api/gateway/tgsettle/internal/service/gateway/connector.go index 012d7562..e5a1ac8f 100644 --- a/api/gateway/tgsettle/internal/service/gateway/connector.go +++ b/api/gateway/tgsettle/internal/service/gateway/connector.go @@ -111,6 +111,8 @@ func (s *Service) SubmitOperation(ctx context.Context, req *connectorv1.SubmitOp zap.String("amount", strings.TrimSpace(normalizedAmount.GetAmount())), zap.String("currency", strings.TrimSpace(normalizedAmount.GetCurrency())), zap.String("quote_ref", quoteRef), + zap.String("operation_ref", req.Operation.GetOperationRef()), + zap.String("intent_ref", op.GetIntentRef()), zap.String("outgoing_leg", outgoingLeg), ) logFields = append(logFields, transferDestinationLogFields(dest)...) @@ -209,13 +211,15 @@ func transferToOperation(transfer *chainv1.Transfer) *connectorv1.Operation { return nil } op := &connectorv1.Operation{ - OperationId: strings.TrimSpace(transfer.GetTransferRef()), - Type: connectorv1.OperationType_TRANSFER, - Status: transferStatusToOperation(transfer.GetStatus()), - Money: transfer.GetRequestedAmount(), - ProviderRef: strings.TrimSpace(transfer.GetTransferRef()), - CreatedAt: transfer.GetCreatedAt(), - UpdatedAt: transfer.GetUpdatedAt(), + OperationId: strings.TrimSpace(transfer.GetTransferRef()), + Type: connectorv1.OperationType_TRANSFER, + Status: transferStatusToOperation(transfer.GetStatus()), + Money: transfer.GetRequestedAmount(), + ProviderRef: strings.TrimSpace(transfer.GetTransferRef()), + IntentRef: strings.TrimSpace(transfer.GetIntentRef()), + OperationRef: strings.TrimSpace(transfer.GetOperationRef()), + CreatedAt: transfer.GetCreatedAt(), + UpdatedAt: transfer.GetUpdatedAt(), } if source := strings.TrimSpace(transfer.GetSourceWalletRef()); source != "" { op.From = &connectorv1.OperationParty{Ref: &connectorv1.OperationParty_Account{Account: &connectorv1.AccountRef{ @@ -287,6 +291,7 @@ func operationLogFields(op *connectorv1.Operation) []zap.Field { zap.String("correlation_id", strings.TrimSpace(op.GetCorrelationId())), zap.String("parent_intent_id", strings.TrimSpace(op.GetParentIntentId())), zap.String("operation_type", op.GetType().String()), + zap.String("intent_ref", strings.TrimSpace(op.GetIntentRef())), } } diff --git a/api/gateway/tgsettle/internal/service/gateway/service.go b/api/gateway/tgsettle/internal/service/gateway/service.go index c0d28f50..1a62b888 100644 --- a/api/gateway/tgsettle/internal/service/gateway/service.go +++ b/api/gateway/tgsettle/internal/service/gateway/service.go @@ -169,6 +169,8 @@ func (s *Service) SubmitTransfer(ctx context.Context, req *chainv1.SubmitTransfe zap.String("rail", intent.OutgoingLeg), zap.String("organization_ref", strings.TrimSpace(req.GetOrganizationRef())), zap.String("source_wallet_ref", strings.TrimSpace(req.GetSourceWalletRef())), + zap.String("operation_ref", strings.TrimSpace(req.GetOperationRef())), + zap.String("intent_ref", strings.TrimSpace(req.GetIntentRef())), } if intent.RequestedMoney != nil { logFields = append(logFields, @@ -243,6 +245,10 @@ func (s *Service) onIntent(ctx context.Context, intent *model.PaymentGatewayInte s.logger.Warn("Payment gateway intent rejected", zap.String("reason", "payment_intent_id is required"), zap.String("idempotency_key", intent.IdempotencyKey)) return merrors.InvalidArgument("payment_intent_id is required", "payment_intent_id") } + if intent.IntentRef == "" { + s.logger.Warn("Payment gateway intent rejected", zap.String("reason", "payment_intent_ref is required"), zap.String("idempotency_key", intent.IdempotencyKey)) + return merrors.InvalidArgument("payment_intent_ref is required", "payment_intent_ref") + } if intent.RequestedMoney == nil || strings.TrimSpace(intent.RequestedMoney.Amount) == "" || strings.TrimSpace(intent.RequestedMoney.Currency) == "" { s.logger.Warn("Payment gateway intent rejected", zap.String("reason", "requested_money is required"), zap.String("idempotency_key", intent.IdempotencyKey)) return merrors.InvalidArgument("requested_money is required", "requested_money") @@ -274,7 +280,8 @@ func (s *Service) onIntent(ctx context.Context, intent *model.PaymentGatewayInte record := paymentRecordFromIntent(intent, confirmReq) if err := s.updateTransferStatus(ctx, record); err != nil { - s.logger.Warn("Failed to persist payment record", zap.Error(err), zap.String("idempotency_key", confirmReq.RequestID)) + s.logger.Warn("Failed to persist payment record", zap.Error(err), + zap.String("idempotency_key", confirmReq.RequestID), zap.String("intent_ref", record.IntentRef)) return err } if err := s.sendConfirmationRequest(confirmReq); err != nil { @@ -397,6 +404,8 @@ func (s *Service) buildConfirmationRequest(intent *model.PaymentGatewayIntent) ( TimeoutSeconds: timeout, SourceService: string(mservice.PaymentGateway), Rail: rail, + OperationRef: intent.OperationRef, + IntentRef: intent.IntentRef, }, nil } @@ -562,6 +571,10 @@ func intentFromSubmitTransfer(req *chainv1.SubmitTransferRequest, defaultRail, d if idempotencyKey == "" { return nil, merrors.InvalidArgument("submit_transfer: idempotency_key is required") } + intentRef := strings.TrimSpace(req.GetIntentRef()) + if intentRef == "" { + return nil, merrors.InvalidArgument("submit_transfer: intent_ref is required") + } amount := req.GetAmount() if amount == nil { return nil, merrors.InvalidArgument("submit_transfer: amount is required") @@ -609,6 +622,7 @@ func intentFromSubmitTransfer(req *chainv1.SubmitTransferRequest, defaultRail, d OutgoingLeg: outgoingLeg, QuoteRef: quoteRef, RequestedMoney: requestedMoney, + IntentRef: intentRef, }, nil } diff --git a/api/gateway/tgsettle/internal/service/gateway/transfer_notifications.go b/api/gateway/tgsettle/internal/service/gateway/transfer_notifications.go index aa212c7b..8a9e2958 100644 --- a/api/gateway/tgsettle/internal/service/gateway/transfer_notifications.go +++ b/api/gateway/tgsettle/internal/service/gateway/transfer_notifications.go @@ -9,7 +9,6 @@ import ( "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/pkg/payments/rail" - gatewayv1 "github.com/tech/sendico/pkg/proto/common/gateway/v1" "go.uber.org/zap" ) @@ -35,15 +34,6 @@ func toOpStatus(t *model.PaymentRecord) rail.OperationResult { } } -func toError(t *model.PaymentRecord) *gatewayv1.OperationError { - if t.Status == model.PaymentStatusSuccess { - return nil - } - return &gatewayv1.OperationError{ - Message: t.FailureReason, - } -} - func (s *Service) updateTransferStatus(ctx context.Context, record *model.PaymentRecord) error { if err := s.repo.Payments().Upsert(ctx, record); err != nil { s.logger.Warn("Failed to update transfer status", zap.String("payment_ref", record.PaymentIntentID), zap.String("status", string(record.Status)), zap.Error(err)) diff --git a/api/gateway/tgsettle/storage/mongo/store/payments.go b/api/gateway/tgsettle/storage/mongo/store/payments.go index b255b2ff..ab978271 100644 --- a/api/gateway/tgsettle/storage/mongo/store/payments.go +++ b/api/gateway/tgsettle/storage/mongo/store/payments.go @@ -82,6 +82,10 @@ func (p *Payments) Upsert(ctx context.Context, record *model.PaymentRecord) erro record.QuoteRef = strings.TrimSpace(record.QuoteRef) record.OutgoingLeg = strings.TrimSpace(record.OutgoingLeg) record.TargetChatID = strings.TrimSpace(record.TargetChatID) + record.IntentRef = strings.TrimSpace(record.IntentRef) + if record.PaymentIntentID == "" { + return merrors.InvalidArgument("intention reference is required", "payment_intent_ref") + } if record.IdempotencyKey == "" { return merrors.InvalidArgument("idempotency key is required", "idempotency_key") } diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go index 32488463..c78d6a2f 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go @@ -295,7 +295,7 @@ func (p *paymentExecutor) executeSendStep( } logger.Info("Sending provider settlement transfer", - zap.String("idempotency", req.IdempotencyKey), + zap.String("idempotency", req.IdempotencyKey), zap.String("intent_ref", req.IntentRef), ) result, err := gw.Send(ctx, req) diff --git a/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go b/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go index 5ac6536e..93fc5c76 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go +++ b/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go @@ -31,6 +31,10 @@ func (p *paymentExecutor) buildProviderSettlementTransferRequest(payment *model. if requestID == "" { return rail.TransferRequest{}, merrors.InvalidArgument("provider settlement: idempotency key is required") } + intentRef := strings.TrimSpace(payment.Intent.Ref) + if intentRef == "" { + return rail.TransferRequest{}, merrors.InvalidArgument("provider settlement: intention ref is required") + } paymentRef := strings.TrimSpace(payment.PaymentRef) if paymentRef == "" { return rail.TransferRequest{}, merrors.InvalidArgument("provider settlement: payment_ref is required") @@ -88,7 +92,7 @@ func (p *paymentExecutor) buildProviderSettlementTransferRequest(payment *model. Metadata: metadata, PaymentRef: paymentRef, OperationRef: operationRef, - IntentRef: payment.Intent.Ref, + IntentRef: intentRef, } if fromRole != nil { req.FromRole = *fromRole diff --git a/api/proto/gateway/chain/v1/chain.proto b/api/proto/gateway/chain/v1/chain.proto index 8f33ea8b..b28b484f 100644 --- a/api/proto/gateway/chain/v1/chain.proto +++ b/api/proto/gateway/chain/v1/chain.proto @@ -153,6 +153,7 @@ message Transfer { google.protobuf.Timestamp updated_at = 14; string intent_ref = 15; string payment_ref = 16; + string operation_ref = 17; } message SubmitTransferRequest { -- 2.49.1