From 26df2ec4903ad309c7da7530cb3badbc8d652a98 Mon Sep 17 00:00:00 2001 From: elraphty Date: Tue, 17 Dec 2024 06:16:46 +0100 Subject: [PATCH] added more logs for reversal --- db/workspaces.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/db/workspaces.go b/db/workspaces.go index 382bff574..71965fa06 100644 --- a/db/workspaces.go +++ b/db/workspaces.go @@ -3,6 +3,7 @@ package db import ( "errors" "fmt" + "log" "net/http" "strings" "time" @@ -724,15 +725,26 @@ func (db database) ProcessReversePayments(paymentId uint) error { paymentHistory.PaymentStatus = PaymentFailed workspace_uuid := paymentHistory.WorkspaceUuid + log.Println("WorkspaceUuid =====", workspace_uuid) + + // get workspace + workspace := Workspace{} + tx.Model(&Workspace{}).Where("uuid = ?", workspace_uuid).Find(&workspace) + + log.Println("Workspace =====", workspace) // check that the sum of budget withdrawals and payments is not greater than deposits var depositAmount uint tx.Model(&NewPaymentHistory{}).Where("workspace_uuid = ?", workspace_uuid).Where("status = ?", true).Where("payment_type = ?", "deposit").Select("SUM(amount)").Row().Scan(&depositAmount) + log.Println("DepositAmount =====", depositAmount) + var withdrawalAmount uint tx.Model(&NewPaymentHistory{}).Where("workspace_uuid = ?", workspace_uuid).Where("status = ?", true).Where("payment_type != ?", "deposit").Select("SUM(amount)").Row().Scan(&withdrawalAmount) + log.Println("WithdrawalAmount =====", withdrawalAmount) + if withdrawalAmount > depositAmount { tx.Rollback() return errors.New("cannot perform this reversal")