1.2.2 • Published 10 months ago

next-easy-stripe v1.2.2

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

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:

  1. Create a stripe.ts file inside of app/lib
  2. 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)
}
  1. Create a route.ts file in app/api/somepath/route.ts. "somepath" can be anything you want. I use api/payments/webhook/route.ts
  2. 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);
}
1.2.2

10 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.1.2

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago