Can anyone help me look at the Algorithms for Adding a Stripe customer to my Nodejs signup API

static async registration(req, res) {
		const {
			firstName,
			lastName,
			email,
                       password
		} = req.body;
		var hash = bcrypt.hashSync(password, salt);
		  try {
			const userAcc = await User.findOne({ email });
			if (userAcc) {
				const message1 = {
					message: "A user with that email address or username already exists",
					status: 404,
				};
			  return res.json({
				error: 'error',
				message: message1
			  });
			} else {
			  const user = new User({
				email,
				firstName,
				lastName,
				password: hash,
			  })
				const customer = await stripe.customer.create(
					{
						email: req.body.email,
					}
				)
				console.log(customer);
			  const result = await user.save()
			  const userToken = GenerateToken(result);
				res.json({
					access_token: userToken,
					user: result,
					response: "TRUE",
					message: "Your account has been created, please check your email for a password",
					customerId: customer.id,
					customerEmail: customer.email,
				});
			}
		  } catch (error) {
			console.error(error)
		  }
	}

when i run this on Postman it generates an empty array, i think i am not using the Stripe variable well
i get this from the log

TypeError: Cannot read property 'create' of undefined

Shouldn’t it be customers (plural)
https://stripe.com/docs/api/customers/create?lang=node

Edit: Just in case I’m not being super clear, use stripe.customers.create(), and not stripe.customer.create()

@sparkidea25 I edited your post so we can see the error log.

Thank you its working now

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.