Skip to content

Commit 42ac347

Browse files
committed
[upd] stripe checkout integrate
1 parent 54ed30b commit 42ac347

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

src/api/payment/handleCheckout.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { axiosClient } from "../axiosclient";
2+
3+
export default async function handleCheckout() {
4+
const response = await axiosClient.post('/pro/create-stripe-session');
5+
const { data } = response;
6+
return data.data.redirect_url;
7+
}

src/components/Pricing.tsx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
1+
import handleCheckout from "@/api/payment/handleCheckout";
12
import { Button } from "@/components/ui/button";
2-
import { SVGProps } from "react";
3-
import { useNavigate } from "react-router-dom";
3+
import { useSubscription } from "@/hooks/useSubscription";
4+
import { SVGProps, useEffect, useRef } from "react";
5+
import toast from "react-hot-toast";
6+
import { useLocation, useNavigate } from "react-router-dom";
47

58
export default function Pricing() {
9+
const {isProUser}=useSubscription();
10+
const sessionUrl=useRef<string>("");
11+
const { search } = useLocation();
12+
const params = new URLSearchParams(search);
613
const navigate = useNavigate();
14+
useEffect(() => {
15+
handleCheckout().then((redirect_url) => {
16+
console.log(redirect_url);
17+
sessionUrl.current = redirect_url;
18+
}).catch(() => {
19+
toast.error("Error in Generating you session Url");
20+
});
21+
}, []);
22+
if (params.get("success") == "true") {
23+
toast.success("Payment SuccessFul");
24+
setTimeout(() => {
25+
navigate("/test");
26+
}, 2000);
27+
return (
28+
<section className="w-full py-12 bg-gradient-to-r from-gray-50 to-gray-100 dark:from-zinc-900 dark:to-zinc-800 flex items-center justify-center h-screen flex-col sm:flex-row">
29+
<CheckIcon /> Redirecting to DashBoard{" "}
30+
<span className="animate-bounce text-xl font-extrabold">.</span>
31+
<span className="animate-bounce text-xl font-extrabold">.</span>
32+
<span className="animate-bounce text-xl font-extrabold">.</span>
33+
<span className="animate-bounce text-xl font-extrabold">.</span>
34+
</section>
35+
);
36+
}
37+
if (params.get("success") == "false") {
38+
toast.error("Payment Failed");
39+
}
740
return (
841
<section className="w-full py-12 bg-gradient-to-r from-gray-50 to-gray-100 dark:from-zinc-900 dark:to-zinc-800 flex items-center justify-center h-screen flex-col sm:flex-row">
9-
<h1 className="w-1/2 sm:text-3xl font-bold text-center p-4">TYPESIGHT comes with only one feature plan to give you the unlimited experience</h1>
42+
<h1 className="w-1/2 sm:text-3xl font-bold text-center p-4">
43+
TYPESIGHT comes with only one feature plan to give you the unlimited
44+
experience
45+
</h1>
1046
<div className="relative flex flex-col p-6 bg-white shadow-lg rounded-lg dark:bg-zinc-850 justify-between border border-purple-500 sm:w-1/3">
1147
<div className="px-3 py-1 text-sm text-white bg-gradient-to-r from-pink-500 to-purple-500 rounded-full inline-block absolute top-0 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
1248
Popular
@@ -35,10 +71,10 @@ export default function Pricing() {
3571
<Button
3672
className="w-full bg-gradient-to-r from-pink-500 to-purple-500"
3773
onClick={() => {
38-
navigate("/test");
74+
window.location.href=sessionUrl.current;
3975
}}
4076
>
41-
Get Started
77+
{isProUser ? "Manage Subscription" : "Subscribe Now"}
4278
</Button>
4379
</div>
4480
</div>
@@ -64,3 +100,4 @@ function CheckIcon(props: JSX.IntrinsicAttributes & SVGProps<SVGSVGElement>) {
64100
</svg>
65101
);
66102
}
103+

src/pages/Homepage/HomeScreen.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import banner from "../../assets/images/banner.jpeg";
44
import about from "../../assets/images/about.png";
55
import CheckCircleIcon from "@/icons/Checkicon";
66
import ContactUS from "@/components/ContactUS";
7-
import Pricing from "@/components/Pricing";
87
import { ArrowRightIcon } from "lucide-react";
98
import { useNavigate } from "react-router-dom";
109
import FadeAnimate from "@/components/FadeAnimateWrapper";
@@ -130,8 +129,6 @@ const HomeScreen = () => {
130129
</div>
131130
</div>
132131
</section>
133-
{/* Pricing */}
134-
<Pricing />
135132
{/* Contact */}
136133
<ContactUS />
137134
</FadeAnimate>

0 commit comments

Comments
 (0)