Create Checkout Session
POST /api/payments/checkout
Creates a checkout session for a specific plan.
Implementation
Fromsrc/app/api/payments/checkout/route.ts:15-51:
Authentication
This endpoint requires authentication. User must have an active session.
Request
Plan name to purchase. Must be one of:
starterproenterprise
free plan is not purchasable via checkout.URL to redirect to after successful payment.Default:
/dashboard?checkout=success (from src/config/payments.ts:240)URL to redirect to if user cancels checkout.Default:
/dashboard?checkout=canceled (from src/config/payments.ts:241)Response
Checkout session URL to redirect the user to
Payment provider’s session ID for tracking
Example
Response Example
Plan Configuration
Plans are defined insrc/config/payments.ts:52-235. Each plan includes:
Starter Plan
Starter Plan
Pricing:
- Monthly: $9.90/month
- Yearly: $99/year (save 17%)
- Up to 10 projects
- Advanced analytics
- Email support
- Premium templates
- Custom integrations
Pro Plan (Recommended)
Pro Plan (Recommended)
Pricing:
- Monthly: $29.90/month
- Yearly: $299/year (save 17%)
- Unlimited projects
- Real-time analytics
- Priority support
- White-label options
- Advanced integrations
- Team collaboration
- Custom workflows
Enterprise Plan
Enterprise Plan
Pricing:
- Monthly: $99.90/month
- Yearly: $999/year (save 17%)
- Everything in Pro
- Dedicated account manager
- Custom contracts
- SLA guarantees
- Advanced security
- Unlimited seats
- Custom integrations
- On-premise deployment
Multi-Provider Support
ShipFree supports multiple payment providers. The active provider is determined by environment configuration:PAYMENT_PROVIDER environment variable.
Validation
Request validation schema fromsrc/app/api/payments/checkout/route.ts:9-13:
Error Handling
User is not authenticated. Session token is missing or invalid.
Invalid request body. Plan name is invalid or missing.
Payment provider error or server error.
Post-Checkout Flow
After successful payment:- User completes payment on provider’s checkout page
- Provider redirects to
successUrl - Webhook is sent to
/api/webhooks/payments(see Webhooks) - Database is updated with subscription/payment records
- 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