From 43c4866ad7dd67e48c805b7ca9b1d52fa6ad649b Mon Sep 17 00:00:00 2001 From: Stephan D Date: Thu, 4 Dec 2025 21:50:49 +0100 Subject: [PATCH] +logging --- .../service/gateway/card_processor.go | 41 +++++++++++++++++++ .../mntx/internal/service/monetix/sender.go | 1 + 2 files changed, 42 insertions(+) diff --git a/api/gateway/mntx/internal/service/gateway/card_processor.go b/api/gateway/mntx/internal/service/gateway/card_processor.go index 7cc10db..8640ede 100644 --- a/api/gateway/mntx/internal/service/gateway/card_processor.go +++ b/api/gateway/mntx/internal/service/gateway/card_processor.go @@ -46,11 +46,17 @@ func (p *cardPayoutProcessor) Submit(ctx context.Context, req *mntxv1.CardPayout return nil, merrors.Internal("card payout processor not initialised") } if strings.TrimSpace(p.config.BaseURL) == "" || strings.TrimSpace(p.config.SecretKey) == "" { + p.logger.Warn("monetix configuration is incomplete for payout submission") return nil, merrors.Internal("monetix configuration is incomplete") } req = sanitizeCardPayoutRequest(req) if err := validateCardPayoutRequest(req, p.config); err != nil { + p.logger.Warn("card payout validation failed", + zap.String("payout_id", req.GetPayoutId()), + zap.String("customer_id", req.GetCustomerId()), + zap.Error(err), + ) return nil, err } @@ -59,6 +65,7 @@ func (p *cardPayoutProcessor) Submit(ctx context.Context, req *mntxv1.CardPayout projectID = p.config.ProjectID } if projectID == 0 { + p.logger.Warn("monetix project_id is not configured", zap.String("payout_id", req.GetPayoutId())) return nil, merrors.Internal("monetix project_id is not configured") } @@ -88,6 +95,11 @@ func (p *cardPayoutProcessor) Submit(ctx context.Context, req *mntxv1.CardPayout state.ProviderMessage = err.Error() state.UpdatedAt = timestamppb.New(p.clock.Now()) p.store.Save(state) + p.logger.Warn("monetix payout submission failed", + zap.String("payout_id", req.GetPayoutId()), + zap.String("customer_id", req.GetCustomerId()), + zap.Error(err), + ) return nil, err } @@ -118,11 +130,17 @@ func (p *cardPayoutProcessor) SubmitToken(ctx context.Context, req *mntxv1.CardT return nil, merrors.Internal("card payout processor not initialised") } if strings.TrimSpace(p.config.BaseURL) == "" || strings.TrimSpace(p.config.SecretKey) == "" { + p.logger.Warn("monetix configuration is incomplete for token payout submission") return nil, merrors.Internal("monetix configuration is incomplete") } req = sanitizeCardTokenPayoutRequest(req) if err := validateCardTokenPayoutRequest(req, p.config); err != nil { + p.logger.Warn("card token payout validation failed", + zap.String("payout_id", req.GetPayoutId()), + zap.String("customer_id", req.GetCustomerId()), + zap.Error(err), + ) return nil, err } @@ -131,6 +149,7 @@ func (p *cardPayoutProcessor) SubmitToken(ctx context.Context, req *mntxv1.CardT projectID = p.config.ProjectID } if projectID == 0 { + p.logger.Warn("monetix project_id is not configured", zap.String("payout_id", req.GetPayoutId())) return nil, merrors.Internal("monetix project_id is not configured") } @@ -160,6 +179,11 @@ func (p *cardPayoutProcessor) SubmitToken(ctx context.Context, req *mntxv1.CardT state.ProviderMessage = err.Error() state.UpdatedAt = timestamppb.New(p.clock.Now()) p.store.Save(state) + p.logger.Warn("monetix token payout submission failed", + zap.String("payout_id", req.GetPayoutId()), + zap.String("customer_id", req.GetCustomerId()), + zap.Error(err), + ) return nil, err } @@ -191,6 +215,11 @@ func (p *cardPayoutProcessor) Tokenize(ctx context.Context, req *mntxv1.CardToke } cardInput, err := validateCardTokenizeRequest(req, p.config) if err != nil { + p.logger.Warn("card tokenization validation failed", + zap.String("request_id", req.GetRequestId()), + zap.String("customer_id", req.GetCustomerId()), + zap.Error(err), + ) return nil, err } @@ -199,6 +228,7 @@ func (p *cardPayoutProcessor) Tokenize(ctx context.Context, req *mntxv1.CardToke projectID = p.config.ProjectID } if projectID == 0 { + p.logger.Warn("monetix project_id is not configured", zap.String("request_id", req.GetRequestId())) return nil, merrors.Internal("monetix project_id is not configured") } @@ -208,6 +238,11 @@ func (p *cardPayoutProcessor) Tokenize(ctx context.Context, req *mntxv1.CardToke apiReq := buildCardTokenizeRequest(projectID, req, cardInput) result, err := client.CreateCardTokenization(ctx, apiReq) if err != nil { + p.logger.Warn("monetix tokenization request failed", + zap.String("request_id", req.GetRequestId()), + zap.String("customer_id", req.GetCustomerId()), + zap.Error(err), + ) return nil, err } @@ -233,11 +268,13 @@ func (p *cardPayoutProcessor) Status(_ context.Context, payoutID string) (*mntxv id := strings.TrimSpace(payoutID) if id == "" { + p.logger.Warn("payout status requested with empty payout_id") return nil, merrors.InvalidArgument("payout_id is required", "payout_id") } state, ok := p.store.Get(id) if !ok || state == nil { + p.logger.Warn("payout status not found", zap.String("payout_id", id)) return nil, merrors.NoData("payout not found") } return state, nil @@ -248,18 +285,22 @@ func (p *cardPayoutProcessor) ProcessCallback(ctx context.Context, payload []byt return http.StatusInternalServerError, merrors.Internal("card payout processor not initialised") } if len(payload) == 0 { + p.logger.Warn("received empty Monetix callback payload") return http.StatusBadRequest, merrors.InvalidArgument("callback body is empty") } if strings.TrimSpace(p.config.SecretKey) == "" { + p.logger.Warn("monetix secret key is not configured; cannot verify callback") return http.StatusInternalServerError, merrors.Internal("monetix secret key is not configured") } var cb monetixCallback if err := json.Unmarshal(payload, &cb); err != nil { + p.logger.Warn("failed to unmarshal Monetix callback", zap.Error(err)) return http.StatusBadRequest, err } if strings.TrimSpace(cb.Signature) == "" { + p.logger.Warn("Monetix callback signature is missing", zap.String("payout_id", cb.Payment.ID)) return http.StatusBadRequest, merrors.InvalidArgument("signature is missing") } if err := verifyCallbackSignature(cb, p.config.SecretKey); err != nil { diff --git a/api/gateway/mntx/internal/service/monetix/sender.go b/api/gateway/mntx/internal/service/monetix/sender.go index 3757716..e9ad47c 100644 --- a/api/gateway/mntx/internal/service/monetix/sender.go +++ b/api/gateway/mntx/internal/service/monetix/sender.go @@ -111,6 +111,7 @@ func (c *Client) sendTokenization(ctx context.Context, req CardTokenizeRequest) duration := time.Since(start) if err != nil { observeRequest(outcomeNetworkError, duration) + c.logger.Warn("monetix tokenization request failed", zap.Error(err)) return nil, merrors.Internal("monetix tokenization request failed: " + err.Error()) } defer resp.Body.Close()