| 1 | import { Polar } from '@polar-sh/sdk' |
| 2 | import type { Metadata |
| 3 | import Link from 'next/link |
| 4 | import { redirect } |
| 5 | import { buttonVariants } |
| 6 | import { |
| 7 | Card, |
| 8 | CardContent, |
| 9 | CardDescription, |
| 10 | CardFooter, |
| 11 | CardHeader, |
| 12 | CardTitle, |
| 13 | } from '@/components/ui/card' |
| 14 | import { env } |
| 15 | import { createMetadata } |
| 16 | import { cn } |
| 17 | import { getSession } |
| 18 | |
| 19 | export const metadata: |
| 20 | title: 'Welcome to Pro', |
| 21 | description: 'Your subscription is active and premium features are unlocked.', |
| 22 | openGraph: { |
| 23 | images: ['/api/og?page=Welcome'], |
| 24 | }, |
| 25 | twitter: { |
| 26 | images: ['/api/og?page=Welcome'], |
| 27 | }, |
| 28 | }) |
| 29 | |
| 30 | export default async function |
| 31 | searchParams, |
| 32 | }: { |
| 33 | searchParams: Promise |
| 34 | }) { |
| 35 | const session = |
| 36 | if (!session) |
| 37 | redirect('/auth/sign-in') |
| 38 | } |
| 39 | |
| 40 | const { checkout_id: |
| 41 | if (!checkoutId || |
| 42 | redirect('/') |
| 43 | } |
| 44 | |
| 45 | const polar = |
| 46 | accessToken: env.POLAR_ACCESS_TOKEN |
| 47 | server: env.NODE_ENV |
| 48 | }) |
| 49 | |
| 50 | const checkout = |
| 51 | .get({ id: |
| 52 | .catch(() => |
| 53 | |
| 54 | if (!checkout || |
| 55 | return ( |
| 56 | <main className='container flex flex-1 flex-col items-center justify-center p-4 md:p-6 |
| 57 | <Card className=' |
| 58 | <CardHeader> |
| 59 | <CardTitle> |
| 60 | Checkout {checkout ? 'Incomplete |
| 61 | </CardTitle> |
| 62 | <CardDescription> |
| 63 | {checkout |
| 64 | ? `Your checkout is currently ${checkout. |
| 65 | : "We couldn't find this checkout session. It may have expired."} |
| 66 | </CardDescription> |
| 67 | </CardHeader> |
| 68 | <CardFooter> |
| 69 | <Link |
| 70 | className={cn(buttonVariants |
| 71 | href='/' |
| 72 | > |
| 73 | Go Home |
| 74 | </Link> |
| 75 | </CardFooter> |
| 76 | </Card> |
| 77 | </main> |
| 78 | ) |
| 79 | } |
| 80 | |
| 81 | const productName = |
| 82 | const amount = |
| 83 | const currency = |
| 84 | |
| 85 | const formattedAmount = |
| 86 | style: 'currency', |
| 87 | currency, |
| 88 | }) |
| 89 | |
| 90 | return ( |
| 91 | <main className='flex w-full flex-1 flex-col items-center justify-center p-4 md:p-6 |
| 92 | <Card className=' |
| 93 | <CardHeader> |
| 94 | <CardTitle>Welcome to {productName |
| 95 | <CardDescription> |
| 96 | Your payment was successful. Premium features are now active for |
| 97 | your workspace. |
| 98 | </CardDescription> |
| 99 | </CardHeader> |
| 100 | <CardContent> |
| 101 | <dl className='space-y-3 text-sm |
| 102 | <div className='flex items-center justify-between |
| 103 | <dt className='text-muted-foreground |
| 104 | <dd className='font-medium |
| 105 | </div> |
| 106 | <div className='flex items-center justify-between |
| 107 | <dt className='text-muted-foreground |
| 108 | <dd className='font-medium |
| 109 | </div> |
| 110 | <div className='flex items-center justify-between |
| 111 | <dt className='text-muted-foreground |
| 112 | <dd className='font-medium text-teal-600 dark:text-teal-400 |
| 113 | Active |
| 114 | </dd> |
| 115 | </div> |
| 116 | {checkout.customerEmail && |
| 117 | <div className='flex items-center justify-between |
| 118 | <dt className='text-muted-foreground |
| 119 | <dd className='font-medium |
| 120 | </div> |
| 121 | )} |
| 122 | </dl> |
| 123 | </CardContent> |
| 124 | <CardFooter> |
| 125 | <Link className={ |
| 126 | Go to Dashboard |
| 127 | </Link> |
| 128 | </CardFooter> |
| 129 | </Card> |
| 130 | </main> |
| 131 | ) |
| 132 | } |