ducky/subscriptions
13:1ff031bebf9e Browse Files
Add golint comments. Comment on some more of our exported types, functions, and variables, both to make golint happy and because uncommented code never ever ends well.
1.1 --- a/memstore.go Sun Sep 27 21:20:09 2015 -0700 1.2 +++ b/memstore.go Sun Sep 27 21:20:46 2015 -0700 1.3 @@ -19,6 +19,8 @@ 1.4 } 1.5 } 1.6 1.7 +// Reset empties all the data from the Memstore. It should only 1.8 +// be used in tests. 1.9 func (m *Memstore) Reset() error { 1.10 m.subscriptionLock.Lock() 1.11 defer m.subscriptionLock.Unlock()
2.1 --- a/stripe.go Sun Sep 27 21:20:09 2015 -0700 2.2 +++ b/stripe.go Sun Sep 27 21:20:46 2015 -0700 2.3 @@ -12,22 +12,33 @@ 2.4 ) 2.5 2.6 const ( 2.7 + // PendingPlan holds the name for the plan users that haven't chosen a plan are subscribed to. 2.8 PendingPlan = "pending" 2.9 ) 2.10 2.11 var ( 2.12 - ErrNilCustomer = errors.New("nil customer passed") 2.13 - ErrNilCustomerSubs = errors.New("customer with nil subscriptions list passed") 2.14 + // ErrNilCustomer is returned when a *Customer is expected, but nil is passed. 2.15 + ErrNilCustomer = errors.New("nil customer passed") 2.16 + // ErrNilCustomerSubs is returned when *Customer.Subs is expected to be a slice, but is nil. 2.17 + ErrNilCustomerSubs = errors.New("customer with nil subscriptions list passed") 2.18 + // ErrWrongNumberOfCustomerSubs is returned when a *Customer.Subs slice has more or fewer elements than expected. 2.19 ErrWrongNumberOfCustomerSubs = errors.New("customer with wrong number of subscriptions passed") 2.20 - ErrNilSubscription = errors.New("nil subscription passed") 2.21 + // ErrNilSubscription is returned when a *Subscription is expected, but nil is passed. 2.22 + ErrNilSubscription = errors.New("nil subscription passed") 2.23 ) 2.24 2.25 +// Stripe is a wrapper around the clients for Stripe that we're using. It's responsible for 2.26 +// all the interaction with the Stripe API that we're doing. It is a level higher than the 2.27 +// raw Stripe clients, and can be thought of as Stripe-from-the-perspective-of-subscriptions. 2.28 type Stripe struct { 2.29 apiKey string 2.30 customers customer.Client 2.31 subscriptions sub.Client 2.32 } 2.33 2.34 +// NewStripe creates a new Stripe instance using the passed parameters. The stripe.Backend 2.35 +// parameter can be used to create a stub instead of something that actually hits the Stripe 2.36 +// API. See the github.com/stripe/stripe-go documentation for more information about Backends. 2.37 func NewStripe(apiKey string, backend stripe.Backend) Stripe { 2.38 return Stripe{ 2.39 apiKey: apiKey, 2.40 @@ -42,6 +53,9 @@ 2.41 } 2.42 } 2.43 2.44 +// CreateStripeCustomer sets up a customer using the passed Stripe client, ensuring it follows all 2.45 +// the conventions that subscriptions expects (the description being set properly, the UserID meta, 2.46 +// etc.) Creating a customer automatically creates a subscription for that customer. 2.47 func CreateStripeCustomer(plan, email string, userID uuid.ID, s Stripe) (*stripe.Customer, error) { 2.48 customerParams := &stripe.CustomerParams{ 2.49 Desc: "Customer for user " + userID.String(), 2.50 @@ -56,6 +70,8 @@ 2.51 return c, nil 2.52 } 2.53 2.54 +// UpdateStripeSubscription modifies a subscription in Stripe, updating the plan and/or token. 2.55 +// A nil plan or token indicates no change to the parameter. 2.56 func UpdateStripeSubscription(customerID string, plan, token *string, s Stripe) (*stripe.Sub, error) { 2.57 params := &stripe.SubParams{} 2.58 if plan != nil { 2.59 @@ -110,6 +126,8 @@ 2.60 return subscription, nil 2.61 } 2.62 2.63 +// StripeSubscriptionChange takes a Subscription and a stripe.Sub, and returns a SubscriptionChange 2.64 +// that will change only the properties necessary to make the Subscription match the stripe.Sub. 2.65 func StripeSubscriptionChange(orig Subscription, subscription stripe.Sub) SubscriptionChange { 2.66 var change SubscriptionChange 2.67 if subscription.ID != orig.StripeSubscription {