diff --git a/api4/cloud.go b/api4/cloud.go index d517291d48..96bb112fef 100644 --- a/api4/cloud.go +++ b/api4/cloud.go @@ -132,6 +132,10 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) { return } + if subscriptionChange.DowngradeFeedback != nil { + c.App.Srv().GetTelemetryService().SendTelemetry("downgrade_feedback", subscriptionChange.DowngradeFeedback.ToMap()) + } + json, err := json.Marshal(changedSub) if err != nil { c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err) diff --git a/model/cloud.go b/model/cloud.go index 36c639d66c..48383f48e8 100644 --- a/model/cloud.go +++ b/model/cloud.go @@ -4,6 +4,7 @@ package model import ( + "encoding/json" "strings" ) @@ -260,9 +261,11 @@ type FailedPayment struct { type CloudWorkspaceOwner struct { UserName string `json:"username"` } + type SubscriptionChange struct { - ProductID string `json:"product_id"` - Seats int `json:"seats"` + ProductID string `json:"product_id"` + Seats int `json:"seats"` + DowngradeFeedback *DowngradeFeedback `json:"downgrade_feedback"` } type BoardsLimits struct { @@ -304,6 +307,11 @@ type CreateSubscriptionRequest struct { DiscountID string `json:"discount_id"` } +type DowngradeFeedback struct { + Reason string `json:"reason"` + Comments string `json:"comments"` +} + func (p *Product) IsYearly() bool { return p.RecurringInterval == RecurringIntervalYearly } @@ -311,3 +319,18 @@ func (p *Product) IsYearly() bool { func (p *Product) IsMonthly() bool { return p.RecurringInterval == RecurringIntervalMonthly } + +func (df *DowngradeFeedback) ToMap() map[string]any { + var res map[string]any + feedback, err := json.Marshal(df) + if err != nil { + return res + } + + err = json.Unmarshal(feedback, &res) + if err != nil { + return res + } + + return res +}