/* This is the pricing component. You can switch between flat payment or subscription by setting the flat variable. ---------- Dont forget to create your customer portal on Stripe https://dashboard.stripe.com/test/settings/billing/portal */ import { getSub, supabase } from 'utils/supabaseClient'; import { useEffect, useState } from 'react'; import { Prices } from 'utils/priceList'; import { Switch } from '@headlessui/react'; import axios from 'axios'; import router from 'next/router'; import { useAuth } from 'utils/AuthContext'; const Pricing = (): JSX.Element => { const [enabled, setEnabled] = useState(false); const { user, session } = useAuth(); const [customerId, setCustomerId] = useState(null); const [sub, setSub] = useState(false); const flat = false; // Switch between subscription system or flat prices const portal = () => { axios .post('/api/stripe/customer-portal', { customerId, }) .then((result) => { router.push(result.data.url); }); }; useEffect(() => { if (user) { getSub().then((result) => setSub(result)); supabase .from('subscriptions') .select(`customer_id`) .eq('id', user.id) .single() .then((result) => { setCustomerId(result.data?.customer_id); }); } }, [user]); const pricing = { monthly: { personal: '$5/mo', team: '$15/mo', pro: '$35/mo', }, yearly: { personal: '$50/yr', team: '$150/yr', pro: '$350/yr', }, flat: { personal: '€49', team: '€99', pro: '€149', }, }; const handleSubmit = async (e: React.SyntheticEvent, priceId: string) => { e.preventDefault(); // Create a Checkout Session. This will redirect the user to the Stripe website for the payment. axios .post('/api/stripe/create-checkout-session', { priceId, email: user.email, customerId, userId: user.id, tokenId: session.access_token, pay_mode: flat ? 'payment' : 'subscription', }) .then((result) => router.push(result.data.url)); }; return (

Pricing

This is an example of a pricing page. You can choose a payment method, monthly or yearly.

{!flat && (

Billed monthly

Switch bill

Billed annually

)}

Personal

{flat ? pricing.flat.personal : enabled ? pricing.yearly.personal : pricing.monthly.personal}

  • A cool feature
  • Another feature

Team

{flat ? pricing.flat.team : enabled ? pricing.yearly.team : pricing.monthly.team}

  • All basic features
  • Dolor sit amet
  • Consectetur
  • Adipisicing
  • Elit repellat

Pro

{flat ? pricing.flat.pro : enabled ? pricing.yearly.pro : pricing.monthly.pro}

  • Lorem ipsum
  • Dolor sit amet
  • Consectetur
  • Adipisicing
  • Much more...
); }; export default Pricing;