ducky/subscriptions
ducky/subscriptions/subscription_postgres.go
Export all subscriptionStore methods. We're not going to wrap all our subscriptionStore interactions in a Context type, so we need to expose all the functions so other packages can call them. Also, it's now SubscriptionStore. Also creates a SubscriptionRequest type that is used to create a new Subscription instance, along with a Validate method on it, to detect errors when creating a SubscriptionRequest. Update our CreateSubscription function to be New, and have it take a SubscriptionRequest, a Stripe instance, and a SubscriptionStore as arguments. It'll create the Subscription in the SubscriptionStore, create a customer in Stripe, and create the subscription in Stripe, then associate the Stripe subscription with the created Subscription. Also, fix our StripeSubscriptionChange function to correctly equate a missing/zero Unix timestamp from Stripe with a missing/zero time.Time.
1.1 --- a/subscription_postgres.go Tue Jun 16 23:09:59 2015 -0400 1.2 +++ b/subscription_postgres.go Mon Jun 22 18:34:07 2015 -0400 1.3 @@ -21,7 +21,7 @@ 1.4 return query.FlushExpressions(" ") 1.5 } 1.6 1.7 -func (p Postgres) reset() error { 1.8 +func (p Postgres) Reset() error { 1.9 query := p.resetSQL() 1.10 _, err := p.Exec(query.String(), query.Args...) 1.11 if err != nil { 1.12 @@ -39,7 +39,7 @@ 1.13 return query.FlushExpressions(" ") 1.14 } 1.15 1.16 -func (p Postgres) createSubscription(sub Subscription) error { 1.17 +func (p Postgres) CreateSubscription(sub Subscription) error { 1.18 query := p.createSubscriptionSQL(sub) 1.19 _, err := p.Exec(query.String(), query.Args...) 1.20 if e, ok := err.(*pq.Error); ok && e.Constraint == "subscriptions_pkey" { 1.21 @@ -71,7 +71,7 @@ 1.22 return query.FlushExpressions(" ") 1.23 } 1.24 1.25 -func (p Postgres) updateSubscription(id uuid.ID, change SubscriptionChange) error { 1.26 +func (p Postgres) UpdateSubscription(id uuid.ID, change SubscriptionChange) error { 1.27 if change.IsEmpty() { 1.28 return ErrSubscriptionChangeEmpty 1.29 } 1.30 @@ -101,7 +101,7 @@ 1.31 return query.FlushExpressions(" ") 1.32 } 1.33 1.34 -func (p Postgres) deleteSubscription(id uuid.ID) error { 1.35 +func (p Postgres) DeleteSubscription(id uuid.ID) error { 1.36 query := p.deleteSubscriptionSQL(id) 1.37 res, err := p.Exec(query.String(), query.Args...) 1.38 if err != nil { 1.39 @@ -131,7 +131,7 @@ 1.40 return query.FlushExpressions(" ") 1.41 } 1.42 1.43 -func (p Postgres) getSubscriptions(ids []uuid.ID) (map[string]Subscription, error) { 1.44 +func (p Postgres) GetSubscriptions(ids []uuid.ID) (map[string]Subscription, error) { 1.45 results := map[string]Subscription{} 1.46 if len(ids) < 1 { 1.47 return results, ErrNoSubscriptionID 1.48 @@ -190,7 +190,7 @@ 1.49 return query.FlushExpressions(" ") 1.50 } 1.51 1.52 -func (p Postgres) getSubscriptionStats() (SubscriptionStats, error) { 1.53 +func (p Postgres) GetSubscriptionStats() (SubscriptionStats, error) { 1.54 stats := SubscriptionStats{ 1.55 Plans: map[string]int64{}, 1.56 }