Credit System
PayPal-integrated billing system with transaction tracking
The credit system allows users to top up their balance via PayPal and use credits to purchase groups and
services.
Overview
Credit Balance
Track user credits in EUR
PayPal Integration
Secure payments via PayPal REST API
Transaction History
Complete audit trail
Top-Up Flow
User Journey
- User navigates to
/credits - Views current balance and transaction history
- Clicks "Top Up Credits"
- Selects amount (€5-€1000) or enters custom amount
- Clicks "Continue to PayPal"
- Redirected to PayPal for payment
- Completes payment on PayPal
- Redirected back to success page
- Credits automatically added to balance
- Transaction logged in history
Top-Up Amounts
| Amount | Quick Select | Use Case |
|---|---|---|
| €5 | Basic group purchase | |
| €10 | Small top-up | |
| €20 | Pro group purchase | |
| €50 | Enterprise group | |
| €100 | Bulk purchase | |
| Custom | Any amount €5-€1000 |
PayPal Configuration
Sandbox (Testing)
PAYPAL_MODE=sandbox
PAYPAL_CLIENT_ID=your-sandbox-client-id
PAYPAL_CLIENT_SECRET=your-sandbox-client-secret
Get Sandbox Credentials:
- Go to PayPal Developer Dashboard
- Create a sandbox app
- Copy Client ID and Secret
Production
PAYPAL_MODE=live
PAYPAL_CLIENT_ID=your-live-client-id
PAYPAL_CLIENT_SECRET=your-live-client-secret
Before Going Live:
- Test thoroughly in sandbox
- Create production app in PayPal
- Enable SSL/HTTPS
- Set up webhook verification
- Review PayPal's policies
Transaction Types
Credit Transactions
- PayPal Top-Up: User adds credits via PayPal
- Admin Credit: Manual credit by admin
- Refund: Credits returned
Debit Transactions
- Group Purchase: User buys a group
- Service Purchase: Other services
- Admin Debit: Manual deduction
Database Schema
Tables
credits
User credit balances
id, user_id, balance, updated_at
transactions
Credit/debit transaction history
id, user_id, type, amount, description, reference_id, created_at
paypal_payments
PayPal payment tracking
id, user_id, payment_id, payer_id, amount, status, created_at
API Routes
GET /credits - View balance & history
GET /credits/topup - Top-up form
POST /credits/payment/create - Create PayPal payment
GET /credits/payment/success - Payment success callback
GET /credits/payment/cancel - Payment cancelled callback
Security Features
Atomic Transactions
Database transactions ensure consistency
PayPal Verification
Signature verification in production
Audit Trail
Complete transaction logging