ducky/subscriptions

Paddy 2015-07-18 Parent:b240b6123548 Child:1ff031bebf9e

10:2c8250237566 Go to Latest

ducky/subscriptions/memstore.go

Update subscription_creator to use the new strategy. When creating subscriptions through the client, detect when the returned error is saying the account already has a subscription, or the subscription already exists in stripe. Add an UpdateSubscription function that will update a subscription through the API. Update our subscription_creator listener to listen for profile creation and login verification messages. This mainly involved fixing the constants (the system, model, and topic) that the listener for profile creation was listening for. It also meant adding a new updateMessageHandler that listens for login verification, tries to create a subscription that has the user ID and email of the login that was verified, and if a subscription already exists, updates it instead to use the email address that was just verified. This will ensure that users get their receipts automatically emailed to them by Stripe.

History
1 package subscriptions
3 import (
4 "sync"
5 )
7 // Memstore is an in-memory version of our datastores, useful
8 // for testing. It should not be used in production.
9 type Memstore struct {
10 subscriptions map[string]Subscription
11 subscriptionLock sync.RWMutex
12 }
14 // NewMemstore returns a pointer to a Memstore object, ready
15 // to be used as a datastore.
16 func NewMemstore() *Memstore {
17 return &Memstore{
18 subscriptions: map[string]Subscription{},
19 }
20 }
22 func (m *Memstore) Reset() error {
23 m.subscriptionLock.Lock()
24 defer m.subscriptionLock.Unlock()
26 m.subscriptions = map[string]Subscription{}
27 return nil
28 }