Skip to content

Update Next.js Guide: Use Full Confirmation URL in successUrl for Checkout Route #5475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
amittam104 opened this issue Apr 12, 2025 · 0 comments

Comments

@amittam104
Copy link

Documentation Update: Invalid URL Error in Next.js Guide for Checkout

Current Status

The current code in the Next.js integration guide uses a relative URL for the successUrl:

// src/app/checkout/route.ts
import { Checkout } from '@polar-sh/nextjs'

export const GET = Checkout({
  accessToken: process.env.POLAR_ACCESS_TOKEN!,
  successUrl: '/confirmation',
  server: 'sandbox', // Use this option if you're using the sandbox environment - else use 'production' or omit the parameter
});

This throws the following error:

⨯ [TypeError: Invalid URL] {
  code: 'ERR_INVALID_URL',
  input: '/confirmation'
}

Expected Behavior

The successUrl should accept a valid, absolute URL string — not a relative one.

Recommended Fix

Update the successUrl to use a full absolute URL instead of a relative path. The updated example should look like this:

// src/app/checkout/route.ts
import { Checkout } from '@polar-sh/nextjs'

export const GET = Checkout({
  accessToken: process.env.POLAR_ACCESS_TOKEN!,
  successUrl: 'https://your-domain.com/confirmation', // Use localhost in development, swap with your production URL in production
  server: 'sandbox', // Use this option if you're using the sandbox environment - else use 'production' or omit the parameter
});

This resolves the Invalid URL error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Status: No status
Development

No branches or pull requests

1 participant