Oren
Oren5mo ago

action is not available to runAction / app / typescript

the stripe.ts and its actions are visible on dashboard but not available to ts / runAction
No description
No description
No description
10 Replies
Oren
OrenOP5mo ago
No description
Oren
OrenOP5mo ago
I tried cleanup all modules and builds and start fresh, didn't help
v
v5mo ago
Can we see the code inside stripe
ballingt
ballingt5mo ago
also what does convex/_generated/api.d.ts look like?
Oren
OrenOP5mo ago
tried with empty action as well no luck
No description
Oren
OrenOP5mo ago
this is the actual stripe handler code
"use node";

import { v } from "convex/values";
import Stripe from "stripe";

import { api, internal } from "./_generated/api";
import { action } from "./_generated/server";

export const createCheckoutSession = action({
args: { priceId: v.string() },
handler: async (ctx) => {
const stripe = new Stripe(process.env.STRIPE_KEY!, {
apiVersion: "2024-06-20",
});

let customer;

const { data: dbCustomer } = await ctx.runQuery(api.users.getCustomer);
const { data: user } = await ctx.runQuery(api.users.getCurrentUser);

if (!user) {
return { data: null, error: "Not authenticated" };
}

if (!dbCustomer) {
const stripeCustomer = await stripe.customers.create({
email: user?.email,
name: user?.name,
});

const { data: stripe_customer_id } = await ctx.runMutation(
internal.users.createCustomer,
{
stripe_customer_id: stripeCustomer.id,
}
);

customer = stripe_customer_id;
} else {
customer = dbCustomer?.stripe_customer_id;
}

if (!customer) {
return { data: null, error: "No customer found" };
}

const session = (await stripe.checkout.sessions.create({
payment_method_types: ["card"],
billing_address_collection: "auto",
customer: customer,
customer_update: {
address: "auto",
},
line_items: [
{
price: "priceId",
quantity: 1,
},
],
mode: "subscription",
allow_promotion_codes: true,
success_url: `${process.env.NEXT_PUBLIC_SITE_URL}/app/settings'`,
cancel_url: `${process.env.NEXT_PUBLIC_SITE_URL}/app/settings`,
})) as any;

console.log(session.url);
return { data: session.url };
},
});
"use node";

import { v } from "convex/values";
import Stripe from "stripe";

import { api, internal } from "./_generated/api";
import { action } from "./_generated/server";

export const createCheckoutSession = action({
args: { priceId: v.string() },
handler: async (ctx) => {
const stripe = new Stripe(process.env.STRIPE_KEY!, {
apiVersion: "2024-06-20",
});

let customer;

const { data: dbCustomer } = await ctx.runQuery(api.users.getCustomer);
const { data: user } = await ctx.runQuery(api.users.getCurrentUser);

if (!user) {
return { data: null, error: "Not authenticated" };
}

if (!dbCustomer) {
const stripeCustomer = await stripe.customers.create({
email: user?.email,
name: user?.name,
});

const { data: stripe_customer_id } = await ctx.runMutation(
internal.users.createCustomer,
{
stripe_customer_id: stripeCustomer.id,
}
);

customer = stripe_customer_id;
} else {
customer = dbCustomer?.stripe_customer_id;
}

if (!customer) {
return { data: null, error: "No customer found" };
}

const session = (await stripe.checkout.sessions.create({
payment_method_types: ["card"],
billing_address_collection: "auto",
customer: customer,
customer_update: {
address: "auto",
},
line_items: [
{
price: "priceId",
quantity: 1,
},
],
mode: "subscription",
allow_promotion_codes: true,
success_url: `${process.env.NEXT_PUBLIC_SITE_URL}/app/settings'`,
cancel_url: `${process.env.NEXT_PUBLIC_SITE_URL}/app/settings`,
})) as any;

console.log(session.url);
return { data: session.url };
},
});
api.d.ts
/* eslint-disable */
/**
* Generated `api` utility.
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.14.1.
* To regenerate, run `npx convex dev`.
* @module
*/

import type {
ApiFromModules,
FilterApi,
FunctionReference,
} from "convex/server";
import type * as auth from "../auth.js";
import type * as feedbacks from "../feedbacks.js";
import type * as http from "../http.js";
import type * as renders from "../renders.js";
import type * as stripe from "../stripe.js";
import type * as users from "../users.js";

/**
* A utility for referencing Convex functions in your app's API.
*
* Usage:
*/
declare const fullApi: ApiFromModules<{
auth: typeof auth;
feedbacks: typeof feedbacks;
http: typeof http;
renders: typeof renders;
stripe: typeof stripe;
users: typeof users;
}>;
export declare const api: FilterApi<
typeof fullApi,
FunctionReference<any, "public">
>;
export declare const internal: FilterApi<
typeof fullApi,
FunctionReference<any, "internal">
>;
/* eslint-disable */
/**
* Generated `api` utility.
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.14.1.
* To regenerate, run `npx convex dev`.
* @module
*/

import type {
ApiFromModules,
FilterApi,
FunctionReference,
} from "convex/server";
import type * as auth from "../auth.js";
import type * as feedbacks from "../feedbacks.js";
import type * as http from "../http.js";
import type * as renders from "../renders.js";
import type * as stripe from "../stripe.js";
import type * as users from "../users.js";

/**
* A utility for referencing Convex functions in your app's API.
*
* Usage:
*/
declare const fullApi: ApiFromModules<{
auth: typeof auth;
feedbacks: typeof feedbacks;
http: typeof http;
renders: typeof renders;
stripe: typeof stripe;
users: typeof users;
}>;
export declare const api: FilterApi<
typeof fullApi,
FunctionReference<any, "public">
>;
export declare const internal: FilterApi<
typeof fullApi,
FunctionReference<any, "internal">
>;
ballingt
ballingt5mo ago
Based on that _generated/api.d.ts you shouldn't have that TypeScript error, api.stripe should autocomplete I wonder if that changed since you took those first screenshots?
v
v5mo ago
Maybe restart ur idea /ts server
Oren
OrenOP5mo ago
wait now its there, strange I see d.ts was updated and old version doesn't have stripe. I always use "restart extension host" and removed node_modules and did restarted servers but it just got updated now ty for fast help 👍
v
v5mo ago
W tom as always I love convex support

Did you find this page helpful?