export const storeStripeCustomerId = action({
args: {},
handler: async ctx => {
const stripe = new Stripe(
process.env.STRIPE_SECRET_KEY! ?? "",
{
apiVersion: "2023-10-16",
typescript: true,
}
);
const user = await ctx.runQuery(internal.users.getUserInternalQuery);
if (!user) {
throw new Error("User not found");
}
console.log("bla bla bla run now");
console.log(user, "user");
if(!user.stripeId) {
const customer = await stripe.customers.create({
email: user.email,
name: user.firstName + " " + user.lastName,
});
console.log("let me create one");
// await ctx.db.patch(user._id, {
// stripeId: customer.id,
// });
const stripeId : string
= await ctx.runMutation(internal.users.storeStripeId, { userId: user._id, stripeId: customer.id });
return stripeId;
}
return user.stripeId;
},
});
export const storeStripeCustomerId = action({
args: {},
handler: async ctx => {
const stripe = new Stripe(
process.env.STRIPE_SECRET_KEY! ?? "",
{
apiVersion: "2023-10-16",
typescript: true,
}
);
const user = await ctx.runQuery(internal.users.getUserInternalQuery);
if (!user) {
throw new Error("User not found");
}
console.log("bla bla bla run now");
console.log(user, "user");
if(!user.stripeId) {
const customer = await stripe.customers.create({
email: user.email,
name: user.firstName + " " + user.lastName,
});
console.log("let me create one");
// await ctx.db.patch(user._id, {
// stripeId: customer.id,
// });
const stripeId : string
= await ctx.runMutation(internal.users.storeStripeId, { userId: user._id, stripeId: customer.id });
return stripeId;
}
return user.stripeId;
},
});