Initial Setup
Payments
Stripe
One Time

One Time Payments - Coming Soon

Change the mode in the src/app/api/stripe/route.ts file from subscription to payment and remove the metadata attach to it.

Before

src/app/api/stripe/route.ts
const stripeSession = await stripe.checkout.sessions.create({
	success_url: billingUrl,
	cancel_url: billingUrl,
	payment_method_types: ["card"],
	mode: "subscription",
	billing_address_collection: "auto",
	customer_email: user.email,
	line_items: [
		{
			price: priceId!,
			quantity: 1,
		},
	],
	metadata: {
		userId: user.id,
	},
});

After

src/app/api/stripe/route.ts
const stripeSession = await stripe.checkout.sessions.create({
	success_url: billingUrl,
	cancel_url: billingUrl,
	payment_method_types: ["card"],
	mode: "payment",
	billing_address_collection: "auto",
	customer_email: user.email,
	line_items: [
		{
			price: priceId!,
			quantity: 1,
		},
	],
});

Now comment out the subscription plan check in the src/app/api/stripe/route.ts file.

Before

src/app/api/stripe/route.ts
const subscriptionPlan = await getUserSubscription(user.id);
 
if (subscriptionPlan instanceof Error) {
	return new NextResponse("Unauthorized", { status: 401 });
}

After

src/app/api/stripe/route.ts
// const subscriptionPlan = await getUserSubscription(user.id);
 
// if (subscriptionPlan instanceof Error) {
// 	return new NextResponse("Unauthorized", { status: 401 });
// }

Change PriceId

Change the priceId in the .env.local file to the one-time payment price id.

.env.local
NEXT_PUBLIC_STRIPE_PRICE_ID=your-price-id

Remove all other events from the src/app/api/stripe/webhook/route.ts file except the checkout.session.completed event.

Now run the server in one terminal window:

npm run dev

And run the Stripe webhook listener in another terminal window:

npm run stripe:listen

Now you can create a new user and test one-time payments. You can use the following test card numbers:

  • 4242 4242 4242 4242 (Visa)
  • 5555 5555 5555 4444 (Mastercard)
  • 3782 822463 10005 (American Express)