Skip to content

Commit

Permalink
fix: bc mark invoice not working
Browse files Browse the repository at this point in the history
  • Loading branch information
lmquang committed Apr 12, 2023
1 parent be49bea commit 4ec7b76
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/controller/invoice/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 18 additions & 0 deletions pkg/controller/invoice/update_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/handler/webhook/basecamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4ec7b76

Please sign in to comment.