Skip to content

Commit

Permalink
corrected webhook update
Browse files Browse the repository at this point in the history
  • Loading branch information
TeisNP committed Feb 4, 2024
1 parent 1aac98c commit d3e61a0
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions internal/rest/controllers/webhooks/stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ func (h *Handlers) handleWebhook(c hs.StripeContext) error {
return echo.ErrBadRequest
}

if subscription.Status == "canceled" {
team, err := h.TeamService.GetByStripeID(c.Request().Context(), subscription.Customer.ID)
if err != nil {
c.Log.WithError(err).Debug("Error getting team by stripe id")
return c.NoContent(http.StatusInternalServerError)
}
team, err := h.TeamService.GetByStripeID(c.Request().Context(), subscription.Customer.ID)
if err != nil {
c.Log.WithError(err).Debug("Error getting team by stripe id")
return c.NoContent(http.StatusInternalServerError)
}
team.PaymentPlan = subscription.Items.Data[0].Price.LookupKey

if subscription.Status == "canceled" {
team.PaymentPlan = "FREE"
err = h.TeamService.UpdateTeam(c.Request().Context(), team)
if err != nil {
c.Log.WithError(err).Debug("Error updating team")
return c.NoContent(http.StatusInternalServerError)
}
}

err = h.TeamService.UpdateTeam(c.Request().Context(), team)
if err != nil {
c.Log.WithError(err).Debug("Error updating team")
return c.NoContent(http.StatusInternalServerError)
}

case "customer.deleted":
Expand Down

0 comments on commit d3e61a0

Please sign in to comment.