Jul '24 (edited) • General discussion
SOLVED Help with stripe billing portal
In createStripePortal() I am getting an error
This is triggered when I click on the manage plan button on pricing page
"""
Unhandled Runtime Error
Error: You can’t create a portal session in test mode until you save your customer portal settings in test mode at https://dashboard.stripe.com/test/settings/billing/portal.
Call Stack
StripeError.generate
node_modules\stripe\esm\Error.js (7:1)
res.toJSON.then._Error_js__WEBPACK_IMPORTED_MODULE_0__.StripeAPIError.message
node_modules\stripe\esm\RequestSender.js (102:42)
"""
This is generated when I call
"""
const session = await stripe.billingPortal.sessions.create({
customer: stripeCustomerId,
return_url: `${getBaseUrl()}/dashboard`,
});
"""
Seems odd to me as I am trying to save my customer portal settings...
Here is complete createStripePortal code:
""""
"use server";
import { adminDb } from "@/firebaseAdmin";
import getBaseUrl from "@/lib/getBaseUrl";
import stripe from "@/lib/stripe";
import { auth } from "@clerk/nextjs/server";
export async function createStripePortal() {
auth().protect();
const { userId } = await auth();
if (!userId) {
throw new Error("User not found");
}
// get id from database
const user = await adminDb.collection("users").doc(userId).get();
const stripeCustomerId = user.data()?.stripeCustomerId;
console.log(`******* doing stripe **********`);
const session = await stripe.billingPortal.sessions.create({
customer: stripeCustomerId,
return_url: `${getBaseUrl()}/dashboard`,
});
console.log(`******* ${session} **********`);
return session.url;
}
""""
Thank you
0
2 comments
Andrew W
3
SOLVED Help with stripe billing portal
University of Code
skool.com/universityofcode
You'll get Exclusive Lessons & Content, Badass Community Support & More here to elevate as a Dev!
Leaderboard (30-day)
Powered by