Menu

Complete Guide to Pricing & Payment Module

Nexty.dev provides a complete SaaS pricing and payment solution built on Stripe and Supabase database. 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 test and live environments with automatic environment isolation validation to avoid data confusion
  • Multi-language Configuration: Supports multi-language through lang_jsonb field with one-click translation
  • Benefits Definition: Provides default one_time_credits and monthly_credits fields as credit benefits, with flexible plan benefits definition through benefits_jsonb field
  • 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

  1. pricing_plans - Pricing plans table
  • Stores all pricing plan configurations
  • Supports multi-language and benefits definition
  • Stripe environment isolation (test/live)
  1. orders - Orders table
  • Records all payment transactions
  • Supports multiple order types
  • Complete payment information tracking
  1. subscriptions - Subscriptions table
  • Syncs Stripe subscription status
  • Subscription lifecycle management
  • Billing cycle tracking
  1. usage - Usage table
  • User credit balance management
  • Supports multiple credit types
  • Real-time balance updates
  1. 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 logic
  • actions/prices/ - Pricing plan management
  • actions/usage/ - Credit management

Frontend Components

  • components/home/Pricing.tsx - Categorized pricing display (default)
  • components/home/PricingAll.tsx - One-time display of all pricing
  • components/home/PricingCTA.tsx - Purchase button
  • app/[locale]/(protected)/dashboard/(admin)/prices/ - Admin dashboard
  • app/[locale]/(protected)/dashboard/(user)/subscription/ - User subscription management
  • app/[locale]/(protected)/dashboard/(user)/credit-history - User credit change history