Complete Guide to Pricing & Payment Module
Nexty.dev provides a complete SaaS pricing and payment solution built on Stripe. The code design follows best practices for SaaS product payment functionality, supporting both one-time purchase and subscription payment models, with complete user benefits management, credit system, and multi-language support.
Key Features
- ✅ Dual Payment Models: One-time purchase + subscription, with monthly and yearly subscription options
- ✅ Credit System: One-time credits + subscription credits management, yearly subscriptions can reset credits monthly
- ✅ User Credit Change History: Users can view their credit transaction records
- ✅ Stripe Integration: Complete payment flow and webhook handling
- ✅ Multi-language Support: Internationalization for pricing plans
- ✅ Admin Dashboard: Visual pricing plan management
- ✅ Benefits Management: Flexible user benefits configuration
- ✅ Refund Processing: Automated refund and benefits recovery
Core Functionality
Pricing Plan Management
- Environment Isolation: Supports Stripe
testandliveenvironments with automatic environment isolation validation to avoid data confusion - Multi-language Configuration: Supports multi-language through
lang_jsonbfield with one-click translation - Benefits Definition: Provides default
one_time_creditsandmonthly_creditsfields as credit benefits, with flexible plan benefits definition throughbenefits_jsonbfield - Display Control: Supports highlighting, sorting, and activation status control
- Real-time Preview: Card modifications with real-time preview, secure and controllable pricing plan display content
For detailed introduction to pricing management, see Pricing Plan Management.
Payment Process
One-time Purchase Flow
Loading diagram...
Subscription Flow
Loading diagram...
Credit System
Nexty's credit system provides the following out-of-the-box features:
- One-time Credits: Permanently valid after purchase, supports cumulative calculation
- Subscription Credits: Reset each billing cycle, allocated monthly/yearly, yearly subscription credits can be distributed/reset monthly
- Deduction Strategy: Prioritizes subscription credits, deducts one-time credits when subscription credits are insufficient
- Balance Management: Real-time balance inquiry and updates
- Credit History: Users can view their credit transaction history
For simple SaaS products, you can directly use the built-in logic. If you need a more complex credit system and processing logic, you can freely extend through the benefits_jsonb field and develop corresponding logic according to subsequent tutorials.
Database Design
Core Table Structure
- pricing_plans - Pricing plans table
- Stores all pricing plan configurations
- Supports multi-language and benefits definition
- Stripe environment isolation (test/live)
- orders - Orders table
- Records all payment transactions
- Supports multiple order types
- Complete payment information tracking
- subscriptions - Subscriptions table
- Syncs Stripe subscription status
- Subscription lifecycle management
- Billing cycle tracking
- usage - Usage table
- User credit balance management
- Supports multiple credit types
- Real-time balance updates
- credit_logs - Credit logs table
- User change history records
- Complete change records can be submitted as evidence in case of disputes
Key Components
Backend Components
lib/stripe/- Stripe core processing logicactions/prices/- Pricing plan managementactions/usage/- Credit management
Frontend Components
components/home/Pricing.tsx- Categorized pricing display (default)components/home/PricingAll.tsx- One-time display of all pricingcomponents/home/PricingCTA.tsx- Purchase buttonapp/[locale]/(protected)/dashboard/(admin)/prices/- Admin dashboardapp/[locale]/(protected)/dashboard/(user)/subscription/- User subscription managementapp/[locale]/(protected)/dashboard/(user)/credit-history- User credit change history