Skip to content

Commit

Permalink
Merge pull request stakwork#1966 from stakwork/feat/7days-pending-to-…
Browse files Browse the repository at this point in the history
…failed

Feat: reverse pending bounties after 7 days
  • Loading branch information
Evanfeenstra authored Nov 26, 2024
2 parents 5d2af28 + bea3954 commit e6d7e90
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
15 changes: 15 additions & 0 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,21 @@ func (h *bountyHandler) UpdateBountyPaymentStatus(w http.ResponseWriter, r *http
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(msg)
return
} else if tagResult.Status == db.PaymentPending {
if payment.PaymentStatus == db.PaymentPending {
created := utils.ConvertTimeToTimestamp(payment.Created.String())

now := time.Now()
daysDiff := utils.GetDateDaysDifference(int64(created), &now)

if daysDiff >= 7 {

err = h.db.ProcessReversePayments(payment.ID)
if err != nil {
log.Printf("Could not reverse bounty payment after 7 days : Bounty ID - %d, Payment ID - %d, Error - %s", bounty.ID, payment.ID, err)
}
}
}
}
}

Expand Down
35 changes: 26 additions & 9 deletions handlers/v2_payments_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/stakwork/sphinx-tribes/config"
"github.com/stakwork/sphinx-tribes/db"
"github.com/stakwork/sphinx-tribes/utils"
)

func InitV2PaymentsCron() {
Expand All @@ -18,12 +19,13 @@ func InitV2PaymentsCron() {
tag := payment.Tag
tagResult := GetInvoiceStatusByTag(tag)

if tagResult.Status == db.PaymentComplete {
db.DB.SetPaymentAsComplete(tag)
bounty := db.DB.GetBounty(payment.BountyId)

bounty := db.DB.GetBounty(payment.BountyId)
if bounty.ID > 0 {

if tagResult.Status == db.PaymentComplete {
db.DB.SetPaymentAsComplete(tag)

if bounty.ID > 0 {
now := time.Now()

bounty.PaymentPending = false
Expand All @@ -35,17 +37,32 @@ func InitV2PaymentsCron() {
bounty.CompletionDate = &now

db.DB.UpdateBountyPaymentStatuses(bounty)
}
} else if tagResult.Status == db.PaymentFailed {
// Handle failed payments
bounty := db.DB.GetBounty(payment.BountyId)

if bounty.ID > 0 {
} else if tagResult.Status == db.PaymentFailed {
// Handle failed payments

err := db.DB.ProcessReversePayments(payment.ID)
if err != nil {
log.Printf("Could not reverse bounty payment : Bounty ID - %d, Payment ID - %d, Error - %s", bounty.ID, payment.ID, err)
}

} else if tagResult.Status == db.PaymentPending {
if payment.PaymentStatus == db.PaymentPending {
created := utils.ConvertTimeToTimestamp(payment.Created.String())

now := time.Now()
daysDiff := utils.GetDateDaysDifference(int64(created), &now)

if daysDiff >= 7 {

err := db.DB.ProcessReversePayments(payment.ID)
if err != nil {
log.Printf("Could not reverse bounty payment after 7 days : Bounty ID - %d, Payment ID - %d, Error - %s", bounty.ID, payment.ID, err)
}
}
}
}

}
}
}
Expand Down

0 comments on commit e6d7e90

Please sign in to comment.