// GetCustomer returns the customer info of a group func GetCustomer(u *url.URL, h http.Header, _ interface{}, context *models.Context) (int, http.Header, interface{}, error) { if err := context.IsGroupAdmin(); err != nil { return response.NewBadRequest(err) } return response.HandleResultAndError( payment.GetCustomerForGroup(context.GroupName), ) }
// ListMembers lists the members of group func ListMembers(u *url.URL, h http.Header, _ interface{}, context *models.Context) (int, http.Header, interface{}, error) { if err := context.IsGroupAdmin(); err != nil { return response.NewBadRequest(err) } query := request.GetQuery(u) query = context.OverrideQuery(query) p := &models.PresenceDaily{} return response.HandleResultAndError(p.FetchActiveAccounts(query)) }
// DeleteCreditCard deletes the credit card of a group func DeleteCreditCard(u *url.URL, h http.Header, _ interface{}, context *models.Context) (int, http.Header, interface{}, error) { if err := context.IsGroupAdmin(); err != nil { return response.NewBadRequest(err) } if err := payment.DeleteCreditCardForGroup(context.GroupName); err != nil { return response.NewBadRequest(err) } return response.NewDefaultOK() }
// CreateCustomer creates the customer for a group func CreateCustomer(u *url.URL, h http.Header, req *stripe.CustomerParams, context *models.Context) (int, http.Header, interface{}, error) { if err := context.IsGroupAdmin(); err != nil { return response.NewBadRequest(err) } return response.HandleResultAndError( payment.EnsureCustomerForGroup( context.Client.Account.Nick, context.GroupName, req, ), ) }
// Info return usage info for a group func Info(u *url.URL, h http.Header, _ interface{}, context *models.Context) (int, http.Header, interface{}, error) { if err := context.IsGroupAdmin(); err != nil { return response.NewBadRequest(err) } group, err := modelhelper.GetGroup(context.GroupName) if err != nil { return response.NewBadRequest(err) } return response.HandleResultAndError( payment.EnsureInfoForGroup(group, context.Client.Account.Nick), ) }
// DeleteCustomer deletes customer for a group. Here for symmetry. func DeleteCustomer(u *url.URL, h http.Header, _ interface{}, context *models.Context) (int, http.Header, interface{}, error) { // do not allow customer deletion, causes losing track of transactions. return http.StatusForbidden, nil, nil, nil if err := context.IsGroupAdmin(); err != nil { return response.NewBadRequest(err) } if err := payment.DeleteCustomerForGroup(context.GroupName); err != nil { return response.NewBadRequest(err) } return response.NewDeleted() }
// ListInvoice lists invoices of group func ListInvoice(u *url.URL, h http.Header, _ interface{}, context *models.Context) (int, http.Header, interface{}, error) { if err := context.IsGroupAdmin(); err != nil { return response.NewBadRequest(err) } urlQuery := u.Query() limit, _ := strconv.Atoi(urlQuery.Get("limit")) if limit == 0 { limit = 10 } return response.HandleResultAndError( payment.ListInvoicesForGroup( context.GroupName, urlQuery.Get("startingAfter"), limit, ), ) }