Merge pull request #236 from getAlby/chore/delete-invoices-on-failure

delete invoices when balance check fails
This commit is contained in:
kiwiidb
2022-10-28 09:41:40 +02:00
committed by GitHub
2 changed files with 4 additions and 0 deletions

View File

@@ -87,6 +87,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
currentBalance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userID)
if err != nil {
controller.svc.DB.NewDelete().Model(&invoice).Where("id = ?", invoice.ID).Exec(c.Request().Context())
return err
}
@@ -96,6 +97,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
}
if currentBalance < minimumBalance {
c.Logger().Errorf("User does not have enough balance invoice_id:%v user_id:%v balance:%v amount:%v", invoice.ID, userID, currentBalance, invoice.Amount)
controller.svc.DB.NewDelete().Model(&invoice).Where("id = ?", invoice.ID).Exec(c.Request().Context())
return c.JSON(http.StatusBadRequest, responses.NotEnoughBalanceError)
}

View File

@@ -89,6 +89,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
currentBalance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userID)
if err != nil {
controller.svc.DB.NewDelete().Model(&invoice).Where("id = ?", invoice.ID).Exec(c.Request().Context())
return err
}
@@ -98,6 +99,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
}
if currentBalance < minimumBalance {
c.Logger().Errorf("User does not have enough balance invoice_id:%v user_id:%v balance:%v amount:%v", invoice.ID, userID, currentBalance, invoice.Amount)
controller.svc.DB.NewDelete().Model(&invoice).Where("id = ?", invoice.ID).Exec(c.Request().Context())
return c.JSON(http.StatusBadRequest, responses.NotEnoughBalanceError)
}