Esempio n. 1
0
// 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),
	)
}
Esempio n. 2
0
// 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))
}
Esempio n. 3
0
// 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()
}
Esempio n. 4
0
// 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,
		),
	)
}
Esempio n. 5
0
// 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),
	)
}
Esempio n. 6
0
// 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()
}
Esempio n. 7
0
// 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,
		),
	)
}