feat(editor): ✨ Team workspaces
This commit is contained in:
@@ -2,14 +2,21 @@ import { User } from 'db'
|
||||
import { loadStripe } from '@stripe/stripe-js'
|
||||
import { sendRequest } from 'utils'
|
||||
|
||||
export const pay = async (user: User, currency: 'usd' | 'eur') => {
|
||||
type Props = {
|
||||
user: User
|
||||
currency: 'usd' | 'eur'
|
||||
plan: 'pro' | 'team'
|
||||
workspaceId: string
|
||||
}
|
||||
|
||||
export const pay = async ({ user, currency, plan, workspaceId }: Props) => {
|
||||
if (!process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY)
|
||||
throw new Error('NEXT_PUBLIC_STRIPE_PUBLIC_KEY is missing in env')
|
||||
const stripe = await loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY)
|
||||
const { data, error } = await sendRequest<{ sessionId: string }>({
|
||||
method: 'POST',
|
||||
url: '/api/stripe/checkout',
|
||||
body: { email: user.email, currency },
|
||||
body: { email: user.email, currency, plan, workspaceId },
|
||||
})
|
||||
if (error || !data) return
|
||||
return stripe?.redirectToCheckout({
|
||||
|
||||
Reference in New Issue
Block a user