-
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
1 parent
54961bb
commit 3225764
Showing
8 changed files
with
815 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import db from "@/lib/ts/db"; | ||
import { stripe } from "@/lib/ts/stripe"; | ||
import { headers } from "next/headers"; | ||
|
||
export async function POST(req: Request) { | ||
const body = await req.text(); | ||
|
||
const signature = headers().get("Stripe-Signature") as string; | ||
|
||
let event; | ||
|
||
try { | ||
event = stripe.webhooks.constructEvent( | ||
body, | ||
signature, | ||
process.env.STRIPE_CONNECT_WEBHOOK_SECRET as string | ||
); | ||
} catch (error: unknown) { | ||
return new Response("webhook error", { status: 400 }); | ||
} | ||
|
||
switch (event.type) { | ||
case "account.updated": { | ||
const account = event.data.object; | ||
|
||
const data = await db.user.update({ | ||
where: { | ||
connectedAccountId: account.id, | ||
}, | ||
data: { | ||
stripeConnectedLinked: | ||
!(account.capabilities?.transfers === "pending" || account.capabilities?.transfers === "inactive"), | ||
}, | ||
}); | ||
break; | ||
} | ||
default: { | ||
console.log("default event"); | ||
} | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Email from "@/components/forms/ReturnEmail"; | ||
import { stripe } from "@/lib/ts/stripe"; | ||
import { headers } from "next/headers"; | ||
import { Resend } from "resend"; | ||
|
||
const resend = new Resend(process.env.RESEND_API_KEY); | ||
|
||
export async function POST(req: Request) { | ||
const body = await req.text(); | ||
|
||
const signature = headers().get("Stripe-Signature") as string; | ||
|
||
let event; | ||
|
||
try { | ||
event = stripe.webhooks.constructEvent( | ||
body, | ||
signature, | ||
process.env.STRIPE_SECRET_WEBHOOK as string | ||
); | ||
} catch (error: unknown) { | ||
return new Response("webhook error", { status: 400 }); | ||
} | ||
|
||
switch (event.type) { | ||
case "checkout.session.completed": { | ||
const session = event.data.object; | ||
const link = session.metadata?.link; | ||
const { data, error } = await resend.emails.send({ | ||
Check warning on line 29 in app/api/stripe/route.ts GitHub Actions / Qodana for JSUnused local symbol
|
||
from: "PixelCart", | ||
to: [`${session.customer_email}`], | ||
subject: "Your Product from PixelCart is here!", | ||
react: Email({ | ||
link: link as string, | ||
}), | ||
}); | ||
|
||
break; | ||
} | ||
default: { | ||
console.log("unhandled event"); | ||
} | ||
} | ||
|
||
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
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,30 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import { Card } from "@/components/ui/card"; | ||
import { Check } from "lucide-react"; | ||
import Link from "next/link"; | ||
|
||
export default function ReturnUrlStripe() { | ||
return ( | ||
<section className="w-full min-h-[80vh] flex items-center justify-center"> | ||
<Card className="w-[350px]"> | ||
<div className="p-6"> | ||
<div className="w-full flex justify-center"> | ||
<Check className="w-12 h-12 rounded-full bg-green-500/30 text-green-500 p-2" /> | ||
</div> | ||
<div className="mt-3 text-center sm:mt-5 w-full"> | ||
<h3 className="text-lg leading-6 font-medium"> | ||
Linking was Successful | ||
</h3> | ||
<p className="mt-2 text-sm text-muted-foreground"> | ||
Your Stripe account has been successfully linked. | ||
</p> | ||
|
||
<Button className="mt-5 sm:mt-6 w-full" asChild> | ||
<Link href="/">Back to Homepage</Link> | ||
</Button> | ||
</div> | ||
</div> | ||
</Card> | ||
</section> | ||
); | ||
} |
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,46 @@ | ||
import { | ||
Body, | ||
Button, | ||
Container, | ||
Head, | ||
Html, | ||
Preview, | ||
Section, | ||
Tailwind, | ||
Text, | ||
} from "@react-email/components"; | ||
|
||
export default function Email({ link }: { link: string }) { | ||
return ( | ||
<Html> | ||
<Head /> | ||
<Preview>Your product is here...</Preview> | ||
<Tailwind> | ||
<Body className="bg-white font-sans"> | ||
<Container style={container}> | ||
<Text className="text-2xl font-semibold">Hi Friend,</Text> | ||
<Text className="text-lg text-gray-600"> | ||
Thank you for buying your product at MarshalUI | ||
</Text> | ||
<Section className="w-full flex justify-center mt-7"> | ||
<Button | ||
href={link} | ||
className="text-white bg-blue-500 rounded-lg px-10 py-4" | ||
> | ||
Your Download Link | ||
</Button> | ||
</Section> | ||
<Text className="text-lg"> | ||
Best, <br /> MarshalUI Team | ||
</Text> | ||
</Container> | ||
</Body> | ||
</Tailwind> | ||
</Html> | ||
); | ||
} | ||
|
||
const container = { | ||
margin: "0 auto", | ||
padding: "20px 0 48px", | ||
}; |
Oops, something went wrong.