Not able to create polar Checkout

Hi, I'm trying to create a polar checkout with polarCheckoutWithSlug

 await auth.api.polarCheckoutWithSlug({
    params: {
      slug: "premium",
    },
    headers: await headers(),
  });


to provide a custom param. Because a user can have multiple items which have to be payed seperatly.
The problem is. That I get follwing error with this function

2025-03-26T22:50:10.685Z ERROR [Better Auth]: Polar checkout creation failed. Error: Invalid URL


I'm using follwing versions:

"better-auth": "^1.2.5",
"@polar-sh/better-auth": "^0.0.9",


My Polar config looks like this:


export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: "postgresql",
  }),
  session: {
    cookieCache: {
      enabled: true,
      maxAge: 5 * 60, // Cache duration in seconds
    },
  },
  plugins: [
    nextCookies(),
    twoFactor(),
    polar({
      client,
      createCustomerOnSignUp: true,
      enableCustomerPortal: true,
      webhooks: {
        secret: env.POLAR_WEBHOOK_SECRET,
        onCheckoutCreated: async (checkout) => {
          // TODO: Handle checkout per id

          if (!checkout.data.customerExternalId) {
            throw new Error("Checkout ID is required");
          }

          await prisma.payment.create({
            data: {
              paymentId: checkout.data.id,
              status: checkout.data.status,
              userId: checkout.data.customerExternalId,
            },
          });
        },
        onCheckoutUpdated: async (checkout) => {
          const payment = await prisma.payment.findFirst({
            where: {
              paymentId: checkout.data.id,
            },
          });

          if (!payment) {
            throw new Error("Payment not found");
          }

          if (checkout.data.status === "confirmed") {
            const userPayments = await prisma.payment.findMany({
              where: {
                userId: payment.userId,
              },
            });

            const filterPayments = userPayments.filter(
              (payment) => payment.paymentId !== checkout.data.id
            );

            await prisma.payment.deleteMany({
              where: {
                id: {
                  in: filterPayments.map((payment) => payment.id),
                },
              },
            });
          }

          await prisma.payment.update({
            where: {
              id: payment.id,
            },
            data: {
              status: checkout.data.status,
            },
          });
        },
      },
      checkout: {
        enabled: true,
        products: [
          {
            productId: "65283361-ab92-4f8d-94b7-c9e9c5f7c4d9",
            slug: "premium",
          },
        ],
        successUrl: "/dashboard/success?checkout_id={CHECKOUT_ID}",
        cancelUrl: "/dashboard/manage/[id]/billing",
      },
    }),
  ],
  appName: "123",
  rateLimit: {
    window: 10, // time window in seconds
    max: 100, // max requests in the window
  },
  socialProviders: {
    google: {
      clientId: env.GOOGLE_CLIENT_ID,
      clientSecret: env.GOOGLE_CLIENT_SECRET,
    },
  },
  emailAndPassword: {
    autoSignIn: true,
    enabled: true,
    minPasswordLength: 8,
  },
});
Was this page helpful?