[MM-28211] API pass-thru to the CWS for getting subscription (#15666)
* API pass-thru to the CWS for getting subscription * Remove use of parameter in favour of env var * Remove unnecessary param * Removed unnecessary fields and added client4 method * Some cleanup * Translation fix Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ca145a83bd
Коммит
2403aae0c4
@@ -20,6 +20,36 @@ func (api *API) InitCloud() {
|
|||||||
// POST /api/v4/cloud/payment/confirm
|
// POST /api/v4/cloud/payment/confirm
|
||||||
api.BaseRoutes.Cloud.Handle("/payment", api.ApiSessionRequired(createCustomerPayment)).Methods("POST")
|
api.BaseRoutes.Cloud.Handle("/payment", api.ApiSessionRequired(createCustomerPayment)).Methods("POST")
|
||||||
api.BaseRoutes.Cloud.Handle("/payment/confirm", api.ApiSessionRequired(confirmCustomerPayment)).Methods("POST")
|
api.BaseRoutes.Cloud.Handle("/payment/confirm", api.ApiSessionRequired(confirmCustomerPayment)).Methods("POST")
|
||||||
|
|
||||||
|
// GET /api/v4/cloud/subscription
|
||||||
|
api.BaseRoutes.Cloud.Handle("/subscription", api.ApiSessionRequired(getSubscription)).Methods("GET")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSubscription(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.getSubscription", "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
|
||||||
|
}
|
||||||
|
|
||||||
|
subscription, appErr := c.App.Cloud().GetSubscription()
|
||||||
|
|
||||||
|
if appErr != nil {
|
||||||
|
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
json, err := json.Marshal(subscription)
|
||||||
|
if err != nil {
|
||||||
|
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCloudProducts(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getCloudProducts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ type CloudInterface interface {
|
|||||||
|
|
||||||
CreateCustomerPayment() (*model.StripeSetupIntent, *model.AppError)
|
CreateCustomerPayment() (*model.StripeSetupIntent, *model.AppError)
|
||||||
ConfirmCustomerPayment(*model.ConfirmPaymentMethodRequest) *model.AppError
|
ConfirmCustomerPayment(*model.ConfirmPaymentMethodRequest) *model.AppError
|
||||||
|
|
||||||
|
GetSubscription() (*model.Subscription, *model.AppError)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5650,3 +5650,16 @@ func (c *Client4) ConfirmCustomerPayment(confirmRequest *ConfirmPaymentMethodReq
|
|||||||
|
|
||||||
return BuildResponse(r)
|
return BuildResponse(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client4) GetSubscription() (*Subscription, *Response) {
|
||||||
|
r, appErr := c.DoApiGet(c.GetCloudRoute()+"/subscription", "")
|
||||||
|
if appErr != nil {
|
||||||
|
return nil, BuildErrorResponse(r, appErr)
|
||||||
|
}
|
||||||
|
defer closeBody(r)
|
||||||
|
|
||||||
|
var subscription *Subscription
|
||||||
|
json.NewDecoder(r.Body).Decode(&subscription)
|
||||||
|
|
||||||
|
return subscription, BuildResponse(r)
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,3 +30,16 @@ type StripeSetupIntent struct {
|
|||||||
type ConfirmPaymentMethodRequest struct {
|
type ConfirmPaymentMethodRequest struct {
|
||||||
StripeSetupIntentID string `json:"stripe_setup_intent_id"`
|
StripeSetupIntentID string `json:"stripe_setup_intent_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subscription model represents a subscription on the system.
|
||||||
|
type Subscription struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
CustomerID string `json:"customer_id"`
|
||||||
|
ProductID string `json:"product_id"`
|
||||||
|
AddOns []string `json:"add_ons"`
|
||||||
|
StartAt int64 `json:"start_at"`
|
||||||
|
EndAt int64 `json:"end_at"`
|
||||||
|
CreateAt int64 `json:"create_at"`
|
||||||
|
Seats int `json:"seats"`
|
||||||
|
DNS string `json:"dns"`
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user