From 4ec7b766583a9b37dc51191056f795b12dd947b7 Mon Sep 17 00:00:00 2001 From: lmquang Date: Wed, 12 Apr 2023 21:41:05 +0700 Subject: [PATCH] fix: bc mark invoice not working --- pkg/controller/invoice/new.go | 1 + pkg/controller/invoice/update_status.go | 18 ++++++++++++++++++ pkg/handler/webhook/basecamp.go | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/controller/invoice/new.go b/pkg/controller/invoice/new.go index fe2c19434..ff34f69f0 100644 --- a/pkg/controller/invoice/new.go +++ b/pkg/controller/invoice/new.go @@ -33,4 +33,5 @@ type IController interface { UpdateStatus(in UpdateStatusInput) (*model.Invoice, error) MarkInvoiceAsError(invoice *model.Invoice) (*model.Invoice, error) MarkInvoiceAsPaid(invoice *model.Invoice, sendThankYouEmail bool) (*model.Invoice, error) + MarkInvoiceAsPaidByBasecampWebhookMessage(invoice *model.Invoice, msg *model.BasecampWebhookMessage) (*model.Invoice, error) } diff --git a/pkg/controller/invoice/update_status.go b/pkg/controller/invoice/update_status.go index 4b758399a..c9bff1d9f 100644 --- a/pkg/controller/invoice/update_status.go +++ b/pkg/controller/invoice/update_status.go @@ -156,6 +156,24 @@ func (c *controller) MarkInvoiceAsPaid(invoice *model.Invoice, sendThankYouEmail return invoice, nil } +func (c *controller) MarkInvoiceAsPaidByBasecampWebhookMessage(invoice *model.Invoice, msg *model.BasecampWebhookMessage) (*model.Invoice, error) { + l := c.logger.Fields(logger.Fields{ + "controller": "invoice", + "method": "MarkInvoiceAsPaidByBasecampWebhookMessage", + "req": invoice, + }) + invoice.Status = model.InvoiceStatusPaid + + c.processPaidInvoice(l, &processPaidInvoiceRequest{ + Invoice: invoice, + InvoiceTodoID: msg.Recording.ID, + InvoiceBucketID: msg.Recording.Bucket.ID, + SentThankYouMail: true, + }) + + return invoice, nil +} + func (c *controller) processPaidInvoice(l logger.Logger, req *processPaidInvoiceRequest) { wg := &sync.WaitGroup{} wg.Add(3) diff --git a/pkg/handler/webhook/basecamp.go b/pkg/handler/webhook/basecamp.go index a2173e93f..52c54b606 100644 --- a/pkg/handler/webhook/basecamp.go +++ b/pkg/handler/webhook/basecamp.go @@ -113,7 +113,8 @@ func (h *handler) markInvoiceAsPaid(msg *model.BasecampWebhookMessage) error { return nil } - if _, err := h.controller.Invoice.MarkInvoiceAsPaid(invoice, true); err != nil { + // if _, err := h.controller.Invoice.MarkInvoiceAsPaid(invoice, true); err != nil { + if _, err := h.controller.Invoice.MarkInvoiceAsPaidByBasecampWebhookMessage(invoice, msg); err != nil { h.service.Basecamp.CommentResult(msg.Recording.Bucket.ID, msg.Recording.ID, h.service.Basecamp.BuildFailedComment(err.Error())) return err }