ducky/subscriptions
10:2c8250237566
Go to Latest
ducky/subscriptions/subscriptionsd/server.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.
8 "code.secondbit.org/ducky/subscriptions.hg"
9 "code.secondbit.org/ducky/subscriptions.hg/api"
10 "code.secondbit.org/trout.hg"
12 "github.com/stripe/stripe-go"
14 "golang.org/x/net/context"
18 log.SetFlags(log.LstdFlags | log.Llongfile)
19 log.Printf("Running version '%s'\n", subscriptions.Version)
20 var subscriptionStore subscriptions.SubscriptionStore
21 if os.Getenv("SUBSCRIPTIONS_PG_DB") != "" {
22 p, err := subscriptions.NewPostgres(os.Getenv("SUBSCRIPTIONS_PG_DB"))
28 subscriptionStore = subscriptions.NewMemstore()
30 var stripeClient subscriptions.Stripe
31 if os.Getenv("STRIPE_KEY") != "" {
32 stripeClient = subscriptions.NewStripe(os.Getenv("STRIPE_KEY"), stripe.GetBackend(stripe.APIBackend))
34 log.Fatal("STRIPE_KEY environment variable must be set!")
36 c := api.WithStripeClient(stripeClient, api.WithSubscriptionStore(subscriptionStore, context.Background()))
37 router := trout.Router{}
38 api.HandleSubscriptions(&router, c)
39 http.Handle("/", router)
40 log.Println("Listening on 9001")
41 log.Fatal(http.ListenAndServe("0.0.0.0:9001", nil))