-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
476 additions
and
213 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
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,55 @@ | ||
import Stripe from "stripe"; | ||
import { headers } from "next/headers"; | ||
import { prisma } from "@/libs/prisma"; | ||
import { stripe } from "@/libs/stripe"; | ||
|
||
export async function POST(request: Request) { | ||
let event: Stripe.Event; | ||
const body = await request.text(); | ||
const signiture = headers().get("Stripe-Signature") as string; | ||
|
||
try { | ||
event = stripe.webhooks.constructEvent( | ||
body, | ||
signiture, | ||
process.env.STRIPE_WEBHOOK_SECRET ?? "" | ||
); | ||
} catch (err) { | ||
return new Response( | ||
`Webhook Error: ${err instanceof Error ? err.message : "Unknown Error"}`, | ||
{ status: 400 } | ||
); | ||
} | ||
const session = event.data.object as Stripe.Checkout.Session; | ||
|
||
if (!session?.metadata?.userId) { | ||
return new Response(null, { | ||
status: 200, | ||
}); | ||
} | ||
if (event.type === "checkout.session.completed") { | ||
const subscription = await stripe.subscriptions.retrieve( | ||
session.subscription as string | ||
); | ||
console.log( | ||
subscription.id, | ||
subscription.customer, | ||
subscription.items.data[0].price.id, | ||
subscription.current_period_end | ||
); | ||
await prisma.profile.update({ | ||
where: { | ||
userId: session.metadata.userId, | ||
}, | ||
data: { | ||
stripeSubscriptionId: subscription.id, | ||
stripeCustomerId: subscription.customer as string, | ||
stripePriceId: subscription.items.data[0].price.id, | ||
stripeCurrentPeriodEnd: new Date( | ||
subscription.current_period_end * 1000 | ||
), | ||
}, | ||
}); | ||
} | ||
return new Response(null, { status: 200 }); | ||
} |
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 |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
@tailwind components; | ||
@tailwind utilities; | ||
|
||
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=Source+Serif+4:opsz,[email protected],300;8..60,400;8..60,500;8..60,600;8..60,700;8..60,800&display=swap"); | ||
|
||
@font-face { | ||
font-family: "Mona Sans"; | ||
src: url("/fonts/mona-sans-cufonfonts/Mona-Sans-Regular.ttf") | ||
|
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
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,16 @@ | ||
"use client"; | ||
import React from "react"; | ||
import { useRouter } from "next/navigation"; | ||
import { Button } from "@/components/shared/Button"; | ||
|
||
export default function EditButton() { | ||
const router = useRouter(); | ||
return ( | ||
<Button | ||
onClick={() => router.push("/profile/edit")} | ||
className="py-3 px-6 font-medium text-gray-900 xl:block rounded-full border border-gray-200" | ||
> | ||
Edit Profile | ||
</Button> | ||
); | ||
} |
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
Oops, something went wrong.