Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Added more logs for reversal #2208

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package db
import (
"errors"
"fmt"
"log"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -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")
Expand Down
Loading