ducky/subscriptions
ducky/subscriptions/sql/postgres_init.sql
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.
| paddy@1 | 1 CREATE TABLE IF NOT EXISTS subscriptions ( |
| paddy@1 | 2 user_id VARCHAR(36) PRIMARY KEY, |
| paddy@2 | 3 stripe_subscription VARCHAR(36) UNIQUE NOT NULL, |
| paddy@2 | 4 plan VARCHAR(36) NOT NULL, |
| paddy@2 | 5 status VARCHAR(16) NOT NULL, |
| paddy@2 | 6 canceling BOOLEAN NOT NULL, |
| paddy@1 | 7 created TIMESTAMPTZ NOT NULL, |
| paddy@2 | 8 trial_start TIMESTAMPTZ NOT NULL, |
| paddy@2 | 9 trial_end TIMESTAMPTZ NOT NULL, |
| paddy@2 | 10 period_start TIMESTAMPTZ NOT NULL, |
| paddy@2 | 11 period_end TIMESTAMPTZ NOT NULL, |
| paddy@2 | 12 canceled_at TIMESTAMPTZ NOT NULL, |
| paddy@2 | 13 failed_charge_attempts INTEGER NOT NULL, |
| paddy@2 | 14 last_failed_charge TIMESTAMPTZ NOT NULL, |
| paddy@2 | 15 last_notified TIMESTAMPTZ NOT NULL |
| paddy@1 | 16 ); |