next-easy-stripe
v1.2.2
Published
An abstraction of the stripe library for Next.js
Downloads
1,035
Readme
next-easy-stripe
An abstraction of the stripe library for Next.js
To install:
bun add next-easy-stripe
or
pnpm add next-easy-stripe
or
npm install next-easy-stripe
How to use:
- Create a stripe.ts file inside of app/lib
- Paste this code there:
import {StripeConfig} from "next-easy-stripe";
export const stripeClient = new StripeConfig(
[
{
name: "Pro",
priceId: "price-id", // get this from stripe
mode: "subscription"
}
// add more products here
],
(data) => {
// add code here
},
(data) => {
// add code here
},
(data) => {
// add code here
},
(data) => {
// add code here
},
process.env.STRIPE_SECRET_KEY!
)
export async function handleStripeSession(formData: FormData): Promise<string | undefined> {
return stripeClient.handleSession(formData)
}
- Create a route.ts file in app/api/somepath/route.ts. "somepath" can be anything you want. I use api/payments/webhook/route.ts
- In route.ts paste this code:
import {NextRequest} from "next/server";
import {stripeClient} from "@/app/lib/stripe/stripe";
export async function POST(req: NextRequest) {
return stripeClient.handleStripeReq(req);
}