Этот коммит содержится в:
Conor Macpherson
2022-12-05 15:07:03 -05:00
родитель 352eedf7c1 43e26ccda2
Коммит 6c43daa218
34 изменённых файлов: 342 добавлений и 193 удалений

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

@@ -139,20 +139,22 @@ 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)
product, err := c.App.Cloud().GetCloudProduct(c.AppContext.Session().UserId, subscriptionChange.ProductID)
if err != nil || product == nil {
c.Logger.Error("Error finding the new cloud product", mlog.Err(err))
}
starterSku := fmt.Sprintf("%s-%s", model.SubscriptionFamilyCloud, model.ProductSkuStarter)
if changedProduct.SKU != starterSku {
if product.SKU != starterSku {
w.Write(json)
return
}
isYearly := product.IsYearly()
// 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 {
if appErr := c.App.SendUpgradeConfirmationEmail(isYearly); appErr != nil {
c.Logger.Error("Error sending purchase confirmation email", mlog.Err(appErr))
}
@@ -650,7 +652,26 @@ func handleCWSWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
case model.EventTypeSendUpgradeConfirmationEmail:
if nErr := c.App.SendUpgradeConfirmationEmail(); nErr != nil {
// isYearly determines whether to send the yearly or monthly Upgrade email
isYearly := false
if event.Subscription != nil && event.CloudWorkspaceOwner != nil {
user, appErr := c.App.GetUserByUsername(event.CloudWorkspaceOwner.UserName)
if appErr != nil {
c.Err = model.NewAppError("Api4.handleCWSWebhook", appErr.Id, nil, appErr.Error(), appErr.StatusCode)
return
}
// Get the current cloud product to determine whether it's a monthly or yearly product
product, err := c.App.Cloud().GetCloudProduct(user.Id, event.Subscription.ProductID)
if err != nil {
c.Err = model.NewAppError("Api4.handleCWSWebhook", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
return
}
isYearly = product.IsYearly()
}
if nErr := c.App.SendUpgradeConfirmationEmail(isYearly); nErr != nil {
c.Err = nErr
return
}