diff --git a/handlers/v2_payments_cron.go b/handlers/v2_payments_cron.go index ae2d6be81..869227513 100644 --- a/handlers/v2_payments_cron.go +++ b/handlers/v2_payments_cron.go @@ -14,14 +14,14 @@ import ( ) func InitV2PaymentsCron() { + log.Println("Pending Invoice Cron Job Started") paymentHistories := db.DB.GetPendingPaymentHistory() for _, payment := range paymentHistories { - tag := payment.Tag - tagResult := GetInvoiceStatusByTag(tag) - bounty := db.DB.GetBounty(payment.BountyId) if bounty.ID > 0 { + tag := payment.Tag + tagResult := GetInvoiceStatusByTag(tag) if tagResult.Status == db.PaymentComplete { db.DB.SetPaymentAsComplete(tag) @@ -37,32 +37,37 @@ func InitV2PaymentsCron() { bounty.CompletionDate = &now db.DB.UpdateBountyPaymentStatuses(bounty) - - } 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 { + log.Println("Payment Status From V2 BOT IS Pending", payment) if payment.PaymentStatus == db.PaymentPending { + log.Println("Payment Status From DB IS Pending", payment) created := utils.ConvertTimeToTimestamp(payment.Created.String()) now := time.Now() daysDiff := utils.GetDateDaysDifference(int64(created), &now) + log.Println("Payment Date Difference Is", daysDiff) + if daysDiff >= 7 { + log.Println("Payment Date Difference Is Greater Or Equals 7 Days", payment) + 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) } } } - } + } 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 { + log.Println("Payment Status From V2 BOT IS Unknown", payment, tagResult) + } } } } @@ -99,7 +104,7 @@ func GetInvoiceStatusByTag(tag string) db.V2TagRes { err = json.Unmarshal(body, &tagRes) if err != nil { - log.Printf("Could not unmarshall get tag result: %s", err) + log.Printf("Could not unmarshal get tag result: %s", err) } resultLength := len(tagRes) diff --git a/main.go b/main.go index 793e6ae6c..58843ddf5 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,7 @@ func main() { func runCron() { c := cron.New() - c.AddFunc("@every 00h30m00s", handlers.InitV2PaymentsCron) + c.AddFunc("@every 0h30m0s", handlers.InitV2PaymentsCron) c.Start() } diff --git a/routes/index.go b/routes/index.go index 4b727df43..030a04db8 100644 --- a/routes/index.go +++ b/routes/index.go @@ -62,8 +62,8 @@ func NewRouter() *http.Server { r.Get("/poll/{challenge}", db.Poll) r.Post("/save", db.PostSave) r.Get("/save/{key}", db.PollSave) - r.Get("/websocket", handlers.HandleWebSocket) r.Get("/migrate_bounties", handlers.MigrateBounties) + r.Get("/websocket", handlers.HandleWebSocket) }) r.Group(func(r chi.Router) { diff --git a/websocket/pool.go b/websocket/pool.go index 3270e98ae..39e03c1dc 100644 --- a/websocket/pool.go +++ b/websocket/pool.go @@ -41,12 +41,10 @@ func (pool *Pool) Start() { } else { fmt.Println("Websocket pool client save error") } - break case client := <-pool.Unregister: pool.Clients[client.Host].Client.Conn.WriteJSON(Message{Type: 1, Body: "User Disconnected..."}) delete(pool.Clients, client.Host) fmt.Println("Size of Connection Pool: ", len(pool.Clients)) - break case message := <-pool.Broadcast: fmt.Println("Sending message to all clients in Pool") for client, _ := range pool.Clients { diff --git a/websocket/websocket.go b/websocket/websocket.go index 0431c906b..5ee4d2c1f 100644 --- a/websocket/websocket.go +++ b/websocket/websocket.go @@ -40,6 +40,7 @@ func ServeWs(pool *Pool, w http.ResponseWriter, r *http.Request) { conn, err := Upgrade(w, r) if err != nil { + fmt.Println("Error in ServeWs", err) fmt.Fprintf(w, "%+v\n", err) }