Add check for subscription change to product with sku cloud-starter.

Этот коммит содержится в:
Conor Macpherson
2022-12-05 14:34:51 -05:00
родитель 3059abdd88
Коммит fc8268990e
2 изменённых файлов: 24 добавлений и 2 удалений

Просмотреть файл

@@ -7,6 +7,7 @@ import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
@@ -96,6 +97,8 @@ func getSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
}
func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
userId := c.AppContext.Session().UserId
if !c.App.Channels().License().IsCloud() {
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.license_error", nil, "", http.StatusInternalServerError)
return
@@ -118,13 +121,13 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
currentSubscription, appErr := c.App.Cloud().GetSubscription(c.AppContext.Session().UserId)
currentSubscription, appErr := c.App.Cloud().GetSubscription(userId)
if appErr != nil {
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
return
}
changedSub, err := c.App.Cloud().ChangeSubscription(c.AppContext.Session().UserId, currentSubscription.ID, subscriptionChange)
changedSub, err := c.App.Cloud().ChangeSubscription(userId, currentSubscription.ID, subscriptionChange)
if err != nil {
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
return
@@ -136,6 +139,17 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
changedProduct, err := c.App.Cloud().GetCloudProduct(userId, changedSub.ProductID)
if err != nil {
c.Err = model.NewAppError("Api4.changeSubscription", "api_cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
starterSku := fmt.Sprintf("%s-%s", model.SubscriptionFamilyCloud, model.ProductSkuStarter)
if changedProduct.SKU != starterSku {
w.Write(json)
return
}
// Log failures for purchase confirmation email, but don't show an error to the user so as not to confuse them
// At this point, the upgrade is complete.
if appErr := c.App.SendUpgradeConfirmationEmail(); appErr != nil {