Hi,
I have an existing database that shows users from a website. When the user subscribes, the subscriptions object from Stripe should be added to the database. I’ve been updating the stripe checkout and know need to append the object to the user document each time there’s a purchase. I’ve been using the UpdateOne to no result. Nothing happens. Can someone help me please? I’m new to nodejs and mongodb so maybe there’s something I’m missing.
Here is my code:
//create subscription
const subscription = await stripe.subscriptions.create({
customer: customer,
items: [{ plan: 'plan_DznNb3tPEEI0cj' }],
default_payment_method: paymentMethod,
expand: ['latest_invoice.payment_intent']
});
let updateUser = await User.findOne({_id: userId });
try {
User.updateOne(
{id: ObjectId(userId) },
{$set: { "stripeCustomer": subscription}},
{ upsert: true }
);
} catch (err) {
console.log(err);
}