ducky/subscriptions
ducky/subscriptions/sql/postgres_init.sql
Export all subscriptionStore methods. We're not going to wrap all our subscriptionStore interactions in a Context type, so we need to expose all the functions so other packages can call them. Also, it's now SubscriptionStore. Also creates a SubscriptionRequest type that is used to create a new Subscription instance, along with a Validate method on it, to detect errors when creating a SubscriptionRequest. Update our CreateSubscription function to be New, and have it take a SubscriptionRequest, a Stripe instance, and a SubscriptionStore as arguments. It'll create the Subscription in the SubscriptionStore, create a customer in Stripe, and create the subscription in Stripe, then associate the Stripe subscription with the created Subscription. Also, fix our StripeSubscriptionChange function to correctly equate a missing/zero Unix timestamp from Stripe with a missing/zero time.Time.
| 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 ); |