Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe Cancel + UI #1010

Merged
merged 121 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
2b13851
flow to experiment rename
supraja-968 Jun 18, 2024
f279039
Merge branch 'main' of https://github.com/labdao/plex into LAB-1484-r…
supraja-968 Jun 24, 2024
aa0e3a0
tool to model rename WIP
supraja-968 Jun 24, 2024
cef8191
tool to model WIP
supraja-968 Jun 24, 2024
20cc775
tool to model remaining changes
supraja-968 Jun 24, 2024
9c79e7e
db script for tool and flow renames
supraja-968 Jun 24, 2024
ccab0d2
db script update
supraja-968 Jun 24, 2024
b0b0c7b
tool manifest update
supraja-968 Jun 24, 2024
32d8cf0
Merge branch 'main' of https://github.com/labdao/plex into LAB-1484-r…
supraja-968 Jun 25, 2024
a91c8ea
checkpoint updates
supraja-968 Jun 25, 2024
b3f6b46
removing old tools from CI
supraja-968 Jun 25, 2024
9afdf9d
removing unused tools from CI
supraja-968 Jun 25, 2024
6d5eff2
removed unused checkpoint handlers
supraja-968 Jun 25, 2024
3e88319
datafiles to files, flow to experiment fixes after main merge
supraja-968 Jun 25, 2024
9f02989
datafile to file
supraja-968 Jun 25, 2024
39d5465
update DB scripts
supraja-968 Jun 25, 2024
c3dcfa4
db script update
supraja-968 Jun 25, 2024
fd6e669
run to job
supraja-968 Jun 25, 2024
62bf79f
db error logs silent
supraja-968 Jun 25, 2024
1c2b667
db script updates
supraja-968 Jun 26, 2024
98cc001
migration script and models wip
supraja-968 Jun 26, 2024
1c1a01f
initial DB schema update and script WIP
supraja-968 Jun 26, 2024
f1ebdf0
input and output files join table fix
supraja-968 Jun 26, 2024
9192348
user files join table fix
supraja-968 Jun 26, 2024
582f98b
file tags join table fixes
supraja-968 Jun 26, 2024
241eb60
add default no_org
supraja-968 Jun 26, 2024
ea5cdd5
datafiles handler fixes
supraja-968 Jun 27, 2024
3afb57a
datafiles -> files rename
supraja-968 Jun 27, 2024
42deaa5
model handlers
supraja-968 Jun 27, 2024
ad3c1af
experiments, jobs handlers fix WIP
supraja-968 Jun 27, 2024
536b4e6
model frontend changes WIP
supraja-968 Jun 27, 2024
7671433
Merge branch 'main' of https://github.com/labdao/plex into LAB-1483-u…
supraja-968 Jun 28, 2024
6aea746
fix CI issue
supraja-968 Jun 28, 2024
4f660f5
cid to id change in a few places
supraja-968 Jun 28, 2024
baa66b4
fix CI
supraja-968 Jun 28, 2024
d2fe60f
script update
supraja-968 Jun 28, 2024
29f7e0f
userid revert back to wallet address
supraja-968 Jul 1, 2024
8f708d0
wallet address fix in new tables
supraja-968 Jul 1, 2024
546cb98
user_id to wallet_address
supraja-968 Jul 1, 2024
97d2f31
userid to walletaddress more changes
supraja-968 Jul 1, 2024
0256ca3
removing user preload
supraja-968 Jul 1, 2024
996eebc
draft - part 1 of form submission working again WIP
supraja-968 Jul 7, 2024
61b4123
exp submission fix
supraja-968 Jul 7, 2024
dd5ae53
adding back created_at for exp
supraja-968 Jul 8, 2024
25cdf63
checkpoints fix
supraja-968 Jul 8, 2024
b676f69
stripe changes
supraja-968 Jul 8, 2024
6970c53
file select display fix
supraja-968 Jul 9, 2024
1b262d7
add job to experiment includes user compute tally updates
acashmoney Jul 9, 2024
1ddddcf
job state uses job status
acashmoney Jul 9, 2024
91c48c6
model passes in s3 uri prop
acashmoney Jul 9, 2024
cf09fd9
initial ray job demo wip
supraja-968 Jul 9, 2024
b32f4ca
send job request working WIP
supraja-968 Jul 12, 2024
149444c
ray job submission working (4x to be fixed)
supraja-968 Jul 15, 2024
ab69c43
moved rayJobID creation
supraja-968 Jul 15, 2024
01ff46d
Merge branch 'main' of https://github.com/labdao/plex into LAB-1491-r…
supraja-968 Jul 15, 2024
74f0e5a
http in default ray api host
supraja-968 Jul 15, 2024
3c5122e
log msgs update
supraja-968 Jul 15, 2024
4a0914f
rename migrations after merge
acashmoney Jul 15, 2024
b44786b
Merge branch 'LAB-1491-ray-jobs' of github.com:labdao/plex into LAB-1…
acashmoney Jul 15, 2024
4ae5395
successful job submission with output files (pending multi job submis…
supraja-968 Jul 16, 2024
51ff706
removing debug file
supraja-968 Jul 16, 2024
7201959
Merge branch 'main' of https://github.com/labdao/plex into LAB-1491-r…
supraja-968 Jul 22, 2024
23038ff
Merge branch 'main' of https://github.com/labdao/plex into LAB-1491-r…
supraja-968 Jul 22, 2024
6e58087
updating migration scripts
supraja-968 Jul 23, 2024
751974b
changing worker summary to show rayjobid instead of job id pk
supraja-968 Jul 23, 2024
eb61876
ray job demo job working WIP
supraja-968 Jul 23, 2024
17a0c5d
Merge branch 'main' of https://github.com/labdao/plex into LAB-1491-r…
supraja-968 Jul 24, 2024
24de7b1
colabdesign ray job working WIP
supraja-968 Jul 24, 2024
09c65d2
frontend changes for state management
supraja-968 Jul 24, 2024
dddf7d4
ray changes to handle small case status with ray caps status
supraja-968 Jul 24, 2024
3d2f009
ray job with inputs as RAY_JOB_INPUTS env var
supraja-968 Jul 26, 2024
2653ef6
Merge branch 'main' of https://github.com/labdao/plex into LAB-1491-r…
supraja-968 Jul 26, 2024
745cb6c
disable 15 sec auto refresh
acashmoney Jul 24, 2024
4a2e381
colabdesign job manifest update from service manifest
supraja-968 Jul 26, 2024
f9f5007
model manifest update
supraja-968 Jul 26, 2024
b6455ee
stripe cancel UI first version WIP
supraja-968 Jul 29, 2024
6ac2e04
Merge branch 'main' of https://github.com/labdao/plex into stripe_cancel
supraja-968 Jul 29, 2024
05fb03a
updated page.tsx for subscribe page
supraja-968 Jul 29, 2024
3eecb05
wiring stripe checkout to the start now button WIP
supraja-968 Jul 29, 2024
256c1d1
fetch wallet address
supraja-968 Jul 29, 2024
c8831bb
using stripecheckoutbutton in page
supraja-968 Jul 29, 2024
15826c7
subscription manage static page outline
supraja-968 Jul 29, 2024
478b11e
checkout success redirect
supraja-968 Jul 29, 2024
33f0384
Merge branch 'stripe_cancel' of https://github.com/labdao/plex into s…
supraja-968 Jul 29, 2024
9daed3a
cancel sub working (without alert)
supraja-968 Jul 29, 2024
f71663a
Merge branch 'stripe_cancel' of https://github.com/labdao/plex into s…
supraja-968 Jul 29, 2024
4d52136
cancel endpoint
supraja-968 Jul 29, 2024
d45f48b
stripe check subscription draft
supraja-968 Jul 29, 2024
47cdbe2
subscribe and subscription manage redirects
supraja-968 Jul 30, 2024
1ccc0fd
Merge branch 'stripe_cancel' of https://github.com/labdao/plex into s…
supraja-968 Jul 30, 2024
974c0b7
check subscription working
supraja-968 Jul 30, 2024
c6f3fc4
redirects without initial load
supraja-968 Jul 30, 2024
f34d517
product error fix in get sub handler
supraja-968 Jul 30, 2024
1642bc6
replacing static values in get subscription with usage summary working
supraja-968 Jul 30, 2024
7650262
fetching usage records for the subscription period
supraja-968 Jul 30, 2024
203cae4
plan template for manage page (pending cost dynamic)
supraja-968 Jul 31, 2024
0aed513
Merge branch 'stripe_cancel' of https://github.com/labdao/plex into s…
supraja-968 Jul 31, 2024
cf61213
stripe check sub api rename, billing portal WIP
supraja-968 Jul 31, 2024
0f6eda9
bug fix in page.tsx
supraja-968 Jul 31, 2024
5837fef
billing portal and display flat fee
supraja-968 Jul 31, 2024
30a8e4c
edit billing portal
supraja-968 Jul 31, 2024
bee5a90
manage subscription dynamic edits
supraja-968 Jul 31, 2024
c355321
backend changes, removing cancel logic, redirecting to billing portal
supraja-968 Jul 31, 2024
13f7df4
get plan details handler
supraja-968 Jul 31, 2024
421d905
get plan details for dynamic subscribe page
supraja-968 Jul 31, 2024
20ab780
stripe stop from giving retrial again
supraja-968 Jul 31, 2024
75717e1
Merge branch 'stripe_cancel' of https://github.com/labdao/plex into s…
supraja-968 Jul 31, 2024
d4bcc3a
UI style updates
supraja-968 Jul 31, 2024
1ce9cd6
Merge branch 'stripe_cancel' of https://github.com/labdao/plex into s…
supraja-968 Jul 31, 2024
42f45a9
some more style updates
supraja-968 Jul 31, 2024
affe59e
plan amount dynamic value
supraja-968 Jul 31, 2024
c546a86
enable to checkout at any point
supraja-968 Jul 31, 2024
04ca2c3
experiment page to redirect to subscribe instead of checkout
supraja-968 Jul 31, 2024
5dcc3ed
colabdesign compute cost update from 10 to 50 to allow 10 free jobs t…
supraja-968 Jul 31, 2024
54bf3ba
Merge branch 'stripe_cancel' of https://github.com/labdao/plex into s…
supraja-968 Jul 31, 2024
2bfb6d7
re-run to also redirect to subscribe
supraja-968 Jul 31, 2024
8bd4ce3
Merge branch 'stripe_cancel' of https://github.com/labdao/plex into s…
supraja-968 Jul 31, 2024
16a6a8d
remove trial period
supraja-968 Aug 2, 2024
fde150a
fix overage charge
supraja-968 Aug 2, 2024
511d2f2
demo job manifest
supraja-968 Aug 2, 2024
d70b656
Merge branch 'main' into stripe_cancel
supraja-968 Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function NewExperimentForm({ task }: { task: any }) {
}
} else if (userTier === 'Paid') {
if (isUserSubscribed) {
// Paid tier user with active subscription (including trial), directly create the experiment
// Paid tier user with active subscription, directly create the experiment
const response = await dispatch(addExperimentThunk(transformedPayload)).unwrap();
if (response && response.ID) {
console.log("Experiment created", response);
Expand All @@ -107,21 +107,9 @@ export default function NewExperimentForm({ task }: { task: any }) {
toast.error("Failed to start experiment");
}
} else {
// Paid tier user without active subscription, initiate checkout process
const result = await dispatch(addExperimentWithCheckoutThunk(transformedPayload)).unwrap();
if (result.checkout) {
// User needs to subscribe, redirect to checkout
window.location.href = result.checkout.url;
} else if (result && result.ID) {
// Experiment was created successfully (this case might not occur for non-subscribed users)
console.log("Experiment created", result);
router.push(`/experiments/${result.ID}`, { scroll: false });
dispatch(experimentListThunk(walletAddress));
toast.success("Experiment started successfully");
} else {
console.log("Something went wrong", result);
toast.error("Failed to start experiment");
}
// Paid tier user without active subscription, redirect to subscription page
console.log('Redirecting...');
router.push('/subscribe');
}
} else {
console.error("Invalid user tier");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,8 @@ export default function RerunExperimentForm() {
toast.error("Failed to add job to experiment");
}
} else if (userTier === 'Paid' && !isUserSubscribed) {
const checkoutResponse = await dispatch(addExperimentWithCheckoutThunk(transformedPayload)).unwrap();
if (checkoutResponse.checkout) {
window.location.href = checkoutResponse.checkout.url;
} else {
console.log("Something went wrong with checkout", checkoutResponse);
toast.error("Failed to initiate subscription process");
}
console.log('Redirecting...');
router.push('/subscribe');
} else {
console.error("Invalid user tier");
toast.error("Unable to process request due to invalid user tier");
Expand Down
129 changes: 129 additions & 0 deletions frontend/app/subscribe/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"use client";

import { usePrivy } from "@privy-io/react-auth";
import React, { useEffect, useState } from "react";
import { Breadcrumbs } from "@/components/global/Breadcrumbs";
import { toast } from "sonner";
import { getAccessToken } from "@privy-io/react-auth";
import backendUrl from "lib/backendUrl";
import { useRouter } from "next/navigation";
import getPlanTemplate, { PlanDetail } from "lib/planTemplate";
import StripeCheckoutButton from "@/components/payment/StripeCheckoutButton";

interface PlanDetails {
plan_name: string;
plan_amount: number;
plan_currency: string;
plan_interval: string;
included_credits: number;
overage_charge: number;
}

export default function SubscribePage() {
const { user } = usePrivy();
const walletAddress = user?.wallet?.address;
const [loading, setLoading] = useState(true);
const [planDetails, setPlanDetails] = useState<PlanDetails | null>(null);
const router = useRouter();

useEffect(() => {
const fetchPlanDetails = async () => {
try {
const authToken = await getAccessToken();
const response = await fetch(`${backendUrl()}/stripe/plan-details`, {
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json",
},
});

if (response.ok) {
const data: PlanDetails = await response.json();
setPlanDetails(data);
setLoading(false);
} else {
console.error("Failed to fetch plan details. Response not OK.");
setLoading(false);
}
} catch (error) {
console.error("Failed to fetch plan details:", error);
setLoading(false);
}
};

const checkSubscriptionStatus = async () => {
try {
const authToken = await getAccessToken();

const response = await fetch(`${backendUrl()}/stripe/subscription/check`, {
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json",
},
});

if (response.ok) {
const data = await response.json();
if (data.isSubscribed) {
router.replace("/subscription/manage");
} else {
fetchPlanDetails();
}
} else {
console.error("Failed to check subscription status. Response not OK.");
setLoading(false);
}
} catch (error) {
console.error("Failed to check subscription status:", error);
setLoading(false);
}
};

if (walletAddress) {
checkSubscriptionStatus();
} else {
console.log("Waiting for wallet address...");
}
}, [router, walletAddress]);

if (loading || !walletAddress || !planDetails) {
return <div>Loading...</div>;
}

return (
<div className="relative flex flex-col h-screen max-w-full grow">
<Breadcrumbs
items={[
{ name: "Subscribe", href: "/subscribe" },
{ name: walletAddress, href: `/subscribe/${walletAddress}` },
]}
actions={null}
/>
<div className="flex flex-col items-center justify-between w-[706px] h-[400px] p-8 bg-white rounded-lg shadow-lg mx-auto my-6">
<h3 className="text-center font-heading" style={{ fontSize: '33px', fontWeight: 500, lineHeight: '43.2px', letterSpacing: '0.5px', color: '#000000'}}>
Become a lab.bio subscriber
</h3>
<div className="text-sm text-gray-600 space-y-4 font-mono" style={{ fontSize: '15px', lineHeight: '25px', letterSpacing: '0.3px', color: '#000000' }}>
{getPlanTemplate().details.map((detail: PlanDetail, index: number) => (
<div key={index} className="flex items-start">
<span className="mr-2 text-black"></span>
<span>{detail.description
.replace('{{includedCredits}}', planDetails.included_credits.toString())
.replace('{{numMolecules}}', (planDetails.included_credits / 10).toString()) // Example calculation
.replace('{{overageCharge}}', planDetails.overage_charge.toString())
}</span>
</div>
))}
</div>
<p className="mt-4 text-center font-heading" style={{ fontSize: '24px', lineHeight: '30px', letterSpacing: '0.14px', color: '#000000', fontWeight: '500' }}>
${planDetails.plan_amount} / month
</p>
<div className="px-2 py-2 w-full">
<StripeCheckoutButton color="primary" size="sm" className="w-full font-bold">
Start now
</StripeCheckoutButton>
</div>
</div>
</div>
);
}
Loading
Loading