added detailed logging for preauth payment processing and result streaming

This commit is contained in:
2026-10-19 17:58:46 +01:00
parent 8a5325414b
commit 28aea4aab2
6 changed files with 188 additions and 5 deletions
+11 -3
View File
@@ -11,6 +11,7 @@ import (
"time"
"gitea.futuresens.co.uk/futuresens/hardlink/internal/db"
"gitea.futuresens.co.uk/futuresens/hardlink/internal/types"
log "github.com/sirupsen/logrus"
)
@@ -74,18 +75,23 @@ func (app *App) spoolPath() string {
// It never returns an error to the caller (so your HTTP flow stays simple),
// but it logs failures.
func (app *App) persistPreauth(ctx context.Context, fields map[string]string, checkoutDate string) {
entry := log.WithFields(log.Fields{
"operation": "preauth", "reference": fields[types.Reference],
"hotel": app.cfg.Hotel, "kiosk": app.cfg.Kiosk,
})
// First, try DB (with your reconnect logic inside getDB)
dbConn, err := app.getDB(ctx)
if err == nil && dbConn != nil {
if err := db.InsertPreauth(ctx, dbConn, fields, checkoutDate); err == nil {
entry.Info("CreditCall PREAUTH SQL persistence completed")
// opportunistic drain once DB is alive
go app.drainPreauthSpool(context.Background())
return
} else {
log.WithError(err).Warn("DB insert failed; will spool preauth")
entry.WithError(err).Warn("DB insert failed; will spool preauth")
}
} else {
log.WithError(err).Warn("DB unavailable; will spool preauth")
entry.WithError(err).Warn("DB unavailable; will spool preauth")
}
// Fallback: spool to file
@@ -95,7 +101,9 @@ func (app *App) persistPreauth(ctx context.Context, fields map[string]string, ch
Fields: fields,
}
if spErr := app.spoolPreauth(rec); spErr != nil {
log.WithError(spErr).Error("failed to spool preauth")
entry.WithError(spErr).Error("failed to spool preauth")
} else {
entry.Warn("CreditCall PREAUTH saved to spool; SQL persistence pending")
}
}