#_kevinx
1 messages ยท Page 1 of 1 (latest)
Hi, what is the question?
Hello there, I'm trying to test the standard account setup with this example here
https://github.com/stripe-samples/connect-onboarding-for-standard/blob/main/server/node/server.js
but Keep getting error
{"error":"Cannot set properties of undefined (setting 'accountID')"}
It seems there is no session in the req obj
Here is my API code
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
export default async function handler(req, res) {
console.log("๐ ~ file: stripeStandardOnboard.js:3 ~ handler ~ req:", req);
try {
const account = await stripe.accounts.create({
type: "standard",
});
// Store the ID of the new Standard connected account.
req.session.accountID = account.id;
console.log(
"๐ ~ file: stripeStandardOnboard.js:10 ~ handler ~ account:",
account
);
const origin = `${req.headers.origin}`;
const accountLink = await stripe.accountLinks.create({
type: "account_onboarding",
account: account.id,
refresh_url: `${origin}/api/stripOnboardRefresh`,
return_url: `${origin}/success`,
});
res.redirect(303, accountLink.url);
} catch (err) {
res.status(500).send({
error: err.message,
});
}
}
Can you share the request id where you saw this error message? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
The error code is saying that it cannot identify '(setting 'accountID')', specifically, 'req.session.accountID = account.id;'. You'd want to log this and see what it is and go from there. The request id you shared succeeded for creating account here stripe.accounts.create.
I did already, logged req, and like I said, there is no session in the req obj, that's why it says undefined
The comment line says what it's supposed to be doing. If you do not intend to store it, I think you could move that.
not a solution, seems the refresh api needs this too, from the same sample
app.get("/onboard-user/refresh", async (req, res) => {
if (!req.session.accountID) {
res.redirect("/");
return;
}
try {
const { accountID } = req.session;
const origin = `${req.secure ? "https://" : "http://"}${req.headers.host}`;
const accountLink = await stripe.accountLinks.create({
type: "account_onboarding",
account: accountID,
refresh_url: `${origin}/onboard-user/refresh`,
return_url: `${origin}/success.html`,
});
res.redirect(303, accountLink.url);
} catch (err) {
res.status(500).send({
error: err.message,
});
}
});
btw, do you have an example of using Next instead of express? not sure if the session is handled differently between these two
@magic wolf Just to clarify here this is purely in your own code/app. Stripe has no concept of a "session" and storing thing in a cookie and such. This is purely something you build/own by tracking who your end customer (the account owner) is, which account id acct_123 they are associated with, etc.
so the whole req.session part is purely yours and we don't really know much about how you'd do this in a certain framework
Got you, following the example from your document here, https://github.com/stripe-samples/connect-onboarding-for-standard/tree/main
and it leads me to these questions
yeah but this is really purely the most basic sample app that you would kind of port to your own entire integration
so the whole ideal here is to store the account.id in session and later pull it back to varify user?
Kind of. You don't really need to store anything in any session. But when someone is sent back to your website/app you should either know who they are and load the account id from somewhere (session or your database) or have them log in first or something