From c5b4577c6938e99db9aa1508bfb59fa2d57d3eea Mon Sep 17 00:00:00 2001 From: elraphty Date: Tue, 22 Oct 2024 16:18:22 +0100 Subject: [PATCH] added payment pending flag --- db/structs.go | 2 ++ handlers/bounty.go | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/db/structs.go b/db/structs.go index 4491fbd88..ff45c4e3e 100644 --- a/db/structs.go +++ b/db/structs.go @@ -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 @@ -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 { diff --git a/handlers/bounty.go b/handlers/bounty.go index fc6aa0430..15b7ad509 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -656,6 +656,25 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request 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) @@ -663,7 +682,6 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request } else { // Send payment status log.Printf("[bounty] V2 Status Was not completed: %s", v2KeysendRes.Status) - paymentHistory.Status = false h.db.AddPaymentHistory(paymentHistory)