Last active
June 26, 2023 08:30
-
-
Save feliche93/ed16a582e16bb170b622718e8c094568 to your computer and use it in GitHub Desktop.
Pricing Table with Lemon Squeezy Data Fetching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { currentUser } from '@clerk/nextjs' | |
import { User } from '@clerk/nextjs/dist/types/server' | |
import { CheckIcon } from '@heroicons/react/20/solid' | |
import { getProductVariants } from '@lib/lemon-squeezy' | |
import { cn } from '@lib/utils' | |
import { JSDOM } from 'jsdom' | |
import { CheckoutButton } from './checkout-button' | |
import { Badge } from './ui/badge' | |
export default async function Pricing({ | |
title, | |
subtitle, | |
sectionTitle, | |
}: { | |
title: string | |
subtitle: string | |
sectionTitle: string | |
}) { | |
// const frequencies = [ | |
// { value: 'monthly', label: 'Monthly', priceSuffix: '/month' }, | |
// // { value: 'annually', label: 'Annually', priceSuffix: '/year' }, | |
// ] | |
const user = await currentUser() | |
let productId = process.env.PRODUCT_ID | |
if (!productId) { | |
throw new Error('No product ID found') | |
} | |
const productVariants = await getProductVariants(productId) | |
function createCheckoutLink({ | |
variantId, | |
user, | |
}: { | |
variantId: string | |
user: User | null | undefined | |
}): string { | |
const baseUrl = new URL(`https://backlinkgpt.lemonsqueezy.com/checkout/buy/${variantId}`) | |
if (!user) return '/sign-in' | |
const email = user.emailAddresses?.[0]?.emailAddress | |
const name = | |
user.firstName || user?.lastName ? `${user?.firstName} ${user?.lastName}` : undefined | |
const userId = user.id | |
const url = new URL(baseUrl) | |
url.searchParams.append('checkout[custom][user_id]', userId) | |
if (email) url.searchParams.append('checkout[email]', email) | |
if (name) url.searchParams.append('checkout[name]', name) | |
return url.toString() | |
} | |
return ( | |
// Pricing Table JSX Code | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment