Payments

Multi-provider payment system (Stripe, LemonSqueezy) with subscription management. Automatically adapts to user-based or organization-based auth.

Installation

1

Install the Package

Add Payments to your project using the Codelesskit CLI:

pnpm dlx codelesskit@latest add payments
2

Set Environment Variables

Create a `.env` file in the root of your project and add the following environment variables:

.env
1
2
3
4
# Stripe Configuration
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
NEXT_PUBLIC_APP_URL=http://localhost:3000

Usage

Once you've installed Payments, you can start using the following actions:

getActivePrices

Get all active pricing plans from Stripe.

1
2
3
import { getActivePrices } from '@/lib/payments'
 
const prices = await getActivePrices()

getPrice

Get a specific price by ID from Stripe.

1
2
3
import { 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.

1
2
3
4
5
6
import { 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.

1
2
3
import { getSubscription } from '@/lib/payments'
 
const subscription = await getSubscription()

getSubscriptionDetails

Get detailed subscription information including payment method and billing period (organization-based only).

1
2
3
import { getSubscriptionDetails } from '@/lib/payments'
 
const details = await getSubscriptionDetails()

cancelSubscription

Cancel the current subscription. Access continues until the end of the billing period.

1
2
3
import { cancelSubscription } from '@/lib/payments'
 
await cancelSubscription()

usePaymentActions

React hook for payment operations in client components. Provides subscribe method and loading states.

1
2
3
4
5
6
7
8
9
import { usePaymentActions } from '@/lib/payments/hooks'
 
function PlanCard() {
const { subscribe, isLoading } = usePaymentActions()
const handleSubscribe = async () => {
await subscribe(priceId)
}
}
Payments | Codelesskit