MM-27147 - /cloud api endpoints (#15428)

Этот коммит содержится в:
Maria A Nunez
2020-09-25 21:03:21 -04:00
коммит произвёл GitHub
родитель f74b86ae95
Коммит 88aed7ec9e
15 изменённых файлов: 296 добавлений и 8 удалений

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

@@ -334,6 +334,10 @@ func (c *Client4) GetSystemRoute() string {
return "/system"
}
func (c *Client4) GetCloudRoute() string {
return "/cloud"
}
func (c *Client4) GetTestEmailRoute() string {
return "/email/test"
}
@@ -5606,3 +5610,43 @@ func (c *Client4) UploadData(uploadId string, data io.Reader) (*FileInfo, *Respo
defer closeBody(r)
return FileInfoFromJson(r.Body), BuildResponse(r)
}
// Cloud Section
func (c *Client4) GetCloudProducts() ([]*Product, *Response) {
r, appErr := c.DoApiGet(c.GetCloudRoute()+"/products", "")
if appErr != nil {
return nil, BuildErrorResponse(r, appErr)
}
defer closeBody(r)
var cloudProducts []*Product
json.NewDecoder(r.Body).Decode(&cloudProducts)
return cloudProducts, BuildResponse(r)
}
func (c *Client4) CreateCustomerPayment() (*StripeSetupIntent, *Response) {
r, appErr := c.DoApiPost(c.GetCloudRoute()+"/payment", "")
if appErr != nil {
return nil, BuildErrorResponse(r, appErr)
}
defer closeBody(r)
var setupIntent *StripeSetupIntent
json.NewDecoder(r.Body).Decode(&setupIntent)
return setupIntent, BuildResponse(r)
}
func (c *Client4) ConfirmCustomerPayment(confirmRequest *ConfirmPaymentMethodRequest) *Response {
json, _ := json.Marshal(confirmRequest)
r, appErr := c.doApiPostBytes(c.GetCloudRoute()+"/payment/confirm", json)
if appErr != nil {
return BuildErrorResponse(r, appErr)
}
defer closeBody(r)
return BuildResponse(r)
}

32
model/cloud.go Обычный файл
Просмотреть файл

@@ -0,0 +1,32 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
// Product model represents a product on the cloud system.
type Product struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
PricePerSeat float64 `json:"price_per_seat"`
AddOns []*AddOn `json:"add_ons"`
}
// AddOn represents an addon to a product.
type AddOn struct {
ID string `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
PricePerSeat float64 `json:"price_per_seat"`
}
// StripeSetupIntent represents the SetupIntent model from Stripe for updating payment methods.
type StripeSetupIntent struct {
ID string `json:"id"`
ClientSecret string `json:"client_secret"`
}
// ConfirmPaymentMethodRequest contains the fields for the customer payment update API.
type ConfirmPaymentMethodRequest struct {
StripeSetupIntentID string `json:"stripe_setup_intent_id"`
}

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

@@ -218,6 +218,8 @@ const (
OFFICE365_SETTINGS_DEFAULT_TOKEN_ENDPOINT = "https://login.microsoftonline.com/common/oauth2/v2.0/token"
OFFICE365_SETTINGS_DEFAULT_USER_API_ENDPOINT = "https://graph.microsoft.com/v1.0/me"
CLOUD_SETTINGS_DEFAULT_CWS_URL = "https://customers.mattermost.com"
LOCAL_MODE_SOCKET_PATH = "/var/tmp/mattermost_local.socket"
)
@@ -2541,6 +2543,16 @@ func (s *JobSettings) SetDefaults() {
}
}
type CloudSettings struct {
CWSUrl *string `access:"environment,write_restrictable"`
}
func (s *CloudSettings) SetDefaults() {
if s.CWSUrl == nil {
s.CWSUrl = NewString(CLOUD_SETTINGS_DEFAULT_CWS_URL)
}
}
type PluginState struct {
Enable bool
}
@@ -2849,6 +2861,7 @@ type Config struct {
DisplaySettings DisplaySettings
GuestAccountsSettings GuestAccountsSettings
ImageProxySettings ImageProxySettings
CloudSettings CloudSettings
}
func (o *Config) Clone() *Config {
@@ -2935,6 +2948,7 @@ func (o *Config) SetDefaults() {
o.DisplaySettings.SetDefaults()
o.GuestAccountsSettings.SetDefaults()
o.ImageProxySettings.SetDefaults(o.ServiceSettings)
o.CloudSettings.SetDefaults()
}
func (o *Config) IsValid() *AppError {