ducky/subscriptions

Paddy 2015-07-18 Parent:f1a22fc2321d

10:2c8250237566 Go to Latest

ducky/subscriptions/postgres.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 "database/sql"
5 )
7 // NewPostgres returns a usable Postgres instance, if and only
8 // if error is nil. If error is not nil, the returned Postgres
9 // instance should not be used.
10 func NewPostgres(conn string) (Postgres, error) {
11 db, err := sql.Open("postgres", conn)
12 if err != nil {
13 return Postgres{}, err
14 }
15 return Postgres{db}, nil
16 }
18 // Postgres represents a thin wrapper around *sql.DB, so we can
19 // inherit its methods but also define our own (so we can fulfill
20 // our subscriptionStore interface on Postgres). Note that the
21 // value of a Postgres variable contains a _pointer_ to an sql.DB
22 // pool of connections, so it's not necessary to use the address of
23 // the Postgres variable itself (though there shouldn't be any harm
24 // in doing so).
25 type Postgres struct {
26 *sql.DB
27 }