From ab767309acfa261d2b83244fb00149b0ff0b863c Mon Sep 17 00:00:00 2001 From: Clint Baker Date: Fri, 30 Aug 2024 11:10:28 -0600 Subject: [PATCH 1/4] when creating stripe checkout session, force the user to share email with stripe (auth0 & stripe email will always be the same) --- client/src/components/Capture.jsx | 7 ++++--- routes/stripeRouter.js | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client/src/components/Capture.jsx b/client/src/components/Capture.jsx index beae592..b85453b 100644 --- a/client/src/components/Capture.jsx +++ b/client/src/components/Capture.jsx @@ -4,13 +4,13 @@ import { useAuth0 } from '@auth0/auth0-react' export default function Capture() { const { user } = useAuth0() const [metadata, setMetadata] = useState({ customerId: '' }) - const [userId, setUserId] = useState('userId') + const [userInfo, setUserInfo] = useState('userId') const [productId, setProductId] = useState(import.meta.env.VITE_STRIPE_PRODUCT_ID) useEffect(() => { if (user) { setMetadata(user[`${import.meta.env.VITE_AUTH0_NAMESPACE}/app_metadata`]) - setUserId(user.sub) + setUserInfo({userId: user.sub, email: user.email}) } }, [user]) @@ -20,7 +20,8 @@ export default function Capture() {

You need to subscribe

Price is $35 / month
- + +
diff --git a/routes/stripeRouter.js b/routes/stripeRouter.js index 13403eb..2b1eb51 100644 --- a/routes/stripeRouter.js +++ b/routes/stripeRouter.js @@ -43,6 +43,11 @@ stripeRouter.get('/confirm', async (req, res, next) => { stripeRouter.post('/create-checkout-session', async (req, res, next) => { const userId = req.body.customer + const userEmail = req.body.email + // error handling for userId + if (!userId || !userEmail) { + res.status(400).send('User ID & Email is required'); + } // price comes from the frontend form, which stores productIds inside of env variables instead of loooking them up via stripe api const subscriptionPriceLookupKey = req.body.productId @@ -58,6 +63,7 @@ stripeRouter.post('/create-checkout-session', async (req, res, next) => { // sucess_url provides auth0 userId & stripe session.id success_url: `${process.env.STRIPE_SUCCESS_URI}&userId=${userId}&session_id={CHECKOUT_SESSION_ID}`, cancel_url: `${process.env.STRIPE_FAILURE_URI}&userId=${userId}`, + customer_email: userEmail }) res.redirect(303, session.url) From 04adc0a1fc8f96e85985b26c92270b6e101497bb Mon Sep 17 00:00:00 2001 From: Clint Baker Date: Fri, 30 Aug 2024 11:58:47 -0600 Subject: [PATCH 2/4] offer 3 options to subscribe --- client/src/components/Capture.jsx | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/client/src/components/Capture.jsx b/client/src/components/Capture.jsx index b85453b..17b9c31 100644 --- a/client/src/components/Capture.jsx +++ b/client/src/components/Capture.jsx @@ -6,6 +6,8 @@ export default function Capture() { const [metadata, setMetadata] = useState({ customerId: '' }) const [userInfo, setUserInfo] = useState('userId') const [productId, setProductId] = useState(import.meta.env.VITE_STRIPE_PRODUCT_ID) + const quarterlyId = import.meta.env.VITE_STRIPE_QUARTERLY_PRODUCT_ID + const yearlyId = import.meta.env.VITE_STRIPE_YEARLY_PRODUCT_ID useEffect(() => { if (user) { @@ -16,9 +18,10 @@ export default function Capture() { return ( <> +

You need to subscribe to access the app.

+
Select an option below
-

You need to subscribe

-
Price is $35 / month
+
Monthly Subscription - $35 / month
@@ -26,6 +29,24 @@ export default function Capture() {
+
+
Quarterly Subscription - $100 / 3 months (save $5)
+
+ + + + +
+
+
+
Yearly Subscription - $350 / year (save $70)
+
+ + + + +
+
) } From 8ea5f46f38f9f155c36d1754355591075728c018 Mon Sep 17 00:00:00 2001 From: Clint Baker Date: Fri, 30 Aug 2024 12:05:33 -0600 Subject: [PATCH 3/4] temporary isAdmin fix on Sidebar, we need to reconfigure this component --- client/src/components/Sidebar.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/components/Sidebar.jsx b/client/src/components/Sidebar.jsx index 10fd4a7..ff47c91 100644 --- a/client/src/components/Sidebar.jsx +++ b/client/src/components/Sidebar.jsx @@ -16,7 +16,9 @@ import { Link } from 'react-router-dom'; const Sidebar = () => { // Retrieve the isAdmin context from the Outlet context - const { isAdmin } = useOutletContext(); + // const { isAdmin } = useOutletContext(); + // temporary sidebar adjustment (how do we get isAdmin) + const isAdmin = false const { logout } = useAuth0(); const handleLogout = () => { From b99f4ae3003b04834cb710df09932286e1353e25 Mon Sep 17 00:00:00 2001 From: Clint Baker Date: Fri, 8 Nov 2024 09:45:30 -0700 Subject: [PATCH 4/4] subscription resting point --- client/src/routes/AdminDashboard.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/routes/AdminDashboard.jsx b/client/src/routes/AdminDashboard.jsx index d4ef479..c070211 100644 --- a/client/src/routes/AdminDashboard.jsx +++ b/client/src/routes/AdminDashboard.jsx @@ -48,7 +48,7 @@ export const AdminDashboard = ({admin}) => { const { logout, user } = useAuth0(); const { getAllFileMetadata } = useFileMetadataContext(); const navigate = useNavigate() - const metadata = user[`${import.meta.env.VITE_AUTH0_NAMESPACE}/user_metadata`] + const metadata = user[`${import.meta.env.VITE_AUTH0_NAMESPACE}/app_metadata`] useEffect(() => { getAllFileMetadata()