-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* most functionality working * payment done * Trigger build * CIT-26: add api change * yes * CIT-26: fix Miraj's unforgivable mistakes, add alerts to event creation, add link * [CIT-26] Cleanup, fix success URL [CIT-26] Fix login redirect [CIT-26] Fix 1 last redirect [CIT-26] Use normal redirect w/o NextResponse [CIT-26] Fix redirect * [CIT-26] Bugfix on all redirects * [CIT-26] Bugfix on all redirects --------- Co-authored-by: Ishaan <[email protected]> Co-authored-by: Daniel <[email protected]> Co-authored-by: Ishaan Upadhyay <[email protected]>
- Loading branch information
1 parent
4ebec0d
commit 5d797e1
Showing
18 changed files
with
455 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use client' | ||
import axios from "axios" | ||
import { useState, useEffect } from "react" | ||
import PricingCard from "@/components/PricingCard" | ||
|
||
const Pricing = () => { | ||
const [prices, setPrices] = useState([]); | ||
|
||
useEffect(() => { | ||
fetchPrices() | ||
}, []) | ||
|
||
|
||
const fetchPrices = async () => { | ||
const {data} = await axios.get('/api/getproducts') | ||
setPrices(data) | ||
} | ||
|
||
return ( | ||
<div className="w-9/12 m-auto"> | ||
<div className="mx-auto max-w-4xl text-center items-center"> | ||
<h2 className="text-3xl font-semibold leading-7 text-[#f1592a]">Pricing</h2> | ||
<p className="mt-2 text-4xl font-bold tracking-tight sm:text-5xl">Choose the right plan for you!</p> | ||
<p className="mx-auto mt-6 max-w-2xl text-lg leading-8 sm:text-center">Check out all the information below</p> | ||
</div> | ||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-8 max-w-[1040px] items-center mx-auto"> | ||
{prices && prices.map((price) => ( | ||
<PricingCard price={price} key={price.id} /> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Pricing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import axios from "axios" | ||
import { stripe } from "@/app/api/payment/route"; | ||
import { redirect } from "next/navigation" | ||
import * as db from "@/lib/db" | ||
import { BASE_URL } from "@/lib/vars" | ||
import { getServerSession } from "next-auth"; | ||
import { authOptions } from "@/app/api/auth/[...nextauth]/route"; | ||
|
||
|
||
export default async function Page({ params }: { params: { id: string } }) { | ||
|
||
const session = await getServerSession(authOptions) | ||
|
||
if (!session || !session.user) { | ||
redirect(BASE_URL + '/login') | ||
} | ||
|
||
const prisma = db.getClient(); | ||
|
||
let update = { | ||
premium: true, | ||
} | ||
|
||
const currentSession = await stripe.checkout.sessions.retrieve( | ||
params.id | ||
) | ||
|
||
|
||
if (currentSession.payment_status === 'paid') { | ||
|
||
try { | ||
await prisma.users.update({ | ||
where: {username: session.user.name}, | ||
data: update | ||
}); | ||
} catch (e) { | ||
return db.handleError(e); | ||
} | ||
|
||
// Replace with stripe.checkout.sessions.expire() | ||
if (currentSession.status == 'open'){ | ||
const expireSession = await stripe.checkout.sessions.expire( | ||
params.id | ||
) | ||
} | ||
} | ||
|
||
|
||
return ( | ||
<div className="w-9/12 m-auto"> | ||
<div className="mx-auto max-w-4xl text-center items-center"> | ||
<h2 className="text-3xl font-semibold leading-7 text-[#f1592a]">Success!</h2> | ||
</div> | ||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-8 max-w-[1040px] items-center mx-auto"> | ||
|
||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Stripe from "stripe"; | ||
import { NextResponse, NextRequest } from 'next/server'; | ||
|
||
|
||
export async function GET(request) { | ||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY); | ||
const prices = await stripe.prices.list({ | ||
limit: 1, | ||
}); | ||
|
||
return NextResponse.json(prices.data.reverse()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Stripe from "stripe"; | ||
import { NextResponse, NextRequest } from "next/server"; | ||
import { redirect } from "next/navigation"; | ||
import * as db from "@/lib/db" | ||
import { getServerSession } from "next-auth"; | ||
import { authOptions } from "../auth/[...nextauth]/route"; | ||
import { BASE_URL } from "@/lib/vars"; | ||
|
||
|
||
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY) | ||
|
||
export async function POST (request) { | ||
const session = await getServerSession(authOptions); | ||
|
||
|
||
if (!session || !session.user) { | ||
redirect(BASE_URL + '/login') | ||
} | ||
|
||
let data = await request.json(); | ||
let priceId = data.priceId | ||
|
||
const stripeSession = await stripe.checkout.sessions.create({ | ||
line_items: [ | ||
{ | ||
price: priceId, | ||
quantity: 1 | ||
} | ||
], | ||
mode: 'payment', | ||
success_url: BASE_URL + '/success/{CHECKOUT_SESSION_ID}', | ||
cancel_url: BASE_URL+ '/cancel', | ||
}) | ||
|
||
return NextResponse.json(stripeSession.url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import axios from "axios" | ||
import Link from "next/link" | ||
import {AiFillCheckCircle} from 'react-icons/ai' | ||
|
||
const PricingCard = ({price}) => { | ||
|
||
|
||
|
||
// POST request | ||
const handleSubscription = async (e) => { | ||
e.preventDefault(); | ||
const { data } = await axios.post('/api/payment', | ||
{ | ||
priceId: price.id | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
window.location.assign(data) | ||
} | ||
|
||
return ( | ||
<div className="border-gray-100 shadow-2xl border-4 text-center mt-10 max-w-[1040px]"> | ||
<div> | ||
<div className="h-28 items-center font-bold"> | ||
<h4 className="text-3xl">{price.nickname}</h4> | ||
<p>Premium Plan</p> | ||
</div> | ||
<div> | ||
<div className="flex flex-col items-center justify-center pt-4"> | ||
<h1 className="text-5xl font-bold"> | ||
{(price.unit_amount / 100).toLocaleString('en-US', { | ||
style: 'currency', | ||
currency: 'USD' | ||
})} | ||
</h1> | ||
</div> | ||
<ul className="flex justify-center"> | ||
<li className="text-xl font-bold" >Premium plan description</li> | ||
</ul> | ||
<button className="mt-8 flex w-full justify-center rounded-md border border-transparent bg-[#f1592a] py-2 px-4 text-sm font-medium text-white shadow-sm" onClick={handleSubscription}> | ||
Subscribe | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default PricingCard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const BASE_URL = process.env.PROTOCOL_SCHEME + process.env.VERCEL_URL; |
Oops, something went wrong.
5d797e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mirajismail is attempting to deploy a commit to a Personal Account on Vercel that is not owned by them.
In order for the commit to be deployed, @mirajismail must be granted access to the connected Vercel project.
If you're the owner of the Personal Account, transfer the project to a Vercel Team and start collaborating, or learn more.