Payments
Multi-provider payment system (Stripe, LemonSqueezy) with subscription management. Automatically adapts to user-based or organization-based auth.
Installation
Install the Package
Add Payments to your project using the Codelesskit CLI:
Set Environment Variables
Create a `.env` file in the root of your project and add the following environment variables:
1234# Stripe ConfigurationSTRIPE_SECRET_KEY=sk_test_...STRIPE_WEBHOOK_SECRET=whsec_...NEXT_PUBLIC_APP_URL=http://localhost:3000Usage
Once you've installed Payments, you can start using the following actions:
getActivePrices
Get all active pricing plans from Stripe.
123import { getActivePrices } from '@/lib/payments' const prices = await getActivePrices()getPrice
Get a specific price by ID from Stripe.
123import { getPrice } from '@/lib/payments' const price = await getPrice(priceId)subscribeToPlan
Subscribe the current user/organization to a billing plan. Returns a redirect URL for paid plans or success status for free plans.
123456import { subscribeToPlan } from '@/lib/payments' const result = await subscribeToPlan(priceId)if (result.status === 'redirect') { redirect(result.url)}getSubscription
Get the current user's/organization's active subscription.
123import { getSubscription } from '@/lib/payments' const subscription = await getSubscription()getSubscriptionDetails
Get detailed subscription information including payment method and billing period (organization-based only).
123import { getSubscriptionDetails } from '@/lib/payments' const details = await getSubscriptionDetails()cancelSubscription
Cancel the current subscription. Access continues until the end of the billing period.
123import { cancelSubscription } from '@/lib/payments' await cancelSubscription()usePaymentActions
React hook for payment operations in client components. Provides subscribe method and loading states.
123456789import { usePaymentActions } from '@/lib/payments/hooks' function PlanCard() { const { subscribe, isLoading } = usePaymentActions() const handleSubscribe = async () => { await subscribe(priceId) }}