[MM-28217] Server API to serve up cloud customer information (#15656)

* [MM-28217] Server API to serve up cloud customer information

* Added missing client4 method

* merge'd

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Devin Binnie
2020-10-05 08:46:52 -04:00
коммит произвёл GitHub
родитель 375931a4b9
Коммит ebd3e6aa49
4 изменённых файлов: 79 добавлений и 0 удалений

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

@@ -21,6 +21,9 @@ func (api *API) InitCloud() {
api.BaseRoutes.Cloud.Handle("/payment", api.ApiSessionRequired(createCustomerPayment)).Methods("POST")
api.BaseRoutes.Cloud.Handle("/payment/confirm", api.ApiSessionRequired(confirmCustomerPayment)).Methods("POST")
// GET /api/v4/cloud/customer
api.BaseRoutes.Cloud.Handle("/customer", api.ApiSessionRequired(getCloudCustomer)).Methods("GET")
// GET /api/v4/cloud/subscription
api.BaseRoutes.Cloud.Handle("/subscription", api.ApiSessionRequired(getSubscription)).Methods("GET")
}
@@ -78,6 +81,32 @@ func getCloudProducts(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write(json)
}
func getCloudCustomer(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.Srv().License() == nil || !*c.App.Srv().License().Features.Cloud {
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.license_error", nil, "", http.StatusNotImplemented)
return
}
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
customer, appErr := c.App.Cloud().GetCloudCustomer()
if appErr != nil {
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
return
}
json, err := json.Marshal(customer)
if err != nil {
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
w.Write(json)
}
func createCustomerPayment(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.Srv().License() == nil || !*c.App.Srv().License().Features.Cloud {
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.license_error", nil, "", http.StatusNotImplemented)

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

@@ -13,5 +13,7 @@ type CloudInterface interface {
CreateCustomerPayment() (*model.StripeSetupIntent, *model.AppError)
ConfirmCustomerPayment(*model.ConfirmPaymentMethodRequest) *model.AppError
GetCloudCustomer() (*model.CloudCustomer, *model.AppError)
GetSubscription() (*model.Subscription, *model.AppError)
}

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

@@ -5651,6 +5651,19 @@ func (c *Client4) ConfirmCustomerPayment(confirmRequest *ConfirmPaymentMethodReq
return BuildResponse(r)
}
func (c *Client4) GetCloudCustomer() (*CloudCustomer, *Response) {
r, appErr := c.DoApiGet(c.GetCloudRoute()+"/customer", "")
if appErr != nil {
return nil, BuildErrorResponse(r, appErr)
}
defer closeBody(r)
var cloudCustomer *CloudCustomer
json.NewDecoder(r.Body).Decode(&cloudCustomer)
return cloudCustomer, BuildResponse(r)
}
func (c *Client4) GetSubscription() (*Subscription, *Response) {
r, appErr := c.DoApiGet(c.GetCloudRoute()+"/subscription", "")
if appErr != nil {

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

@@ -31,6 +31,41 @@ type ConfirmPaymentMethodRequest struct {
StripeSetupIntentID string `json:"stripe_setup_intent_id"`
}
// Customer model represents a customer on the system.
type CloudCustomer struct {
ID string `json:"id"`
CreatorID string `json:"creator_id"`
CreateAt int64 `json:"create_at"`
Email string `json:"email"`
Name string `json:"name"`
NumEmployees int `json:"num_employees"`
ContactFirstName string `json:"contact_first_name"`
ContactLastName string `json:"contact_last_name"`
BillingAddress *Address `json:"billing_address"`
CompanyAddress *Address `json:"company_address"`
PaymentMethod *PaymentMethod `json:"payment_method"`
}
// Address model represents a customer's address.
type Address struct {
City string `json:"city"`
Country string `json:"country"`
Line1 string `json:"line1"`
Line2 string `json:"line2"`
PostalCode string `json:"postal_code"`
State string `json:"state"`
}
// PaymentMethod represents methods of payment for a customer.
type PaymentMethod struct {
Type string `json:"type"`
LastFour int `json:"last_four"`
ExpMonth int `json:"exp_month"`
ExpYear int `json:"exp_year"`
CardBrand string `json:"card_brand"`
Name string `json:"name"`
}
// Subscription model represents a subscription on the system.
type Subscription struct {
ID string `json:"id"`