Skip to content

Commit

Permalink
handle subscription delete
Browse files Browse the repository at this point in the history
  • Loading branch information
TeisNP committed Feb 12, 2024
1 parent 9302712 commit e4641a3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/rest/controllers/webhooks/stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ func (h *Handlers) handleWebhook(c hs.StripeContext) error {
return c.NoContent(http.StatusInternalServerError)
}

case "customer.subscription.deleted":
var subscription stripe.Subscription
err := json.Unmarshal(event.Data.Raw, &subscription)
if err != nil {
c.Log.WithError(err).Debug("Error parsing webhook JSON")
return echo.ErrBadRequest
}

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)
}

case "customer.deleted":
var customer stripe.Customer
err := json.Unmarshal(event.Data.Raw, &customer)
Expand Down

0 comments on commit e4641a3

Please sign in to comment.