Skip to main content
The Checkout API creates payment sessions for users to purchase subscriptions or make one-time payments.

Create Checkout Session

POST /api/payments/checkout Creates a checkout session for a specific plan.

Implementation

From src/app/api/payments/checkout/route.ts:15-51:

Authentication

This endpoint requires authentication. User must have an active session.

Request

string
required
Plan name to purchase. Must be one of:
  • starter
  • pro
  • enterprise
The free plan is not purchasable via checkout.
string
URL to redirect to after successful payment.Default: /dashboard?checkout=success (from src/config/payments.ts:240)
string
URL to redirect to if user cancels checkout.Default: /dashboard?checkout=canceled (from src/config/payments.ts:241)

Response

string
Checkout session URL to redirect the user to
string
Payment provider’s session ID for tracking

Example

Response Example

Plan Configuration

Plans are defined in src/config/payments.ts:52-235. Each plan includes:
Pricing:
  • Monthly: $9.90/month
  • Yearly: $99/year (save 17%)
Features:
  • Up to 10 projects
  • Advanced analytics
  • Email support
  • Premium templates
  • Custom integrations
Trial: 14 days
Pricing:
  • Monthly: $99.90/month
  • Yearly: $999/year (save 17%)
Features:
  • Everything in Pro
  • Dedicated account manager
  • Custom contracts
  • SLA guarantees
  • Advanced security
  • Unlimited seats
  • Custom integrations
  • On-premise deployment
Seat-based billing: Yes (unlimited)Trial: 30 days

Multi-Provider Support

ShipFree supports multiple payment providers. The active provider is determined by environment configuration:
The adapter is selected automatically based on PAYMENT_PROVIDER environment variable.

Validation

Request validation schema from src/app/api/payments/checkout/route.ts:9-13:

Error Handling

Unauthorized
User is not authenticated. Session token is missing or invalid.
Bad Request
Invalid request body. Plan name is invalid or missing.
Internal Server Error
Payment provider error or server error.

Post-Checkout Flow

After successful payment:
  1. User completes payment on provider’s checkout page
  2. Provider redirects to successUrl
  3. Webhook is sent to /api/webhooks/payments (see Webhooks)
  4. Database is updated with subscription/payment records
  5. User gains access to plan features

Next Steps

Customer Portal

Manage subscriptions and billing

Webhooks

Handle payment events

Database Schema

Payment-related tables

Subscription API

Retrieve subscription data