Documentation ¶
Index ¶
- func NewClient(oauthConf *oauth2.Config, token *oauth2.Token) *github.Client
- type Discount
- type Invoice
- type Subscription
- type User
- func (u *User) CancelStripeSubscription(id string, endCancel bool) error
- func (u *User) DisableInstallation(installationID int) error
- func (u *User) EnableInstallation(installationID int) error
- func (u *User) EnabledInstallations() ([]int, error)
- func (u *User) GitHubListOrgMembershipsActive(ctx context.Context) ([]*github.Membership, error)
- func (u *User) InstallationEnabled(installationID int) bool
- func (u *User) ProcessStripeCoupon(couponID string) error
- func (u *User) ProcessStripePayment(token, plan string) error
- func (u *User) StripeCustomer() (*stripe.Customer, error)
- func (u *User) StripeDiscount(customer *stripe.Customer) *Discount
- func (u *User) StripeSubscriptions(customer *stripe.Customer) []Subscription
- func (u *User) StripeUpcomingInvoice() (*Invoice, error)
- type UserManager
- func (um *UserManager) GetUser(userID int) (*User, error)
- func (um *UserManager) GitHubLogin(ctx context.Context, githubID int, token *oauth2.Token) (userID int, err error)
- func (um *UserManager) OAuthCallbackHandler(w http.ResponseWriter, r *http.Request)
- func (um *UserManager) OAuthLoginHandler(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Subscription ¶
type Subscription struct { ID string Name string // Name is the plan name. AmountDisplay string // AmountDisplay is the amount formatted for display. AmountCents uint // AmountCents is the amount in cents. Interval string // Interval is the billing interval, such as month. StartedAt time.Time // StartedAt is the date started. PeriodEndAt time.Time // PeriodEndAt is the end date of the current interval. CancelledAt time.Time // CancelledAt is the date the subscription was cancelled. // EndedAt is the date the subscription finally ended (it may have been // cancelled and ended at the period end). EndedAt time.Time // Ended is whether the subcription is currently active (it maybe cancelled, // but not currently ended). Ended bool }
Subscription represents a payment subscription.
type User ¶
type User struct { Logger *logrus.Entry GHClient *github.Client UserID int `db:"id"` Email string `db:"email"` GitHubID int `db:"github_id"` GitHubToken []byte `db:"github_token"` // nil if none assigned to user StripeCustomerID string `db:"stripe_customer_id"` // contains filtered or unexported fields }
User represents a GopherCI-web user.
func GetUser ¶
func GetUser(logger *logrus.Entry, db *sqlx.DB, oauthConf *oauth2.Config, userID int) (*User, error)
GetUser looks up a user in the db and returns it, if no user was found, user is nil, if an error occurs it will be returned.
func (*User) CancelStripeSubscription ¶
CancelStripeSubscription cancels a stripe subscription at the end of the current billing period if endCancel is true. It does not disable any enabled installations.
func (*User) DisableInstallation ¶
DisableInstallation marks a GitHub installation as disabled for this user. This does not disable the installation in GopherCI. Returns an error if an error occurred, else success if successfully changed from enabled to disabled.
func (*User) EnableInstallation ¶
EnableInstallation marks a GitHub installation as enabled for this user. This does not enable the installation in GopherCI. Returns an error if an error occured, else success if successfully changed from disabled to enabled.
func (*User) EnabledInstallations ¶
EnabledInstallations returns a slice of installationIDs that are marked as enabled by for the user.
func (*User) GitHubListOrgMembershipsActive ¶
GitHubListOrgMembershipsActive returns active https://godoc.org/github.com/google/go-github/github#OrganizationsService.ListOrgMemberships
func (*User) InstallationEnabled ¶
InstallationEnabled checks if installationID is enabled by this user, any error means installation is not enabled by this user.
func (*User) ProcessStripeCoupon ¶
ProcessStripeCoupon adds a couponID to a stripe customer.
func (*User) ProcessStripePayment ¶
func (*User) StripeCustomer ¶
StripeCustomer gets the stripe customer, returns nil if there's no stripe customer ID or an error if an error occurs.
func (*User) StripeDiscount ¶
StripeDiscount returns the discount for the current user. If the user does not have an active discount, nil is returned.
func (*User) StripeSubscriptions ¶
func (u *User) StripeSubscriptions(customer *stripe.Customer) []Subscription
StripeSubscriptions returns a slice of subscriptions for the current user, both current and previous subscriptions are returned.
func (*User) StripeUpcomingInvoice ¶
StripeUpcomingInvoice returns the upcoming invoice for a user, nil if there are no upcoming invoices for this user, or an error.
type UserManager ¶
type UserManager struct {
// contains filtered or unexported fields
}
UserManager manages all the user accounts.
func NewUserManager ¶
func NewUserManager(logger *logrus.Entry, db *sqlx.DB, clientID, clientSecret, stripeKey string) *UserManager
NewUserManager returns a new UserManager initialised with db and GitHub clientID and clientSecret.
func (*UserManager) GetUser ¶
func (um *UserManager) GetUser(userID int) (*User, error)
GetUser returns a user for a given UserID, returns nil if user is not found or an error.
func (*UserManager) GitHubLogin ¶
func (um *UserManager) GitHubLogin(ctx context.Context, githubID int, token *oauth2.Token) (userID int, err error)
GitHubLogin assigns the token to an existing user with the given githubID, if the user does not exist, the user is created. If an error occurs err is non-nil, else the userID of the user is returned.
func (*UserManager) OAuthCallbackHandler ¶
func (um *UserManager) OAuthCallbackHandler(w http.ResponseWriter, r *http.Request)
OAuthCallbackHandler handles the callback after GitHub authentication and persists the credentials to storage for use later.
func (*UserManager) OAuthLoginHandler ¶
func (um *UserManager) OAuthLoginHandler(w http.ResponseWriter, r *http.Request)
OAuthLoginHandler starts the initial oauth login flow by redirecting the user to GitHub for authentication and authorisation our app.