backpack1098B
Convex Community3y ago
12 replies
backpack1098

what's the proper way to query an SDK client in node env?

whenever a user navigates to the billing page, i want to check stripe if they have cancelled the pay, essentially, im trying to do
const plan: Stripe.Subscription = await stripe.subscriptions.retrieve(
  stripeSubscriptionId
)

since stripe SDK is in the node env, i need to wrap it in an "action"
export const getStripePlan = action({
  handler: async (ctx) => {
    const stripe = new Stripe(process.env.STRIPE_KEY!, {
      apiVersion: "2023-10-16",
      typescript: true,
    })

    const stripeSubscriptionId = ...

    const plan: Stripe.Subscription = await stripe.subscriptions.retrieve(
      stripeSubscriptionId
    )
    return plan.cancel_at_period_end
  },
})

and i was thinking that i could do
// /api/stripe/route.ts
export async function GET(req: NextApiRequest, res: NextApiResponse) {
  const plan = await convex.query(api.stripe.actions.getStripePlan, {})
  res.status(200).json({ plan })
}

and on the page.tsx, do a fetch to my API above. but im running into
formatDate
Argument of type 'FunctionReference<"action", "public", EmptyObject, boolean>' is not assignable to parameter of type 'FunctionReference<"query">'.

or is there a better approach to what im trying to achieve? thanks!
Was this page helpful?