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

PR: fixed V2 payment history for failed payments #1900

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ type Bounty struct {
CodingLanguages pq.StringArray `gorm:"type:text[];not null default:'[]'" json:"coding_languages"`
PhaseUuid *string `json:"phase_uuid"`
PhasePriority *int `json:"phase_priority"`
PaymentPending bool `gorm:"default:false" json:"payment_pending"`
}

// Todo: Change back to Bounty
Expand Down Expand Up @@ -427,6 +428,7 @@ type NewBounty struct {
CodingLanguages pq.StringArray `gorm:"type:text[];not null default:'[]'" json:"coding_languages"`
PhaseUuid string `json:"phase_uuid"`
PhasePriority int `json:"phase_priority"`
PaymentPending bool `gorm:"default:false" json:"payment_pending"`
}

type BountyOwners struct {
Expand Down
11 changes: 0 additions & 11 deletions db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,6 @@ func (db database) WithdrawBudget(sender_pubkey string, workspace_uuid string, a
func (db database) AddPaymentHistory(payment NewPaymentHistory) NewPaymentHistory {
db.db.Create(&payment)

// get Workspace budget and subtract payment from total budget
WorkspaceBudget := db.GetWorkspaceBudget(payment.WorkspaceUuid)
totalBudget := WorkspaceBudget.TotalBudget

// deduct amount if it's a bounty payment
if payment.PaymentType == "payment" {
WorkspaceBudget.TotalBudget = totalBudget - payment.Amount
}

db.UpdateWorkspaceBudget(WorkspaceBudget)

return payment
}

Expand Down
22 changes: 21 additions & 1 deletion handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
BountyId: id,
Created: &now,
Updated: &now,
Status: true,
Status: false,
PaymentType: "payment",
Tag: v2KeysendRes.Tag,
PaymentStatus: v2KeysendRes.Status,
Expand All @@ -649,12 +649,32 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
bounty.PaidDate = &now
bounty.Completed = true
bounty.CompletionDate = &now
paymentHistory.Status = true

h.db.ProcessBountyPayment(paymentHistory, bounty)

msg["msg"] = "keysend_success"
msg["invoice"] = ""

socket, err := h.getSocketConnections(request.Websocket_token)
if err == nil {
socket.Conn.WriteJSON(msg)
}
} else if v2KeysendRes.Status == db.PaymentPending {
// Send payment status
log.Printf("[bounty] V2 Status is pending: %s", v2KeysendRes.Status)
bounty.Paid = false
bounty.PaymentPending = true
bounty.PaidDate = &now
bounty.Completed = true
bounty.CompletionDate = &now
paymentHistory.Status = true

h.db.ProcessBountyPayment(paymentHistory, bounty)

msg["msg"] = "keysend_pending"
msg["invoice"] = ""

socket, err := h.getSocketConnections(request.Websocket_token)
if err == nil {
socket.Conn.WriteJSON(msg)
Expand Down
Loading