Skip to content

Commit

Permalink
Merge pull request #2218 from stakwork/feat/fix_7days_pending_bounties
Browse files Browse the repository at this point in the history
Refactor: Fixed 7 days payment reversal
  • Loading branch information
elraphty authored Dec 18, 2024
2 parents 5abd8f6 + 94a4d7b commit ac63ea2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ func (db database) ProcessReversePayments(paymentId uint) error {
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)
tx.Model(&NewPaymentHistory{}).Where("workspace_uuid = ?", workspace_uuid).Where("status = ?", true).Where("payment_type = ?", "withdraw").Select("SUM(amount)").Row().Scan(&withdrawalAmount)

log.Println("WithdrawalAmount =====", withdrawalAmount)

if withdrawalAmount > depositAmount {
if withdrawalAmount >= depositAmount {
tx.Rollback()
return errors.New("cannot perform this reversal")
}
Expand Down Expand Up @@ -793,5 +793,7 @@ func (db database) ProcessReversePayments(paymentId uint) error {
tx.Rollback()
}

log.Println("Reversed Payment Successfully =====", paymentId)

return tx.Commit().Error
}

0 comments on commit ac63ea2

Please sign in to comment.