#fabulousray_code

1 messages ยท Page 1 of 1 (latest)

pure mistBOT
plush skyBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

pure mistBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1276050089215004768

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

low compass
#

i have a file 'authservice.js' without stripe imports that has a function:
const registerUser = async (user, additionalData = {}) => {

const newUser = await createUser(newUserData, false, true);
newUserId = newUser._id;

if (emailEnabled && !newUser.emailVerified) {
  await sendVerificationEmail({
    _id: newUserId,
    email,
    name,
  });
} else {
  await updateUser(newUserId, { emailVerified: true });
}

return { status: 200, message: genericVerificationMessage };

} catch (err) {
logger.error('[registerUser] Error in registering user:', err);
this calls createuser function in usermethods.js file:
hrows {Error} If a user with the same user_id already exists.
*/
const createUser = async (data, disableTTL = true, returnUser = false) => {
const userData = {
...data,
expiresAt: disableTTL ? null : new Date(Date.now() + 604800 * 1000), // 1 week in milliseconds
};

if (disableTTL) {
delete userData.expiresAt;
}
try {
// Create a new customer in Stripe

const stripeCustomer = await stripe.customers.create({
  email: data.email,
  name: data.name,
});

// Add the Stripe customer ID to the user data
userData.stripeCustomerId = stripeCustomer.id;
const user = await User.create(userData);
// Intialize message balance for the new user

const messageBalance = new MessageBalance({
  user: user._id,
  messageCredits: 10,
});
await messageBalance.save();
if (returnUser) {
  return user.toObject();
}

return user._id;

} catch (error) {
throw new Error('Error creating user: ' + error.message);
}
};

#

i get this error in deployment when registering user on railway

#

it works perfectly in local

wide kestrel
#

hello! is it the stripe.customers.create line that is throwing this error? It's not immediately clear from that error message which line is causing this error

low compass
#

hello!

#

it should be stripe.customers.create since that's the only thing related to stripe

#

i have imported api test key from env in usermethods.js which has function createuser which uses stripe.customer.create

#

however the error is thrown by the authservice.js (error: [registerUser]) which has the registeruser function which calls createuser function

#

hello?

wide kestrel
#

hrm, can you add some log lines before and after? i.e. print stripe just before that call and log stripeCustomer after that function to confirm?

low compass
#

okay ill try that

#

// Create a new customer in Stripe
logger.info('Stripe object before creating customer:', stripe);
const stripeCustomer = await stripe.customers.create({
email: data.email,
name: data.name,
});
logger.info('Stripe customer created:', stripeCustomer);
// Add the Stripe customer ID to the user data
userData.stripeCustomerId = stripeCustomer.id;
const user = await User.create(userData);
i did this, and nothing came out... 2024-08-22T05:57:28.403Z info: Stripe object before creating customer:
2024-08-22T05:57:29.240Z info: Stripe customer created:

wide kestrel
#

how did you initialize stripe? can you share the snippet? remember to redact the secret key

low compass
#

as in intialisation like this?:
const Stripe = require('stripe');
const stripe = Stripe(process.env.STRIPE_SECRET_KEY);

#

sorry i'm a complete noob

wide kestrel
#

yep, so if you log process.env.STRIPE_SECRET_KEY before const stripe = Stripe(process.env.STRIPE_SECRET_KEY); and then log stripe after. Do both have values when logged?

low compass
#

yep they both exist

wide kestrel
#

You can try initializing stripe i.e. const stripe = Stripe(process.env.STRIPE_SECRET_KEY); just before stripe.customers.create just as another test to see if it works

if that works, then i think then the next step here you would need to check is why the stripe object you're using to create a Customer object has no value then. I have no context on how your code is passing or handling the stripe object across files or functions.

low compass
#

well the thing is it works locally and not on railway upon deployment

wide kestrel
#

did you do the logging in local or after deployment?

low compass
#

local now

wide kestrel
#

there's no point in logging in local right? The problem is in deployment

low compass
#

๐Ÿ˜… yea...

wide kestrel
#

you'll want to add additional logs to deployment to figure out what's going on

low compass
#

okay ill do that now

#

sorry please bear with me, i'm getting some problems in deployment

wide kestrel
#

sure, no worries

low compass
#

thanks for hanging on

#

deploy logs do indeed output stripe key and object, hopefully from usermethods.js:
console.log('Stripe Secret Key:', process.env.STRIPE_SECRET_KEY);

const stripe = Stripe(process.env.STRIPE_SECRET_KEY);
const { logger } = require('~/config');
console.log('Stripe Object:', stripe);
im trying to get my deployment to work in order to see the function calling error but i get application not found errors so i have to fix that.

wide kestrel
#

i would clearly indicate which file you're logging those details from to be certain

low compass
#

okay ill try that

#

okay outside the function createuser,
const bcrypt = require('bcryptjs');
const signPayload = require('~/server/services/signPayload');
const User = require('./User');
const Stripe = require('stripe');
console.log('Stripe Secret Key(Usermethod.js const):', process.env.STRIPE_SECRET_KEY);

const stripe = Stripe(process.env.STRIPE_SECRET_KEY);
const { logger } = require('~/config');
console.log('Stripe Object(Usermethod.js const):', stripe);

const MessageBalance = require('./messageBalance');
deploy logs show:
Stripe Secret Key(Usermethod.js const): undefined
Stripe Object(Usermethod.js const): <ref *1> {

_platformFunctions: NodePlatformFunctions {

_fetchFn: null,

_agent: null,

_exec: [Function: exec],

_UNAME_CACHE: null

},

VERSION: '16.4.0',

on: [Function: bound addListener],

once: [Function: bound once],......

low compass
#

also my deployment is a docker image from github container btw

wide kestrel
#

well, if your stripe secret key is undefined, then you need to debug why

low compass
#

i have environment variables set on the railway config

wide kestrel
#

I'm not familiar with railway and there's very little that I can do here to help, maybe you'll want to check in with the railway community instead?

low compass
#

yea i did

#

could there be anything else that could cause the api key not to pass in within the code though?

wide kestrel
#

it's really something that is very specific to your own integration or setup. It could be anything from something not being cached properly to some file not being deployed properly

low compass
#

okay i understand

#

would you suggest a systematic way to debug this problem?

#

its bothering me for at least 24 hours...

wide kestrel
#

sorry, but I'm all out of ideas here

pure mistBOT
low compass
#

okay thank you for your help!

#

hello!