user upgrades: add UserUpgrade model.
Add a model to store the status of user upgrades. * Store the upgrade purchaser and the upgrade receiver (these are different for a gifted upgrade, the same for a self upgrade). * Store the upgrade type: gold, platinum, or gold-to-platinum upgrades. * Store the upgrade status: ** pending: User is still on the Stripe checkout page, no payment received yet. ** processing: User has completed checkout, but the checkout status in Stripe is still 'unpaid'. ** complete: We've received notification from Stripe that the payment has gone through and the user has been upgraded. * Store the Stripe checkout ID, to cross-reference the upgrade record on Danbooru with the checkout record on Stripe. This is the upgrade flow: * When the user clicks the upgrade button on the upgrade page, we call POST /user_upgrades and create a pending UserUpgrade. * We redirect the user to the checkout page on Stripe. * When the user completes checkout on Stripe, Stripe sends us a webhook notification at POST /webhooks/receive. * When we receive the webhook, we check the payment status, and if it's paid we mark the UserUpgrade as complete and upgrade the user. * After Stripe sees that we have successfully processed the webhook, they redirect the user to the /user_upgrades/:id page, where we show the user their upgrade receipt.
This commit is contained in:
@@ -3104,6 +3104,41 @@ CREATE SEQUENCE public.user_name_change_requests_id_seq
|
||||
ALTER SEQUENCE public.user_name_change_requests_id_seq OWNED BY public.user_name_change_requests.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_upgrades; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.user_upgrades (
|
||||
id bigint NOT NULL,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
recipient_id bigint NOT NULL,
|
||||
purchaser_id bigint NOT NULL,
|
||||
upgrade_type integer NOT NULL,
|
||||
status integer NOT NULL,
|
||||
stripe_id character varying
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_upgrades_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.user_upgrades_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_upgrades_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.user_upgrades_id_seq OWNED BY public.user_upgrades.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
@@ -4172,6 +4207,13 @@ ALTER TABLE ONLY public.user_feedback ALTER COLUMN id SET DEFAULT nextval('publi
|
||||
ALTER TABLE ONLY public.user_name_change_requests ALTER COLUMN id SET DEFAULT nextval('public.user_name_change_requests_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_upgrades id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_upgrades ALTER COLUMN id SET DEFAULT nextval('public.user_upgrades_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -4537,6 +4579,14 @@ ALTER TABLE ONLY public.user_name_change_requests
|
||||
ADD CONSTRAINT user_name_change_requests_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_upgrades user_upgrades_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_upgrades
|
||||
ADD CONSTRAINT user_upgrades_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -7045,6 +7095,41 @@ CREATE INDEX index_user_name_change_requests_on_original_name ON public.user_nam
|
||||
CREATE INDEX index_user_name_change_requests_on_user_id ON public.user_name_change_requests USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_upgrades_on_purchaser_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_upgrades_on_purchaser_id ON public.user_upgrades USING btree (purchaser_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_upgrades_on_recipient_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_upgrades_on_recipient_id ON public.user_upgrades USING btree (recipient_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_upgrades_on_status; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_upgrades_on_status ON public.user_upgrades USING btree (status);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_upgrades_on_stripe_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_upgrades_on_stripe_id ON public.user_upgrades USING btree (stripe_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_upgrades_on_upgrade_type; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_upgrades_on_upgrade_type ON public.user_upgrades USING btree (upgrade_type);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_users_on_created_at; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -7437,6 +7522,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20200816175151'),
|
||||
('20201201211748'),
|
||||
('20201213052805'),
|
||||
('20201219201007');
|
||||
('20201219201007'),
|
||||
('20201224101208');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user