ducky/subscriptions

Paddy 2015-06-22 Parent:61c4ce5850da Child:fb2c0e498e37

3:b240b6123548 Go to Latest

ducky/subscriptions/subscription_memstore.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.

History
     1.1 --- a/subscription_memstore.go	Tue Jun 16 23:09:59 2015 -0400
     1.2 +++ b/subscription_memstore.go	Mon Jun 22 18:34:07 2015 -0400
     1.3 @@ -13,7 +13,7 @@
     1.4  	return false
     1.5  }
     1.6  
     1.7 -func (m *Memstore) createSubscription(sub Subscription) error {
     1.8 +func (m *Memstore) CreateSubscription(sub Subscription) error {
     1.9  	m.subscriptionLock.Lock()
    1.10  	defer m.subscriptionLock.Unlock()
    1.11  
    1.12 @@ -27,7 +27,7 @@
    1.13  	return nil
    1.14  }
    1.15  
    1.16 -func (m *Memstore) updateSubscription(id uuid.ID, change SubscriptionChange) error {
    1.17 +func (m *Memstore) UpdateSubscription(id uuid.ID, change SubscriptionChange) error {
    1.18  	if change.IsEmpty() {
    1.19  		return ErrSubscriptionChangeEmpty
    1.20  	}
    1.21 @@ -49,7 +49,7 @@
    1.22  	return nil
    1.23  }
    1.24  
    1.25 -func (m *Memstore) deleteSubscription(id uuid.ID) error {
    1.26 +func (m *Memstore) DeleteSubscription(id uuid.ID) error {
    1.27  	m.subscriptionLock.Lock()
    1.28  	defer m.subscriptionLock.Unlock()
    1.29  
    1.30 @@ -61,7 +61,7 @@
    1.31  	return nil
    1.32  }
    1.33  
    1.34 -func (m *Memstore) getSubscriptions(ids []uuid.ID) (map[string]Subscription, error) {
    1.35 +func (m *Memstore) GetSubscriptions(ids []uuid.ID) (map[string]Subscription, error) {
    1.36  	if len(ids) < 1 {
    1.37  		return map[string]Subscription{}, ErrNoSubscriptionID
    1.38  	}
    1.39 @@ -80,7 +80,7 @@
    1.40  	return result, nil
    1.41  }
    1.42  
    1.43 -func (m *Memstore) getSubscriptionStats() (SubscriptionStats, error) {
    1.44 +func (m *Memstore) GetSubscriptionStats() (SubscriptionStats, error) {
    1.45  	m.subscriptionLock.RLock()
    1.46  	defer m.subscriptionLock.RUnlock()
    1.47