ducky/subscriptions

Paddy 2015-06-16 Parent:f1a22fc2321d

2:61c4ce5850da Go to Latest

ducky/subscriptions/sql/postgres_init.sql

Use stripe's built-in subscriptions. We're going to use Stripe's built-in subscriptions to manage our subscriptions, which required us to change a lot of stuff. We're now tracking stripe_subscription instead of stripe_customer, and we need to track the plan, status, and if the user is canceling after this month. We also don't need to know when to begin charging them (Stripe will do it), but we should track when their trial starts and ends, when the current pay period they're in starts and ends, when they canceled (if they've canceled), the number of failed charge attempts they've had, and the last time we notified them about billing (To avoid spamming users). We get to delete all the stuff about periods, which is nice. We updated our SubscriptionChange type to match. Notably, there are a lot of non-user modifiable things now, but our Stripe webhook will need to use them to update our database records and keep them in sync. We no longer need to deal with sorting stuff, which is also nice. Our SubscriptionStats have been updated to be... useful? Now we can track how many users we have, and how many of them have failing credit cards, how many are canceling at the end of their current payment period, and how many users are on each plan. We also switched around how the TestUpdateSubscription loops were written, to avoid resetting more than we needed to. Before, we had to call store.reset() after every single change iteration. Now we get to call it only when switching stores. This makes a significant difference in the amount of time it takes to run tests. Finally, we added a test case for retrieving subscription stats. It's minimal, but it works.

History
1 CREATE TABLE IF NOT EXISTS subscriptions (
2 user_id VARCHAR(36) PRIMARY KEY,
3 stripe_subscription VARCHAR(36) UNIQUE NOT NULL,
4 plan VARCHAR(36) NOT NULL,
5 status VARCHAR(16) NOT NULL,
6 canceling BOOLEAN NOT NULL,
7 created TIMESTAMPTZ NOT NULL,
8 trial_start TIMESTAMPTZ NOT NULL,
9 trial_end TIMESTAMPTZ NOT NULL,
10 period_start TIMESTAMPTZ NOT NULL,
11 period_end TIMESTAMPTZ NOT NULL,
12 canceled_at TIMESTAMPTZ NOT NULL,
13 failed_charge_attempts INTEGER NOT NULL,
14 last_failed_charge TIMESTAMPTZ NOT NULL,
15 last_notified TIMESTAMPTZ NOT NULL
16 );